swag
绑定到1.8.1版本的开发环境。我有一个模块,我相信它是在该版本上构建的:
# .deps/swag.nix
{ pkgs }:
{
swag = pkgs.buildGoModule rec {
name = "go-swag-1.8.1";
version = "1.8.1";
src = pkgs.fetchFromGitHub {
owner = "swaggo";
repo = "swag";
rev = "v${version}";
sha256 = "sha256-r19SYRHewbPL6S7bZGGqJk9QX8V9IxmRx3zyDeKGdn0=";
};
vendorHash = "sha256-QphjiJSQRULphWjrJ8RzrUblTDYL/fYoSNT3+g0tP48=";
subPackages = [ "cmd/swag" ];
};
}
我已将其包含在我的
flake.nix
中,如下所示:
{
inputs = {
flake-utils.url = "github:numtide/flake-utils";
nixpkgs.url = "github:nixos/nixpkgs";
};
outputs = { self, nixpkgs, flake-utils }:
flake-utils.lib.eachDefaultSystem (system:
let pkgs = import nixpkgs { inherit system; };
in {
devShells.default = pkgs.mkShell {
packages = [ (import ./.deps/swag.nix { inherit pkgs; }) ];
};
});
}
当我运行
nix develop
时,我看到此错误:
error: while calling the 'derivationStrict' builtin
pkgs/stdenv/generic/make-derivation.nix:375:7:
nativeBuildInputs = elemAt (elemAt dependencies 0) 1;
^
depsBuildTarget = elemAt (elemAt dependencies 0) 2;
error: Dependency is not of a valid type: element 1 of nativeBuildInputs for nix-shell
如何调试此类错误?
packages
最终合并到 nativeBuildInputs 中,这是 stdenv.mkDerivation 上的参数,它需要是派生列表。您可以像这样检查您的模块实际导出的内容:
$ nix repl
nix-repl> pkgs = import<nixpkgs>{ }
nix-repl> import ./swag.nix { inherit pkgs; }
{ swag = «derivation /nix/store/frkbcnwr0kak5yvp847zq4w3d5nb84zk-go-swag-1.8.1.drv»; }
您会注意到它实际上不是派生,而是包含派生的属性集。修改模块,使其实际返回推导:
{ pkgs }:
pkgs.buildGoModule rec {
name = "go-swag-1.8.1";
version = "1.8.1";
src = pkgs.fetchFromGitHub {
owner = "swaggo";
repo = "swag";
rev = "v${version}";
sha256 = "sha256-r19SYRHewbPL6S7bZGGqJk9QX8V9IxmRx3zyDeKGdn0=";
};
vendorHash = "sha256-QphjiJSQRULphWjrJ8RzrUblTDYL/fYoSNT3+g0tP48=";
subPackages = [ "cmd/swag" ];
}
在 repl 中查看时请注意差异:
nix-repl> import ./swag.nix { inherit pkgs; }
«derivation /nix/store/frkbcnwr0kak5yvp847zq4w3d5nb84zk-go-swag-1.8.1.drv»
在此更改之后,您在
mkShell.packages
提供的内容实际上将是一个派生列表。