Why does git init break my flake?

So, if I go to an empty directory and run nix flake init and then nix run it works as expected. But if I run git init there and then the flake breaks and nix run no longer works.

> nix flake init
> nix run
Hello, world!
> git init
> nix run # It broke
error: path '/nix/store/0ccnxa25whszw7mgbgyzdm4nqc0zwnm8-source/flake.nix' does not exist
> rm -rf .git
> nix run # It works again
Hello, world!

Would be great if someone can explain to me the relation between flakes and git and point me to proper documentation (I tried but couldn’t find it). Thanks.

You need to git add the file before you run a flake.

1 Like

Oh yeah. That works. Thanks. Would you mind explaining the relation between git and flake a bit? Also link me to the documentation? :slight_smile:

When using flakes, the whole flake is copied to the store first.
Only paths that are in the git index will get copied to the store when using flakes in a git repo.
There are no official docs on this that I know of.

1 Like