I am going through my yearly “try out other DEs and neovim again” exercise and decided to implement it with nixos specialisations this time: NixOS Search
My understanding is that these are sort of like “runtime-system-profiles” so that you can switch between different configurations within a single generation. So, maybe by default I boot without any GUI configured, and then I “switch” into my sway or gnome or plasma specialisation based on how I feel (or which ones are actually working :P).
Anyway, the exercise has me curious, how many folks use specialisations? Do you have any particularly novel use-cases?
I use specialisation so I can easily switch to a system where dedicated graphic card is disabled, CPU undervolting and all options related to power saving are enabled, when I need to use my laptop without power supply.
I recently learned about specialisation too: I saw a PR in nixpkgs from someone who too rediscovered the feature and renamed it. The orignal name “nesting” was so criptic probably only a couple people knew about it.
Anyway, I have two specialisations. The first is for when I connect my computer to a tv: it sets up autologin for my user, enables wifi, sets default audio output to HDMI and starts the controller daemon. The other is similar but without the autologin, which I use when travelling but I have access to a keyboard.
I use system.nixos.tags to tag each one with same name as of specialisation.<name>, so they appear in grub menu and I can switch at boot. Btw, grub now has pasword support in NixOS so the autologin completely isn’t insecure.
I recently learned about specialisation too: I saw a PR in nixpkgs from someone who too rediscovered the feature and renamed it. The orignal name “nesting” was so criptic probably only a couple people knew about it.
«nesting» was also a rename from «children»… it’s a bit of a wandering feature.
I was able to get specialisations working with flakes, and I managed to achieve what I had set out for (initial boot is just my limited “interactive” profile without any DE or GUI apps, but I have plasma/sway specialisations available to switch to).
But, how do you go back to the parent configuration? It changes /run/current-system and I can’t find any back-reference to the parent toplevel.
Another rough edge: when you nixos-rebuild ... switch the system, it switches back to the “parent” configuration instead of the current “specialisation”. Considering the implementation, it’s not surprising, but it’s not the best UX (and could potentially be very disruptive… especially if display-manager disappears from underneath you…).
Poking around, I think the specialisation module actually reaches into some boot.loader.grub.configurationName option, so if you use systemd-boot, and don’t specify this per-specialisation, it winds up being unset.
I think instead, maybe, it should be inferred from the key in the specialisation option. Then, it would be guaranteed to be available in /run/current-system/configuration-name and then a smarter script can know the current active specialisation and could switch into the built specialisation with the same name.
So, I’ve just tried to fix these rough edges of specialisations.
Setting a tag or the configuration name based on the specialisation.<name> is trivial and I did it. What I haven’t been able to do, though, is adding a link to the parent. I think there is a circular dependency problem:
children configurations are built before the parent (part of its closure)
to link the parent to a children I need the store path of the parent
the parent can’t be built until the children are
note: I can’t simply modify the children during the parent built because the system configurations are already built and read-only.
Technically, the same (internally) child specialisation might even be used as a child for multiple parent specialisations…
I wonder if it is worth it, in the bootloader generation, make each entry record the root of specialisation tree in something like /run/current-unspecialised-system/ ?
I have a laptop with an integrated intel gpu and a nvidia gpu. I would also like to use specialisation to get a system with low power usage. Could you share what settings you are using?