Current system loses specialisation config when switching

Whenever I run nixos-rebuild switch while on a specialisation, I seem to lose any config that was made specifically on said specialisation.

For example, if using my gpu passthrough setup and switching, I will lose access to programs like virt-manager, virsh, etc etc until I reboot and select it again.

Is this some kind of limitation or can the behaviour be changed?

 - system: `"x86_64-linux"`
 - host os: `Linux 6.0.10, NixOS, 22.11 (Raccoon), 22.11.466.596a8e828c5`
 - multi-user?: `yes`
 - sandbox: `yes`
 - version: `nix-env (Nix) 2.11.0`
 - channels(root): `"home-manager-22.11.tar.gz, nixos-22.11, nixos-hardware"`
 - nixpkgs: `/nix/var/nix/profiles/per-user/root/channels/nixos`

nixos-rebuild will always switch to default specialisation if you use switch.

What you can do is to use nixos-rebuild boot and then manually switch to the specialisation you want on the new version.

@viperML’s nh has specialisation support.

Please be aware: it is experimental and and might become disfunct when nixos activationlogic changes.

nixos-rebuild switch runs <toplevel>/bin/switch-to-configuration boot && <toplevel>/bin/switch-to-configuration test. The first command is correct, while you need your specialisation’s switch-to-configuration (<toplevel>/specialisation/<spec-name>/bin/switch-to-configuration test).

You can manually run these scripts out of your system’s toplevel, which you can build with nixos-rebuild build, but the API might change.