Khenziii / nixos-config

❄️ My configuration files
GNU General Public License v3.0
9 stars 1 forks source link

nixos: .git directory causing --flake rebuild to fail #1

Closed Khenziii closed 1 month ago

Khenziii commented 3 months ago

The Issue

For some reason, rebuilding using this command:

$ sudo nixos-rebuild switch --flake ".#nixos"

Fails, because of "missing" hardware-configuration.nix:

even though, that hardware-configuration.nix is in the correct path, and is being imported correctly by configuration.nix

error:
       … while calling the 'seq' builtin

         at /nix/store/8s55w0927lh3mdbkxf434zb0c5hqsz8z-source/lib/modules.nix:322:18:

          321|         options = checked options;
          322|         config = checked (removeAttrs config [ "_module" ]);
             |                  ^
          323|         _module = checked (config._module);

       … while evaluating a branch condition

         at /nix/store/8s55w0927lh3mdbkxf434zb0c5hqsz8z-source/lib/modules.nix:261:9:

          260|       checkUnmatched =
          261|         if config._module.check && config._module.freeformType == null && merged.unmatchedDefns != [] then
             |         ^
          262|           let

       (stack trace truncated; use '--show-trace' to show the full trace)

       error: getting status of '/nix/store/i9xm3vhir130v2ckywsqj1x3hd9zhhja-source/hardware-configuration.nix': No such file or directory

This issue, seems to get resolved after removing / renaming the .git folder:

$ mv .git .git-old
$ sudo nixos-rebuild switch --flake ".#nixos"
building the system configuration...
activating the configuration...
setting up /etc...
reloading user units for khenzii...
restarting sysinit-reactivation.target

Solution

I have genuinely 0 idea on why this might happen. Why does Nix even care to look at the content of .git?

If I won't figure out anything in the next couple days, I'm probably going to start a thread on Nix's discourse.

Until then, we'll be just renaming the .git directory..

$ mv .git .git-old && sudo nixos-rebuild switch --flake ".#nixos"; mv .git-old .git
Khenziii commented 1 month ago

This was actually happening because of Nix's philosophy.

Nix is fully functional, so an action should have no side-consequences; we refer to this as purity.

To keep flakes pure, they should only require theirs inputs to build, nothing more. I was importing ./hardware-configuration.nix, which was .gitignored, so Nix was reasonably giving me errors. My previous setup could lead to a build being successful on one machine, and unsuccessful on another.

A lot of community members have criticized this behavior for it's unclear motives & I partially agree, the error should be more descriptive. Throwing a random "File Not Found" error is definitely not sufficient.

This issue has been resolved by explicitly informing Nix that this flake is impure, which is okay in our case (we obviously can't VCS hardware-configuration.nix).