Nixos-rebuild fails, asking me to run nixos-rebuild first

When I try to run sudo nixos-rebuild switch --upgrade, I get the error:

error: evaluation aborted with the following error message: '
This version of Nixpkgs requires Nix >= 2.2, please upgrade:

- If you are running NixOS, `nixos-rebuild' can be used to upgrade your system.

But of course, the very command it’s asking me to run is the one which triggers that failure. So I’m not sure what to do here.

I’ve also tried sudo nix upgrade-nix but it says error: Nix on NixOS must be upgraded via 'nixos-rebuild'.

Have you switched channels recently?

I don’t think so. I’m just using a NixOS image that’s about a year old.

Can you then please check your current channel of root?

sudo nix-channel --list

It’s nixos https://nixos.org/channels/nixos-unstable

That’s a rolling channel, it can make those jumps in between, though if updated often enough that shouldn’t be a problem if updated regularly.

Perhaps you can use pinning techniques to get an older version of that channel that roughly is from the time of your last update, and then slowly advance it month by month.

1 Like

I don’t use channels but I would start by

  1. upgrading (or is it called updating) my current channel
  2. removing everything except bare essentials from my configuration.nix
  3. doing a nicos-rebuild switch.

and then adding things slowly.

1 Like

Thanks. I got it running again by switching to the stable channel and upgrading.