I need to bind swag to a development environment at version 1.8.1. I have a module which I believe builds it at that version:
# .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" ];
};
}
I've included it in my flake.nix like so:
{
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; }) ];
};
});
}
When I run nix develop I see this error:
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
How can I debug this kind of error?
packagesin mkShell ends up getting merged into nativeBuildInputs which is a parameter on stdenv.mkDerivation which needs to be a list of derivations.In your case,
nativeBuildInputswas empty, so element 1 obviously refers to the only element supplied topackages. In other cases the index in the error might be offset by the merge.You can check what your module is actually exporting like so:
You'll notice that it's not actually a derivation, it's an attribute set containing a derivation. Modify the module to remove
swag =and just let it export the output ofpkgs.buildGoModuledirectly.Notice the difference when you check it out in the repl:
Following this change, what you're supplying at
mkShell.packageswill actually be a list of derivations.