Upgrading NixOSThe best way to keep your NixOS installation up to date is to
use one of the NixOS channels. A channel is a
Nix mechanism for distributing Nix expressions and associated
binaries. The NixOS channels are updated automatically from NixOS’s
Git repository after certain tests have passed and all packages have
been built. These channels are:
Stable channels, such as nixos-14.12.
These only get conservative bug fixes and package upgrades. For
instance, a channel update may cause the Linux kernel on your
system to be upgraded from 3.4.66 to 3.4.67 (a minor bug fix), but
not from 3.4.x to
3.11.x (a major change that has the
potential to break things). Stable channels are generally
maintained until the next stable branch is created.The unstable channel, nixos-unstable.
This corresponds to NixOS’s main development branch, and may thus
see radical changes between channel updates. It’s not recommended
for production systems.Small channels, such as nixos-14.12-small
or nixos-unstable-small. These
are identical to the stable and unstable channels described above,
except that they contain fewer binary packages. This means they
get updated faster than the regular channels (for instance, when a
critical security patch is committed to NixOS’s source tree), but
may require more packages to be built from source than
usual. They’re mostly intended for server environments and as such
contain few GUI applications.
To see what channels are available, go to . (Note that the URIs of the
various channels redirect to a directory that contains the channel’s
latest version and includes ISO images and VirtualBox
appliances.)When you first install NixOS, you’re automatically subscribed to
the NixOS channel that corresponds to your installation source. For
instance, if you installed from a 14.12 ISO, you will be subscribed to
the nixos-14.12 channel. To see which NixOS
channel you’re subscribed to, run the following as root:
$ nix-channel --list | grep nixos
nixos https://nixos.org/channels/nixos-unstable
To switch to a different NixOS channel, do
$ nix-channel --add https://nixos.org/channels/channel-name nixos
(Be sure to include the nixos parameter at the
end.) For instance, to use the NixOS 14.12 stable channel:
$ nix-channel --add https://nixos.org/channels/nixos-14.12 nixos
If you have a server, you may want to use the “small” channel instead:
$ nix-channel --add https://nixos.org/channels/nixos-14.12-small nixos
And if you want to live on the bleeding edge:
$ nix-channel --add https://nixos.org/channels/nixos-unstable nixos
You can then upgrade NixOS to the latest version in your chosen
channel by running
$ nixos-rebuild switch --upgrade
which is equivalent to the more verbose nix-channel --update
nixos; nixos-rebuild switch.It is generally safe to switch back and forth between
channels. The only exception is that a newer NixOS may also have a
newer Nix version, which may involve an upgrade of Nix’s database
schema. This cannot be undone easily, so in that case you will not be
able to go back to your original channel.Automatic UpgradesYou can keep a NixOS system up-to-date automatically by adding
the following to configuration.nix:
system.autoUpgrade.enable = true;
This enables a periodically executed systemd service named
nixos-upgrade.service. It runs
nixos-rebuild switch --upgrade to upgrade NixOS to
the latest version in the current channel. (To see when the service
runs, see systemctl list-timers.) You can also
specify a channel explicitly, e.g.
system.autoUpgrade.channel = https://nixos.org/channels/nixos-15.09;