I have a common problem and I was wondering if there is a good solution here.
Generally it happens like this:
- The channel I am following updates and my config fails to evaluate (maybe a non-critical package was broken and my config uses it).
- I try
nixos-rebuild boot --upgrade a few times over the next couple of days to check if it has been fixed.
- I want to make a small change to my config but I can’t because I am on an outdated version.
The goal here is now to update my channel to the version that I built my system with last. That way I can make a small change (like installing a package) and update my system.
Right now I basically run
nix-channel --rollback and then rebuild until it works. Once I find the right revision I then run a no-op
nix-channel --rollback 123 so that I can pull it out of my shell history rather than doing the search again.
So basically is there an easy way to roll back my channel to the right version. I’m open to any options, it could be generating a script during rebuild that I can run or some other tool that scrapes the right version from somewhere.
I mean the obvious thing is to do a channel rollback immediately when an update fails so that you’re always on a working version. Just make sure to also
nix-env -p /nix/var/nix/profiles/system --delete-generations BAD to delete the thing you just rolled back from, because
--rollback just sets the current generation and doesn’t delete. So if you update and rollback again, you’ll be on the previous broken one. i.e. you’ll get
1 -update-> 2 -rollback-> 1 -update-> 3 -rollback-> 2
if you don’t delete
Yeah, that is definitely an improvement to my workflow. I’ll integrate deleting the new bad channels.
It still isn’t a nice one-step jump to the right version though.
Yea it’s annoying that
nixos-rebuild --upgrade ... doesn’t rollback and delete on its own when it fails.
That would solve 98% of my use case. Occasionally I want to keep the new
channel to test out for a bit (maybe I need to rebase a patch I am
applying) but in those cases I can rollback and delete the channel
manually. Maybe we could add a
--try-upgrade flag or something that
deleted the new channel if the upgrade failed.
Use flakes instead, and don’t commit if the system doesn’t build after the update.
(disclaimer: flakes are an experimental feature; use with caution)
sorry to hijack this thread but this is how to remove a specific nixos build version!?!
This command should be added to the man page of
nix-collect-garbage to show how to remove a single version (since it can only delete
older than… ! I searched for this and couldn’t find anything, it seems not documented anywhere…