I installed NicOS earlier today and for a while I was able to run nix-env --install in a reasonable time, but then the 5th time it suddenly started taking over 30 minutes. If I pass the --verbose option I can see it’s evaluating every file in /nix/store. I had edited the config and run nixos-rebuild switch a few times but only changing which desktop environment was enabled and changing the bootloader to grub.
I hadn’t done much in my home directory, and resetting all those changes doesn’t seem to have helped, but I’m pretty sure it’s the result of something I’ve done wrong rather than a bug because it didn’t happen the first few times.
Could I please have some advice for diagnosing the problem?
nix-env --install builds derivations and installs them, based on what matches the regex you passed in. A blank match means everything. You’re correct in that it is evaluating every file and that would explain the slowness.
Check out man nix-env-install for more. I’m sure most folks with tell you to avoid nix-env altogether but skim/reference/read that manual page nonetheless to get a better understanding.
The important note is that, if you omit -A, nix-env will do so regardless of which regex you give it.
This is because without -A it uses the derivation name, rather than the name of its attribute in nixpkgs, so it needs to evaluate every single derivation to compute their names. This will take a lot of time if you don’t have much memory (~4GB is probably just about enough these days), and even a while with sufficient memory.
It also has other horrible implications, see the link I shared earlier.