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.
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.
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.
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.
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.
- https://nixos.org/channels/nixpkgs-unstable is our unstable repository.
- 'unstable' is the name of our new channel. We will need this later if we want to reference the unstable channel.
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
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.
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
Great article! So if I want still want to use
pkgs.your-package-name
to install packages fromunstable
, should I just replace the channel url fornixos
ornixpkgs
? Also is there a difference betweennixos
andnixpkgs
channel?