使用 flake 安装 nodejs mongodb 和 mongosh,由于 mongosh 被认为是非自由软件,所以我添加了最后一行
{
description = "Installing Nodejs with a flake";
inputs = {
nixpkgs-stable.url = "github:nixos/nixpkgs/nixos-23.11";
};
outputs = { self, nixpkgs-stable, ... }: with nixpkgs-stable.legacyPackages.x86_64-linux; {
devShells.x86_64-linux.TestingNodejsFlake = mkShell {
buildInputs = [
nodejs
mongodb
mongosh
];
}
{ nixpkgs.config.allowUnfreePredicate = pkg: builtins.elem (lib.getName pkg) [
"mongodb"
];
};
};
}
我运行了 nixdevelopment 并得到了这个错误:
error: error: attempt to call something which is not a function but a set
at /nix/store/q0wkasbrmwk8zyz719g4c0gb6d58v1j7-source/flake.nix:9:49:
8| outputs = { self, nixpkgs-stable, ... }: with nixpkgs-stable.legacyPackages.x86_64-linux; {
9| devShells.x86_64-linux.TestingNodejsFlake = mkShell {
| ^
10| buildInputs = [
我正在尝试使用 flake 开发一个网络应用程序,仅此而已
config
在实例化时应作为参数传递给 nixpkgs。
{
description = "Installing Nodejs with a flake";
inputs = {
nixpkgs-stable.url = "github:nixos/nixpkgs/nixos-23.11";
flake-utils.url = "github:numtide/flake-utils";
};
outputs = { nixpkgs-stable, flake-utils, ... }: flake-utils.lib.eachDefaultSystem (system:
let
inherit (nixpkgs-stable) lib;
pkgs = import nixpkgs-stable {
inherit system;
config.allowUnfreePredicate = pkg: builtins.elem (lib.getName pkg) [
"mongodb"
];
};
in {
devShells.TestingNodejsFlake = pkgs.mkShell {
buildInputs = [
pkgs.nodejs
pkgs.mongodb
pkgs.mongosh
];
};
});
}