Path /nix/store does not exist

I learned about this behavior when I ran into it myself. It is one of the things about Nix flakes that people run into early on. The behavior is intentional and not a bug, but it’s so unintuitive that there’s been a lot of discussion about it. Hopefully some day, it can be made more scrutable.

Here is the gist of the situation as I understand it. When using the nix command with Nix flakes, it copies the flake into the Nix store first. (That’s why the filenames you saw were inside the Nix store instead of where you might have expected.) When doing so with a local path, it automatically determines what fetcher to use. If the path appears to be in a Git repository, a Git fetcher is used. The Git fetcher still keeps changes from the working directory intact if there are any, but any “untracked” files are omitted. This is actually a good idea a lot of the time since you may have very large untracked files in a repository. (A good example might be the direnv cache, for example.) But, it can also be inconvenient.

In order to bypass this, you can specify a URL with a scheme instead. e.g. instead of nix build .#output you can do nix build path://${PWD}#output. (The hash part is optional in either syntax, but in the latter syntax we do need an absolute path, hence the use of $PWD instead of ..)

Hope this helps!

2 Likes