I’m struggling to imagine how you could “upgrade” and not have the prior generation. But I suppose it doesn’t matter – if it’s gone, then it’s gone.
I’m not sure quite what you mean by “downgrade the kernel from a live usb”. Running from a live usb should give you enough control to change pretty-much anything on the destination system. What you want to change will affect how to do it. Working from a live usb is outside my experience, but I can try to offer some guidance if you have the patience.
To figure this out, we may have to dig into details of how the system boot process works. You might prefer to just reinstall rather than wading through these details – especially if you have backups of any data you care about. (If you don’t have backups, maybe you can use the live usb to copy what matters most.)
NixOS symlinks to prior generations in /nix/var/nix/profiles/
. When configuring the boot loader, corresponding files are written to /boot/loader/entries/
. Note that these are directories in separate partitions on the boot drive: fat32 for /boot
and some linux type such as ext4 for /
. (I am assuming your system is configured to use systemd-boot as the boot loader; if not, this info may not apply.)
When booting the live usb, I would expect these directories represent the usb drive and that your target drive probably is not even mounted. The nixos-enter
wiki page has good info as far as it goes, but links to the NixOS manual at a level that doesn’t help so much. I think you have to manually configure /mnt
with your installation target filesystems before running nixos-enter
. This means mounting relevant partitions.
You should be able to get info about your laptop drive by running lsblk
. That should display a list of block devices something like this
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS
sda 8:0 1 0B 0 disk
├─sda1 8:1 0 512M 0 part /boot
└─sda2 8:2 0 16G 0 part /
nvme0n1 259:0 0 1.8T 0 disk
├─nvme0n1p1 259:1 0 512M 0 part
└─nvme0n1p2 259:2 0 1.6T 0 part
Your version will be different. What’s important is that there is one device showing a mountpoint of /
– device sda
in my list. This is the current root filesystem, which should be your live usb.
The other device – nvme0n1
in my list – is your laptop drive. It should show at least two partitions – one with a size less than 1G and one much larger. Typically the smaller one is first and is used for /boot
and the larger one is /
for the new OS.
To use nixos-enter
, you first mount your target root partition at /mnt
and then mount your target /boot
partition at /mnt/boot
. For my nvme0n1
device the commands are
mount /dev/nvme0n1p2 /mnt
mount /dev/nvme0n1p1 /mnt/boot
After mounting those partitions, you can use ls
to explore what files are actually there. Hopefully you will find /mnt/nix/var/nix/profiles/
contains more than one system
generation. I expect that you will find that /mnt/boot/loader/entries/
does not match the profiles.
With those partitions mounted, running nixos-enter
should get you a shell where you can use nix commands to fix the system. (You may have to do extra work to get an Internet connection.) If nixos-rebuild
does not work, it’ll help to know more about what files you see.