Skip to content

Instantly share code, notes, and snippets.

@bratorange
Last active July 8, 2024 13:49
Show Gist options
  • Save bratorange/59ba97e4f759c2498f81289205582e61 to your computer and use it in GitHub Desktop.
Save bratorange/59ba97e4f759c2498f81289205582e61 to your computer and use it in GitHub Desktop.
Adding the nix unstable channel

Using the nipkgs unstable channel

Motivation

There a times when you need to build something from the nix unstable channel. For example the master contains a new package you need, but the next nixpkgs release is somewhere in the future, and you need this package now. In this guide I want to show how to install packages from unstable by using nix-env. Furthermore I hope to give a basic understanding of the channels concept.

What are nix channels?

A channel is a set of expressions which includes severall build, installation and configuration instructions for packages, services and the system itself. The repository normaly used here is nixpkgs. It is developed at https://github.com/NixOS/nixpkgs.

What is the nix unstable channel?

The unstable channel is a copy of the NixOS/nixpkgs master. It is pulled from github once in a while and will be available from a mirror under https://nixos.org/channels/nixpkgs-unstable. Since NixOS uses half-anual released stable channels, some changes (especially new features) wont be merged into the stable channels and in order to directly use them, we need to use the unstable channel.

Showing the channels, your system uses

To have an overview of all channels, you have installed in your system do:

sudo nix-channel --list

If you havent changed this since the installation, the should be a channel called either nixpkgs or nixos, depending on whever you are on nixos or have nix installed in your non-NixOS. This one is the default nixpkgs-channel and is used for example for your configuration.nix, nix-shell and nix-env.

Adding unstable channel

First you need to add unstable to your nix-channels:

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

Be aware that you we do everything with superuser privilegs. This means that everything we do effects every user on the system. If nix is installed for a single user, you wont need these.

Then we need to fetch the actual channel, similar to 'apt update' in Debian/Ubuntu:

sudo nix-channel --update

Furthermore we have to update the chache of nix search:

sudo nix search -u

Installing packages from unstable

Find packages you want to install

You can now use

nix search your-package

to find all packages which contains your-package either in its name or description. Packages from unstable will also appear right now.

Installation

Install packages from unstable:

nix-env -iA unstable.your-package-name

Note the unstable selection path before the package name. It is the channel name we had given earlier when we did nix-channel --add

@winston0410
Copy link

winston0410 commented Aug 11, 2021

Great article! So if I want still want to use pkgs.your-package-name to install packages from unstable, should I just replace the channel url for nixos or nixpkgs? Also is there a difference between nixos and nixpkgs channel?

@bratorange
Copy link
Author

bratorange commented Aug 11, 2021

Great article! So if I want still want to use pkgs.your-package-name to install packages from unstable, should I just replace the channel url for nixos or nixpkgs? Also is there a difference between nixos and nixpkgs channel?

Thank you! Replacing the channel url for nixos or nixpkgs with the unstable channel is not a good idea in my eyes, since everything would be built from the unstable channel then. There are a number reasons why you wouldn't want this, but the most important is stability issues.

Note that this guide only describes the usage of nix env. What you would like to do is use nix search your-package. This will bring you up with a list of packages. Notice that you will probably see nixos.your-package as well as unstable.your-package. Use one of these with nix-env as described above. Or do you want to use a package inside the nix-shellor your configuration.nix?

The difference between nixos and nixpkgs is described here: NixOS/nixpkgs#7659 (comment)

@carlosjesuscaro
Copy link

Could you explain how to install a specific package from unstable but using the configuration.nix file? Thanks!

@bratorange
Copy link
Author

@carlosjesuscaro Hey Carlo, thanks for your question. I can add that the next week, as im busy atm.

@panekj
Copy link

panekj commented Mar 16, 2022

Could you explain how to install a specific package from unstable but using the configuration.nix file? Thanks!

found the answer here: https://microeducate.tech/how-to-add-nixos-unstable-channel-declaratively-in-configuration-nix/

@cig0
Copy link

cig0 commented Jul 27, 2023

Great gist, thanks for sharing! I'm managing my Home Nix / Manager configuration like @winston0410 mentions, having the exact result you point out, @voidIess.
I'll take a look into polishing my configuration to work and behave in a more civilized way :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment