Rolling back a channel


Today I’ve spent some time looking for a way to rollback NixOS, and did a couple of mistakes along the way. So let me write the things I did down, so that, the next time, I don’t have to make these mistakes again :slight_smile:

Earlier today, I’ve run sudo nixos-rebuild switch --upgrade , and got a semi-broken system (some weird error during boot and mouse not working). I’ve booted to the previous generation, and it worked.

So I decided to make the previous generation current. I also wanted to change configuration.nix, and get the new generation based on the old state of channels. I’ve tried sudo nixos-rebuild switch --rollback: that did make the previous generation default, but it didn’t removed the new, broken-one, from boot menu.

So, the next thing I did, which was a mistake, was to run sudo nix-collect-garbadge -d. This didn’t remove the broken generation, but it did remove old version of channels. So, sudo nix-channel --rollback, which is the thing I should be using in the first place, was broken now.

I however have a local copy of nixpkgs repository, so I figured I just use it instead of a channel. To do this, I needed two things:

  • figure out which commit of nixpkgs I should use (it should be the one that was used by the working generation)
  • figure out how to make nixos-rebuild use my local copy of nixpkgs.

To do the first, I run nixos-version, which gave me a version, last component of which was the desired commit hash.

To do the second, I run

sudo nixos-rebuild switch \
    -I nixpkgs=/home/matklad/projects/nixpkgs/ \
    -I nixos=/home/matklad/projects/nixpkgs/nixos/

And now it all seems working :slight_smile:

1 Like

You can simply remove particular symlinks by hand – from inside /nix/var/nix/profiles/**, only note that won’t change the boot menu until you do a switch or boot.

EDIT: I personally prefer to keep quite a long history of working systems. Sometimes you just don’t immediately notice that something less important is broken.

1 Like