Possible nix flake hierarchical lookup bug

Hello. I have submitted a possible bug to github issues for NixOS/nix. It is something that happens when nesting flakes. Has anyone run into hierarchy bugs with flakes? Does my bug look like an actual bug or am i assuming something or doing something stupid?

I set up a git repo for the bug at GitHub - nwg/flake-hierarchy-test: Flake hierarchy possible bug demo , but i’ll just describe it below too.

Basically, you set up a flake1 with:

/tmp/flake1/flake.nix

inputs.mytarget.url = "/tmp/flake2";
outputs = { ... }: {};

And a second at /tmp/flake2/flake.nix

{
   inputs.dwarffs.url = "github:edolstra/dwarffs";
   outputs = { ... }: {};
}

(and of course do appropriate git init for flakes)

and then do this:

cd /tmp/flake2
nix flake update
cd /tmp/flake1
nix flake update

And you get an error:

error: input 'mytarget/dwarffs/nixpkgs' follows a non-existent input 'dwarffs/nix/nixpkgs'
(use '--show-trace' to show detailed location information)

The dwarffs flake contains an input that looks at itself and results in the hierarchy lookup happening, and the input from dwarffs that triggers the bug is this one:

inputs.nixpkgs.follows = "nix/nixpkgs";

I expected it to look at ‘mytarget/dwarffs/nix/nixpkgs’ but it tried ‘dwarffs/nix/nixpkgs’ and failed.

This is a bug right? I was gonna fix the bug myself, but thought i might not be thinking of something and it’s actually not a bug at all.

1 Like

Seems to be an already reported issue

https://github.com/NixOS/nix/issues/3602