Nix flakes /nix/store/***-source no such file or directory

just adding flake.nix file to git , i.e. git add flake.nix solved this for me.

Thank you all this thread was a great resource.

I had no idea about this. I ran into this issue in two separate projects, where I could build a source file with Cabal just fine outside of nix develop or nix build, I’d get an error like:

> Error: Setup: can't find source for SomeSourceFile in src, dist/build/autogen,
> dist/build/global-autogen

Doing a git add on the file allowed me to build just fine after.

1 Like

Also make sure that the flake is already in the repo. If not use
git add flake.nix
In my case it was as simple as that as the repo contained a shell.nix file previously and I just forgot to add the flake.nix

1 Like

For me, adding it to git was the way to go. The error message was not very explanatory this time :slight_smile:

I realise this is an old topic but this error is incredibly confusing.

Why does nixos-rebuild care about whether the contents are version controlled.

This sequence of commands makes no sense:

nixos-rebuild ... [works perfectly]
git init
nixos-rebuild ... [broken with unobvious error message]

Without changing a thing in the configuration nixos-rebuild works or not based on whether another unrelated command has been run.

Worse, you can’t load files which aren’t tracked by git. I had a private directory full of nix files that created things like .ssh and my sublime text licence key.

Plan was to push my config to github with those ignored via .gitignore but the coupling of nixos-rebuild and git breaks that approach

Answered here - Why can't nixos-rebuild see files that aren't in the git repository? - #2 by waffle8946