Rollback: nix-channel or nix-env?

My current generation has errors. I’m not sure why there’s errors, but I want to restore to a previous generation as it works at the moment.

I found a site that explains that I can revert to a previous generation through sudo nix-channel --rollback NUMBER.

site: Different Rollback Methods in NixOS | LibrePhoenix’s Tech Nest

What difference is it if I were to do sudo nix-env --rollback NUMBER? How different is it from a nix-env rollback compared to a nix-channel rollback?

Is this helping?

  1. To list available generations: sudo nix-env --list-generations --profile /nix/var/nix/profiles/system
  2. To switch: sudo nix-env --switch-generation 12345 -p /nix/var/nix/profiles/system (replace 12345 with the generation you want)

Source: List-generations and rollback to any configuration · Issue #24374 · NixOS/nixpkgs · GitHub

For step 1 an even friendlier command would be nixos-rebuild list-generations since it shows a bit more info.

1 Like

As simple as this can be, I could not find this information in the NixOS manual…

2 Likes

And to answer this question, rolling back the system profile using nix-env is changing the currently booted system.

On the other hand, reverting nix-channel will only make a difference if you performed a rebuild using that channel, or if you ran some nix command that uses that channel. i.e. you are simply changing the nixpkgs input, but that input needs to be consumed somehow by some nix command.

1 Like

Oh, I was aware of the commands and how to run rollback, but my question is what’s the difference between nix-channel and nix-env when it comes to --rollback.

But thank you for the breakdown.

If I’m having issues with my current generation, which one should I use to rollback to a working generation?

On the other hand, reverting nix-channel will only make a difference if you performed a rebuild using that channel

So in other words, if I run sudo nixos-rebuild switch --upgrade, and I’m having issues with my current generation, should I use the nix-channel --rollback method?

sudo nixos-rebuild switch --rollback. That will run the nix-env command on the literal previous generation.

EDIT: or sudo nixos-rebuild boot --rollback if you prefer it to apply on next boot.

1 Like