# Update Nix to Unstable

**URL:** https://discourse.nixos.org/t/update-nix-to-unstable/9550
**Category:** Guides
**Created:** [October 19, 2020, 8:54pm UTC](https://discourse.nixos.org/t/update-nix-to-unstable/9550 "2020-10-19T20:54:56Z")
**Posts on this page:** 14
**Page:** 1

<div class="post-metadata">

### Author: ![jeff-hykin](https://discourse.nixos.org/user_avatar/discourse.nixos.org/jeff-hykin/32/2827_2.png) [@jeff-hykin](https://discourse.nixos.org/u/jeff-hykin)
#### Post date: [October 19, 2020, 8:54pm UTC](https://discourse.nixos.org/t/update-nix-to-unstable/9550/1 "2020-10-19T20:54:56Z")

</div>

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](https://github.com/NixOS/nixpkgs/issues/68206) 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](https://discourse.nixos.org/t/update-nix-to-unstable/9550/10)

---

<div class="post-metadata">

### Author: ![jonringer](https://discourse.nixos.org/user_avatar/discourse.nixos.org/jonringer/32/1348_2.png) [@jonringer](https://discourse.nixos.org/u/jonringer)
#### Post date: [October 19, 2020, 9:38pm UTC](https://discourse.nixos.org/t/update-nix-to-unstable/9550/2 "2020-10-19T21:38:03Z")

</div>

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:

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

```

“fetch” the channel and related package set

```auto
nix-channel --update

```

then run the command that “applies” a channel

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

```

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

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

```

then

```auto
sudo nixos-rebuild switch

```

EDIT: forgot update command

---

<div class="post-metadata">

### Author: ![jeff-hykin](https://discourse.nixos.org/user_avatar/discourse.nixos.org/jeff-hykin/32/2827_2.png) [@jeff-hykin](https://discourse.nixos.org/u/jeff-hykin)
#### Post date: [October 19, 2020, 9:47pm UTC](https://discourse.nixos.org/t/update-nix-to-unstable/9550/3 "2020-10-19T21:47:59Z")

</div>

@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.

---

<div class="post-metadata">

### Author: ![jonringer](https://discourse.nixos.org/user_avatar/discourse.nixos.org/jonringer/32/1348_2.png) [@jonringer](https://discourse.nixos.org/u/jonringer)
#### Post date: [October 19, 2020, 9:53pm UTC](https://discourse.nixos.org/t/update-nix-to-unstable/9550/4 "2020-10-19T21:53:32Z")

</div>

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

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

---

<div class="post-metadata">

### Author: ![jeff-hykin](https://discourse.nixos.org/user_avatar/discourse.nixos.org/jeff-hykin/32/2827_2.png) [@jeff-hykin](https://discourse.nixos.org/u/jeff-hykin)
#### Post date: [October 19, 2020, 10:03pm UTC](https://discourse.nixos.org/t/update-nix-to-unstable/9550/5 "2020-10-19T22:03:31Z")

</div>

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!

---

<div class="post-metadata">

### Author: ![NobbZ](https://discourse.nixos.org/user_avatar/discourse.nixos.org/nobbz/32/7022_2.png) [@NobbZ](https://discourse.nixos.org/u/NobbZ)
#### Post date: [October 19, 2020, 10:25pm UTC](https://discourse.nixos.org/t/update-nix-to-unstable/9550/6 "2020-10-19T22:25:56Z")

</div>

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

---

<div class="post-metadata">

### Author: ![jeff-hykin](https://discourse.nixos.org/user_avatar/discourse.nixos.org/jeff-hykin/32/2827_2.png) [@jeff-hykin](https://discourse.nixos.org/u/jeff-hykin)
#### Post date: [October 19, 2020, 10:35pm UTC](https://discourse.nixos.org/t/update-nix-to-unstable/9550/7 "2020-10-19T22:35:53Z")

</div>

```auto
$ 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:

```auto
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

---

<div class="post-metadata">

### Author: ![jonringer](https://discourse.nixos.org/user_avatar/discourse.nixos.org/jonringer/32/1348_2.png) [@jonringer](https://discourse.nixos.org/u/jonringer)
#### Post date: [October 19, 2020, 10:53pm UTC](https://discourse.nixos.org/t/update-nix-to-unstable/9550/8 "2020-10-19T22:53:32Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![jeff-hykin](https://discourse.nixos.org/user_avatar/discourse.nixos.org/jeff-hykin/32/2827_2.png) [@jeff-hykin](https://discourse.nixos.org/u/jeff-hykin)
#### Post date: [October 19, 2020, 10:53pm UTC](https://discourse.nixos.org/t/update-nix-to-unstable/9550/9 "2020-10-19T22:53:32Z")

</div>

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

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

```

Looks like it has something to do with this,

```auto
/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

---

<div class="post-metadata">

### Author: ![jeff-hykin](https://discourse.nixos.org/user_avatar/discourse.nixos.org/jeff-hykin/32/2827_2.png) [@jeff-hykin](https://discourse.nixos.org/u/jeff-hykin)
#### Post date: [October 19, 2020, 11:09pm UTC](https://discourse.nixos.org/t/update-nix-to-unstable/9550/10 "2020-10-19T23:09:35Z")

</div>

# 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)

```auto
sudo nix-channel --add https://channels.nixos.org/nixos-20.09 nixos
sudo nixos-rebuild switch

```

---

<div class="post-metadata">

### Author: ![simonchatts](https://discourse.nixos.org/letter_avatar_proxy/v4/letter/s/3ec8ea/32.png) [@simonchatts](https://discourse.nixos.org/u/simonchatts)
#### Post date: [October 20, 2020, 8:20am UTC](https://discourse.nixos.org/t/update-nix-to-unstable/9550/11 "2020-10-20T08:20:54Z")

</div>

Just to close the circle, the fix for the [nix-env -qa --json bug on Darwin](https://github.com/NixOS/nixpkgs/issues/68206) 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.

---

<div class="post-metadata">

### Author: ![jeff-hykin](https://discourse.nixos.org/user_avatar/discourse.nixos.org/jeff-hykin/32/2827_2.png) [@jeff-hykin](https://discourse.nixos.org/u/jeff-hykin)
#### Post date: [October 20, 2020, 2:55pm UTC](https://discourse.nixos.org/t/update-nix-to-unstable/9550/12 "2020-10-20T14:55:56Z")

</div>

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)

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

```

---

<div class="post-metadata">

### Author: ![mattfbacon](https://discourse.nixos.org/user_avatar/discourse.nixos.org/mattfbacon/32/5277_2.png) [@mattfbacon](https://discourse.nixos.org/u/mattfbacon)
#### Post date: [March 13, 2022, 7:27pm UTC](https://discourse.nixos.org/t/update-nix-to-unstable/9550/13 "2022-03-13T19:27:02Z")

</div>

I made the mistake of adding the unstable channel to my user channels. Running `sudo nix-channel --list` revealed that the system channel was still on 21.11 and updating that fixed the issue.

---

<div class="post-metadata">

### Author: ![mattfbacon](https://discourse.nixos.org/user_avatar/discourse.nixos.org/mattfbacon/32/5277_2.png) [@mattfbacon](https://discourse.nixos.org/u/mattfbacon)
#### Post date: [March 13, 2022, 7:27pm UTC](https://discourse.nixos.org/t/update-nix-to-unstable/9550/14 "2022-03-13T19:27:35Z")

</div>

Btw, I know this is old but it’s one of the first results on $SEARCH\_ENGINE.
