How do I see what happens during NixOS system activation?

It would be practical to have something that shows which commands are executed / files are written/symlinked / … during system activation, to don’t have to look at the activationScripts/… by hand, a simple script that does that, does a bit of formatting, and maybe explains the most common commands is completely ok.

(I’m kind of still a NixOS noob, so please be patient with me)

There’s a couple of things to note here:

which commands are executed

For activationScripts, switching to a system creates /run/current-system/activate which is an aggregation of the activationScripts snippets from each module so you can just read that directly (or result/activate for a system you’ve built but haven’t switched to). You can use grep '^#### ' /run/current-system/activate to see what snippets are included.

The other main way a system will change is through systemd units, but those changes will be printed to your terminal when you rebuild (you’ve likely already seen this).

files are written/symlinked

This is a bit more complicated and I’m not sure what specifically you’re interested in here. For one example you can look at ls -l /etc/static/ or ls -l result/etc/ which shows you which files in /etc are managed by nixos. You can also look around in /run/current-system/sw/ to find many symlinked files managed by nixos.

2 Likes

To be clear, not everything is encoded in the activation script. systemd-tmpfiles.d does a lot of the heavy lifting these days, alongside a bunch of systemd units.

In fact, upstream is trying to get rid of the activation script entirely.

3 Likes