Update Nix to Unstable

Nix has an option to upgrade to stable
upgrade-nix upgrade Nix to the latest stable version

Is there a way for me to upgrade past that?

There is a bug here that was fixed 2 weeks ago, but even on the latest stable the bug still exists so I’d like to upgrade to so I can use the fix.

Edit: Jump to answer summary

generally this is done through channels.

You’ll want to set your nixpkgs channel to follow the release you want to “upgrade to”. Then you need to use “re-run” the command which consumes that channel

follow new channel:

nix-channel --add https://channels.nixos.org/nixos-20.09 nixos

“fetch” the channel and related package set

nix-channel --update

then run the command that “applies” a channel

nix-env -u '*'
home-manager switch
nix-shell -p ...

For upgrading your system, you’ll just want to run it as sudo

sudo nix-channel --add https://channels.nixos.org/nixos-20.09 nixos

then

sudo nixos-rebuild switch

EDIT: forgot update command

1 Like

@jonringer Thanks for the quick response! Sadly I’m not on nixos (the bug itself is a mac-specific)

I added the channel with
nix-channel --add https://channels.nixos.org/nixpkgs-unstable/ unstable

nix-env -u '*' is the only command that worked for me (I don’t have home-manager either).
I’m not sure what the ... should be for nix-shell command.

nix-shell just drops you into a shell with certain things present

https://www.youtube.com/watch?v=k7NKBfeYXCk a video on it’s usage

Thanks for the link! I use nix-shell pretty often, I just wasn’t sure why nix-shell -p would be needed for applying the update.

Sadly It looks like the change wasn’t applied, nix --version is still 2.3.7, and the bug still exists.

Edit: @jonringer oh that’s your video! Haha I actually watched it when I was trying to learn nix-shell, thanks for making it!

1 Like

Do you perhaps still have other channels active which might cause the issue?

$ nix-channel --list
nixos https://channels.nixos.org/nixos-20.09
nixpkgs https://channels.nixos.org/nixpkgs-unstable
unstable https://channels.nixos.org/nixpkgs-unstable

After listing I went ahead and removed unstable and nixos since I was getting this error:

warning: name collision in input Nix expressions, skipping '/Users/jeffhykin/.nix-defexpr/channels_root/nixpkgs'

Removing them, then running nix-channel --update followed again with nix-env -u '*' seems to be doing a whole lot of something (installing), so I’ll add a post once its finished

Oh yea, I forgot to mention, after you’re tracking the channel, you need to do nix-channel --update to pull down the remote information.

I’m just now realizing nix-env -u '*' is updating every individual package. I was about to say that wasn’t what I wanted to do, since the bug causes nix-env -qa --json to fail and I thought nix-env itself needed to be updated.

But the bug is gone now! So there must be something interestingly recursive about nix-env I don’t understand.

As a slight downside, I’m now getting the following warning with every command, even though I’m only subscribed to one channel now

warning: name collision in input Nix expressions, skipping '/Users/jeffhykin/.nix-defexpr/channels_root/nixpkgs'

Looks like it has something to do with this,

/Users/jeffhykin/.nix-defexpr/channels_root/nixpkgs@ -> /nix/store/kkym0q1g9cy7hxxdng2ivwlyv530mgqk-nixpkgs-20.09pre234801.1facbd61b17/nixpkgs

Probably from when I added the nixos channel. I’m not sure the best way to delete/remove it

Answer (summary)

If you’re not running NixOS, then

  1. Give your nix-env access to the latest by running
    sudo nix-channel --update
  2. Update all of your packages (which will probably take awhile)
    nix-env -u '*'

If you are running NixOS

  1. nix-channel --add https://channels.nixos.org/nixos-20.09 nixos
  2. nix-env -u '*'
  3. (if you have home-manager) home-manager switch
  4. (if you want to upgrade your system)
sudo nix-channel --add https://channels.nixos.org/nixos-20.09 nixos
sudo nixos-rebuild switch
1 Like

Just to close the circle, the fix for the nix-env -qa --json bug on Darwin doesn’t involve the nix executable at all. Rather, it’s a fix within the nixpkgs collection of Nix expressions.

So just updating nixpkgs to a recent enough version is all you need to get the fix, as you discovered.

1 Like

Although this is a bit off topic, if I use the -f option for an older commit (example below) will I basically be re-introducing the bug? (will the nix-env be using the -f packages, or only looking/searching them)

nix-env -qa --json -f https://github.com/NixOS/nixpkgs-channels/archive/8414d8386b9a6b855b291fb3f01a4e3b04c08bbb.tar.gz > ~/testJson.json