LnL7 / nix-darwin

nix modules for darwin
MIT License
3.19k stars 456 forks source link

Flake installation fails if `~/.config` is a Git repository and `nix-darwin/flake.nix` is not committed #948

Closed fmckeogh closed 6 months ago

fmckeogh commented 6 months ago

On macOS 14.4.1 (23E224), after installing Nix from the Determinate Nix installer and following the flake nix-darwin guide in the README I got the following error:

~ $ nix run nix-darwin -- switch --flake ~/.config/nix-darwin
error: path '/nix/store/0lqnbrvn12aq3702vvxx00k31ga2sg2g-source/nix-darwin/flake.nix' does not exist

This is resolved by committing nix-darwin/flake.nix.

I'm new to Nix so apologies if I've misunderstood something, but given that it was pretty hard to search for this problem it might be helpful if anyone else encounters this.

slice commented 6 months ago

I believe this is by design: https://nixos.wiki/wiki/Flakes :)

For flakes in git repos, only files in the working tree will be copied to the store.

(This should probably say "index" or "staging area" instead of "working tree".)

When a git folder exists, flake will only copy files added in git to maximize reproducibility […]

Samasaur1 commented 6 months ago

Yeah, if you set up your config as a git repo, your files need to be tracked by Git or they'll be ignored by Nix

nickkadutskyi commented 2 months ago

When you run it like this: nix run nix-darwin -- switch --flake ~/.config/nix-darwin you essentially run nix run nix-darwin -- switch --flake git+file:~/.config/nix-darwin which will look for files tracked by git. To avoid this while in git repo you can explicitly tell it via nix run nix-darwin -- switch --flake path:~/.config/nix-darwin where path: will not consider anything related to that git repo.

See this https://nix.dev/manual/nix/2.18/command-ref/new-cli/nix3-flake#flake-references and this https://nix.dev/manual/nix/2.18/command-ref/new-cli/nix3-flake#flake-references