2014-08-24 17:18:18 +00:00
|
|
|
|
<chapter xmlns="http://docbook.org/ns/docbook"
|
|
|
|
|
xmlns:xlink="http://www.w3.org/1999/xlink"
|
|
|
|
|
version="5.0"
|
|
|
|
|
xml:id="sec-upgrading">
|
|
|
|
|
|
|
|
|
|
<title>Upgrading NixOS</title>
|
|
|
|
|
|
|
|
|
|
<para>The best way to keep your NixOS installation up to date is to
|
|
|
|
|
use one of the NixOS <emphasis>channels</emphasis>. 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:
|
|
|
|
|
|
|
|
|
|
<itemizedlist>
|
|
|
|
|
<listitem>
|
2014-12-30 21:31:01 +00:00
|
|
|
|
<para><emphasis>Stable channels</emphasis>, such as <literal
|
2017-03-25 19:14:04 +00:00
|
|
|
|
xlink:href="https://nixos.org/channels/nixos-17.03">nixos-17.03</literal>.
|
2014-08-24 17:18:18 +00:00
|
|
|
|
These only get conservative bug fixes and package upgrades. For
|
|
|
|
|
instance, a channel update may cause the Linux kernel on your
|
2017-03-25 19:14:04 +00:00
|
|
|
|
system to be upgraded from 4.9.16 to 4.9.17 (a minor bug fix), but
|
|
|
|
|
not from 4.9.<replaceable>x</replaceable> to
|
|
|
|
|
4.11.<replaceable>x</replaceable> (a major change that has the
|
2014-08-24 17:18:18 +00:00
|
|
|
|
potential to break things). Stable channels are generally
|
|
|
|
|
maintained until the next stable branch is created.</para>
|
2014-12-30 21:31:01 +00:00
|
|
|
|
<para></para>
|
2014-08-24 17:18:18 +00:00
|
|
|
|
</listitem>
|
|
|
|
|
<listitem>
|
2014-12-30 21:31:01 +00:00
|
|
|
|
<para>The <emphasis>unstable channel</emphasis>, <literal
|
2014-12-14 10:26:08 +00:00
|
|
|
|
xlink:href="https://nixos.org/channels/nixos-unstable">nixos-unstable</literal>.
|
2014-08-24 17:18:18 +00:00
|
|
|
|
This corresponds to NixOS’s main development branch, and may thus
|
|
|
|
|
see radical changes between channel updates. It’s not recommended
|
|
|
|
|
for production systems.</para>
|
|
|
|
|
</listitem>
|
2014-12-30 21:31:01 +00:00
|
|
|
|
<listitem>
|
|
|
|
|
<para><emphasis>Small channels</emphasis>, such as <literal
|
2017-03-25 19:14:04 +00:00
|
|
|
|
xlink:href="https://nixos.org/channels/nixos-17.03-small">nixos-17.03-small</literal>
|
2014-12-30 21:31:01 +00:00
|
|
|
|
or <literal
|
|
|
|
|
xlink:href="https://nixos.org/channels/nixos-unstable-small">nixos-unstable-small</literal>. 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.</para>
|
|
|
|
|
</listitem>
|
2014-08-24 17:18:18 +00:00
|
|
|
|
</itemizedlist>
|
|
|
|
|
|
|
|
|
|
To see what channels are available, go to <link
|
2014-12-14 10:26:08 +00:00
|
|
|
|
xlink:href="https://nixos.org/channels"/>. (Note that the URIs of the
|
2014-08-24 17:18:18 +00:00
|
|
|
|
various channels redirect to a directory that contains the channel’s
|
|
|
|
|
latest version and includes ISO images and VirtualBox
|
|
|
|
|
appliances.)</para>
|
|
|
|
|
|
|
|
|
|
<para>When you first install NixOS, you’re automatically subscribed to
|
|
|
|
|
the NixOS channel that corresponds to your installation source. For
|
2017-03-25 19:14:04 +00:00
|
|
|
|
instance, if you installed from a 17.03 ISO, you will be subscribed to
|
|
|
|
|
the <literal>nixos-17.03</literal> channel. To see which NixOS
|
2014-08-24 17:18:18 +00:00
|
|
|
|
channel you’re subscribed to, run the following as root:
|
|
|
|
|
|
|
|
|
|
<screen>
|
2016-06-01 14:23:32 +00:00
|
|
|
|
# nix-channel --list | grep nixos
|
2014-08-24 17:18:18 +00:00
|
|
|
|
nixos https://nixos.org/channels/nixos-unstable
|
|
|
|
|
</screen>
|
|
|
|
|
|
|
|
|
|
To switch to a different NixOS channel, do
|
|
|
|
|
|
|
|
|
|
<screen>
|
2016-06-01 14:23:32 +00:00
|
|
|
|
# nix-channel --add https://nixos.org/channels/<replaceable>channel-name</replaceable> nixos
|
2014-08-24 17:18:18 +00:00
|
|
|
|
</screen>
|
|
|
|
|
|
|
|
|
|
(Be sure to include the <literal>nixos</literal> parameter at the
|
2017-03-25 19:14:04 +00:00
|
|
|
|
end.) For instance, to use the NixOS 17.03 stable channel:
|
2014-12-30 21:31:01 +00:00
|
|
|
|
|
|
|
|
|
<screen>
|
2017-03-25 19:14:04 +00:00
|
|
|
|
# nix-channel --add https://nixos.org/channels/nixos-17.03 nixos
|
2014-12-30 21:31:01 +00:00
|
|
|
|
</screen>
|
|
|
|
|
|
|
|
|
|
If you have a server, you may want to use the “small” channel instead:
|
2014-08-24 17:18:18 +00:00
|
|
|
|
|
|
|
|
|
<screen>
|
2017-03-25 19:14:04 +00:00
|
|
|
|
# nix-channel --add https://nixos.org/channels/nixos-17.03-small nixos
|
2014-08-24 17:18:18 +00:00
|
|
|
|
</screen>
|
|
|
|
|
|
2014-12-30 21:31:01 +00:00
|
|
|
|
And if you want to live on the bleeding edge:
|
2014-08-24 17:18:18 +00:00
|
|
|
|
|
|
|
|
|
<screen>
|
2016-06-01 14:23:32 +00:00
|
|
|
|
# nix-channel --add https://nixos.org/channels/nixos-unstable nixos
|
2014-08-24 17:18:18 +00:00
|
|
|
|
</screen>
|
|
|
|
|
|
|
|
|
|
</para>
|
|
|
|
|
|
|
|
|
|
<para>You can then upgrade NixOS to the latest version in your chosen
|
|
|
|
|
channel by running
|
|
|
|
|
|
|
|
|
|
<screen>
|
2016-06-01 14:23:32 +00:00
|
|
|
|
# nixos-rebuild switch --upgrade
|
2014-08-24 17:18:18 +00:00
|
|
|
|
</screen>
|
|
|
|
|
|
|
|
|
|
which is equivalent to the more verbose <literal>nix-channel --update
|
|
|
|
|
nixos; nixos-rebuild switch</literal>.</para>
|
|
|
|
|
|
2016-12-07 08:06:25 +00:00
|
|
|
|
<note><para>Channels are set per user. This means that running <literal>
|
|
|
|
|
nix-channel --add</literal> as a non root user (or without sudo) will not
|
|
|
|
|
affect configuration in <literal>/etc/nixos/configuration.nix</literal>
|
|
|
|
|
</para></note>
|
|
|
|
|
|
2014-08-24 17:18:18 +00:00
|
|
|
|
<warning><para>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.</para></warning>
|
|
|
|
|
|
2015-09-02 13:38:06 +00:00
|
|
|
|
|
|
|
|
|
<section><title>Automatic Upgrades</title>
|
|
|
|
|
|
|
|
|
|
<para>You can keep a NixOS system up-to-date automatically by adding
|
|
|
|
|
the following to <filename>configuration.nix</filename>:
|
|
|
|
|
|
|
|
|
|
<programlisting>
|
|
|
|
|
system.autoUpgrade.enable = true;
|
|
|
|
|
</programlisting>
|
|
|
|
|
|
|
|
|
|
This enables a periodically executed systemd service named
|
|
|
|
|
<literal>nixos-upgrade.service</literal>. It runs
|
|
|
|
|
<command>nixos-rebuild switch --upgrade</command> to upgrade NixOS to
|
|
|
|
|
the latest version in the current channel. (To see when the service
|
|
|
|
|
runs, see <command>systemctl list-timers</command>.) You can also
|
|
|
|
|
specify a channel explicitly, e.g.
|
|
|
|
|
|
|
|
|
|
<programlisting>
|
2017-03-25 19:14:04 +00:00
|
|
|
|
system.autoUpgrade.channel = https://nixos.org/channels/nixos-17.03;
|
2015-09-02 13:38:06 +00:00
|
|
|
|
</programlisting>
|
|
|
|
|
|
|
|
|
|
</para>
|
|
|
|
|
|
|
|
|
|
</section>
|
|
|
|
|
|
|
|
|
|
|
2014-08-24 17:18:18 +00:00
|
|
|
|
</chapter>
|