Nixos-rebuild switch takes 10 seconds?

Hi there!

I’m trying to learn NixOs so I can switch my Laptop’s OS from Manjaro (Arch) to NixOS.

I like the concept, though what block’s me from iterating and learning fast is that every time I want to apply a change in my system setup config, I have to wait 10 to 15 seconds:

# date +%F_%T.%N ; nixos-rebuild switch ; date +%F_%T.%N
2024-06-03_23:18:13.015192480
warning: Git tree '/etc/nixos' is dirty
building the system configuration...
warning: Git tree '/etc/nixos' is dirty
activating the configuration...
setting up /etc...
reloading user units for user...
restarting sysinit-reactivation.target
2024-06-03_23:18:24.857153061

Is there some faster command to quickly try a config, maybe one that skips creating a generation?

There are some options you can try such as test and dry-activate; perhaps that is what you are looking for? Nixos-rebuild - NixOS Wiki not sure how much it’ll reduce the time but restarting units is probably what it’s taking the most time on but that’s just a guess

1 Like

thank you for the reply!

just tried the first option you mentioned, that doesn’t seem substantially faster:

 date +%F_%T.%N ; nixos-rebuild test ; date +%F_%T.%N
2024-06-03_23:57:55.912001900
warning: Git tree '/etc/nixos' is dirty
building the system configuration...
warning: Git tree '/etc/nixos' is dirty
activating the configuration...
setting up /etc...
reloading user units for user...
restarting sysinit-reactivation.target
2024-06-03_23:58:05.818343535

the second option might be:

date +%F_%T.%N ; nixos-rebuild dry-activate ; date +%F_%T.%N
2024-06-03_23:59:01.807514598
building the system configuration...
warning: Git tree '/etc/nixos' is dirty
would activate the configuration...
2024-06-03_23:59:06.877499606

but the man explanation doesn’t seem to be too useful. All it will tell me is a rough estimate what I would achieve if I switched to that build and tell me if I have any syntax errors, right?

Build the new configuration, but instead of activating it, show what changes would be performed by the activation (i.e. by nixos-rebuild test). For instance, this command will print
which systemd units would be restarted. The list of changes is not guaranteed to be complete.

Yes, that’s how I understand it. I don’t use it often myself. I don’t think it’d even try to build with syntax errors.

yes… well I’m new to NixOS and very unsure if I’ll manage to stick around. I’ve been using Manjaro flavored Arch for many years and would have liked to switch to something more stable and love the declarative concept - but I can’t find a workflow with acceptable fast iteration times, the documentation / tutorials / guides seem all very basic and or don’t work as expected. my Plasma shell seems slower than under Arch even though a lot less stuff has been installed as of yet.

Hope we’ll see you around. Godspeed.

1 Like