How to handle channel generations with the unstable channel being stuck for a while

So I am on the nixos-unstable channel and for some time now it is stuck on Hydra and thus does not update. Worse even, if I do a nix-channel --update it will move my channel to a point where the build of my configuration.nix does not complete.

Now of course I can move back to a previous generation of my profile and my system is perfectly usable. But I also want to modify my configuration.nix and rebuild my system (today I had to add a new wifi). So I have to roll back the channel. Still easy.

Sometimes I happen to execute sudo nixos-rebuild --update switch by habit. Now I have two “unusable” generations of the channel and have to nix-channel --rollback twice before I can rebuild my configuration.

After going into /nix/var/nix/profiles/per-user/root and finding the correct generation number that I want to use with nix-channel --rollback N I have now scripted the process:

cd /nix/var/nix/profiles/per-user/$(whoami) \
  && ls -tl chan* \
  | fzf \
  | sed -n 's/.*channels-\([0-9]\+\)-link -> .*/\1/p' \
  | xargs --no-run-if-empty -n1 nix-channel --rollback

In the end this snippet might be useful to you if

  1. the channel you are on sometimes can be updated but then breaks the rebuild of your configuration
  2. you want to check which generations of the channel you have and which is the current

Or do you have other or better solutions for this problem?

It’s issues like this that were probably the main motivation for flakes, and thus, switching to them might be the best solution to this problem since they allow pinning nixpkgs to a specific revision until you explicitly wish to update.

In the interim, I’m glad you’ve at least found a solution to address you immediate concerns.

@nrdxp currently this “pinning” happens in /nix/var/nix/profiles/per-user/root by the link named channels and the only difference for this scenario would be that I can change the channel/flake input in different locations

  • with nix-channel or in /nix/var/nix/profiles/per-user/root, when working traditionally
  • in the flake.nix next to (or replacing) my configuration.nix, when working with flakes

Or do I misunderstand something?

The big plus with flakes (or niv based pinning) is that you can pin by commit.

If you realise you can’t build your config with deadb33f, but with the commit g00dc0d3, which is just one commit earlier, but newer than what would be your “previous generation”, you can just use that commit. But try that with nix-channels.

And we have not yet talked about reproducibility…

I find the most convenient way (on desktop at least) is to have a local checkout. Otherwise flakes.

1 Like

Yes, it’s convenient for sure, but unless you use a git submodule, it will decouple the state of the configuration and the state of the pin, which is something a lot of use actively trying to avoid.