Abusing generation list in nixOS / GRUB?

Let’s say I have 2+ different workstation configs, all intended to be run on the same laptop but for different situations at different times – i.e. software dev + pen-testing + temporary mobile tethering AP.

I want to choose something like “Coding”, or “Temp AP” from grub and have it boot the latest generation tagged with the name. Does anyone do this – or is there a better solution?

I can think of hacky ways to implement it poorly… it would be nice to have a simple, readable GRUB though

3 Likes

Hi,
I step in not to answer (since I know only hacky options, see below)
but to note that this very request was answered years ago with
OpenSolaris BE (Boot Environments) thanks to IPS and zfs. Due to the
sorry state of GNU/Linux storage (from zfs to stratis) I doubt we can
achieve easily on GNU/Linux, but…

A possible workaround maybe using nixos-install on zfs: instead to root
your “target system” in /mnt it should be possible to use zfs clones of
root volume and “install them” for any reconfigure/updates, the sole
remaining part is instruct the bootloader properly.

Without zfs the other hacky way maybe create few generation with a name
keeping configs in different git branches. Update is a pity but it can
work out of the box…

However It should be possible, with nixos-rebuild changes, having
different “collection of symlinks” that are maintained instead of
plain generation as special ones, updatable all at once or one by
one and easily switchable to some extent.

In the end Nix{,OS} achieve many OpenSolaris IPS goals in a simple
and even better way so :slight_smile:

my two cents/rant, sorry for not really contributing to that very
topic…

– Ingmar

1 Like

Thanks for the response – I had never heard of BE’s, but it does sound a lot like what i am thinking of.

Fun stuff :slight_smile: I will definitely read up on those some more. Seems like just the thing that would benefit from drv / binary substitution and the common store.

You want to use the -p option of nixos-rebuild. It is described in the manual:

You can make your configuration show up in a different submenu of the GRUB 2 boot screen by giving it a different profile name, e.g.

nixos-rebuild switch -p test

which causes the new configuration (and previous ones created using -p test) to show up in the GRUB submenu “NixOS - Profile ‘test’”. This can be useful to separate test configurations from “stable” configurations.

3 Likes

haha of course it was hiding in there somewhere… thanks for enlightening me.

If the mnemonic is “profile” I bet a few people will confuse this with nix-profile. Something like “tagged generations” seems like a more useful name to me – maybe just having the docs explicitly deny correlation could help too.

nonetheless this is what i was looking for

Some time ago I found an example of adding a squashfs image into grub boot menu:

It is not limited to boot from a separate partitions, many NixOS’es could share the same Nix Store (but in this case only one of them is safe to perform GC in).

I am using it to create bootable USB flash drives, so in the grub menu one can choose the arch (i686 vs x86_64) and kernel version

2 Likes

awesome, i need to refresh my memory on boot.loader.* attributes. Those little abstractions like “extraEntries” are so nice… i feel like nix really helps me mitigate cognitive load in these situations

This is neat!

I manage my user profile with home-manager, would it be possible to select home-manager generations at boot as well? Can I also make named HM generations?

If you use home-manager with the NixOS option for it, they would be linked in the boot menu.

Otherwise, I think it would be possible to call the home manager profile’s activation scripts as part of your user login, but I’m not aware of any existing tool for that.