NixOS reads the machine configuration from /etc/nixos/configuration.nix and its imported modules. A nixos-rebuild action evaluates that configuration and creates a new system generation.
Choose what the rebuild should change
nixos-rebuild switch activates the new generation now and makes it the boot default. test activates it without changing the boot default, so a restart returns to the earlier generation. boot selects the new generation for the next restart without changing the current session. build only builds the result.
These commands are not interchangeable. Using switch for a configuration change can also make that generation the next boot choice, while test leaves the previous boot default in place.
Rollback depends on generations that still exist
Earlier system generations appear in the boot menu until cleanup removes them. A running machine can return to the preceding generation with nixos-rebuild switch --rollback.
nix-collect-garbage removes unreferenced store paths but preserves the roots for older system configurations. Adding -d also deletes old generation roots, which removes those rollback choices. If a full boot partition caused the cleanup, NixOS still needs nixos-rebuild boot or switch afterward so the boot partition reflects the remaining generations.




