Flakes, buildInputs and devShell

Hi there,

Now that nix 2.4 is out, i am trying to learn how flakes work. Everything is making sense for single flakes, but I am having some issues when trying to compose several flakes. Here is an example: a simple flake in tmp/flake_exp:

{
  description = "A flake for building Hello World";

  inputs.nixpkgs.url = github:NixOS/nixpkgs/nixos-20.03;

  outputs = { self, nixpkgs }: {

    defaultPackage.x86_64-linux =
      with import nixpkgs { system = "x86_64-linux"; };
      stdenv.mkDerivation {
        name = "foo";
        src = self;
        buildPhase = "gcc -o foo ./hello.c";
        installPhase = "mkdir -p $out/bin; install -t $out/bin foo";
      };

  };
}

this is just the normal intro hello flake, but i have renamed the executable to foo. This builds exactly as I would expect using nix build. Now here is a second flake located in /tmp/flake_exp_2:

{
  description = "A dev environment";

  inputs.nixpkgs.url = github:NixOS/nixpkgs/nixos-20.03;
  inputs.foo.url = path:/tmp/flake_exp;

  outputs = { self, nixpkgs, foo }: {

    devShell.x86_64-linux =
      # Notice the reference to nixpkgs here.
      with import nixpkgs { system = "x86_64-linux"; };
      mkShell {
        buildInputs = [foo];
      };

  };
}

I would expect that running nix develop would enter a shell where the foo built by the first flake would be in $PATH, but it is missing. Presumably i am misunderstanding something, but I am not sure what. Any help understanding would be greatly appreciated!

Build inputs are derivations, and the flake as a whole isn’t one. You need to refer to the derivation itself with foo.defaultPackage.x86_64-linux.

2 Likes

yep, that makes sense and fixes the problem. Thanks @amaproblem :smiley: