Double system evaluation?

I have noticed that almost since forever, when I’m rebuilding my system, the system evaluates my configuration twice. I don’t know why. I press rebuild, it evaluates and once it is done, it is immediately retrying. You can see it in the console log by the double warning: Git tree '/home/bs/dotfiles' is dirty warning. Am I doing something wrong?

My flake is defined here: https://codeberg.org/BlastboomStrice/dotfiles/src/commit/3ae81f9a7e44bfba25d263c96b22f0edc5e945fc/.config/nixos-config/flake.nix

In the example below I added the package cowsay in my configuration.nix and rebuilt:

$ sudo nixos-rebuild switch --flake ~/dotfiles/.config/nixos-config/#$(hostname) && nix store diff-closures /run/*-system
warning: Git tree '/home/bs/dotfiles' is dirty
building the system configuration...
warning: Git tree '/home/bs/dotfiles' is dirty
stage> Running phase: patchPhase
...
Checking switch inhibitors... done
Skipping "/boot/EFI/systemd/systemd-bootx64.efi", same boot loader version in place already.
Skipping "/boot/EFI/BOOT/BOOTX64.EFI", same boot loader version in place already.
stopping the following units: accounts-daemon.service, polkit.service
activating the configuration...
setting up /etc...
reloading user units for bs...
reloading the following user units: dbus-broker.service
restarting the following user units: nixos-activation.service
restarting sysinit-reactivation.target
reloading the following units: dbus-broker.service
starting the following units: accounts-daemon.service, polkit.service
the following new units were started: NetworkManager-dispatcher.service
Done. The new configuration is /nix/store/x6skwg4r95y40ikjgpbh6q1ssylgpffp-nixos-system-nixos-main-26.11.20260715.753cc8a
cowsay: ∅ → 3.8.4, +51.2 KiB

What could be causing that?

I am around 95% sure that your configuration is not being evaluated twice. The warning about the Git tree being dirty is emitted twice, yes, but that doesn’t necessarily mean the evaluation is being made twice as well

2 Likes

This is because nixos-rebuild first builds the new version of nixos-rebuild and reexecs into it to handle the rest of the rebuild, which subsequently does the evaluation of the real system config. You can prevent this with --no-reexec

3 Likes

I also recorded a short video.
I removed the cowsay package and rebuilt:
weird-eval

Oh I see, thank you:)