2014-08-24 18:18:18 +01:00
|
|
|
|
<chapter xmlns="http://docbook.org/ns/docbook"
|
|
|
|
|
xmlns:xlink="http://www.w3.org/1999/xlink"
|
|
|
|
|
version="5.0"
|
|
|
|
|
xml:id="sec-upgrading">
|
2018-05-02 00:57:09 +01:00
|
|
|
|
<title>Upgrading NixOS</title>
|
|
|
|
|
<para>
|
2019-09-19 18:17:30 +01:00
|
|
|
|
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:
|
2018-05-02 00:57:09 +01:00
|
|
|
|
<itemizedlist>
|
|
|
|
|
<listitem>
|
|
|
|
|
<para>
|
2019-09-19 18:17:30 +01:00
|
|
|
|
<emphasis>Stable channels</emphasis>, such as
|
|
|
|
|
<literal
|
2020-09-04 18:16:22 +01:00
|
|
|
|
xlink:href="https://nixos.org/channels/nixos-20.09">nixos-20.09</literal>.
|
2019-09-19 18:17:30 +01:00
|
|
|
|
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 4.19.34 to 4.19.38 (a minor bug fix), but not from
|
|
|
|
|
4.19.<replaceable>x</replaceable> to 4.20.<replaceable>x</replaceable> (a
|
|
|
|
|
major change that has the potential to break things). Stable channels are
|
|
|
|
|
generally maintained until the next stable branch is created.
|
2018-05-02 00:57:09 +01:00
|
|
|
|
</para>
|
2014-12-30 21:31:01 +00:00
|
|
|
|
<para></para>
|
2018-05-02 00:57:09 +01:00
|
|
|
|
</listitem>
|
|
|
|
|
<listitem>
|
|
|
|
|
<para>
|
2019-09-19 18:17:30 +01:00
|
|
|
|
The <emphasis>unstable channel</emphasis>,
|
|
|
|
|
<literal
|
|
|
|
|
xlink:href="https://nixos.org/channels/nixos-unstable">nixos-unstable</literal>.
|
|
|
|
|
This corresponds to NixOS’s main development branch, and may thus see
|
|
|
|
|
radical changes between channel updates. It’s not recommended for
|
|
|
|
|
production systems.
|
2018-05-02 00:57:09 +01:00
|
|
|
|
</para>
|
|
|
|
|
</listitem>
|
|
|
|
|
<listitem>
|
|
|
|
|
<para>
|
2019-09-19 18:17:30 +01:00
|
|
|
|
<emphasis>Small channels</emphasis>, such as
|
|
|
|
|
<literal
|
2020-09-04 18:16:22 +01:00
|
|
|
|
xlink:href="https://nixos.org/channels/nixos-20.09-small">nixos-20.09-small</literal>
|
2019-09-19 18:17:30 +01: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.
|
2018-05-02 00:57:09 +01:00
|
|
|
|
</para>
|
|
|
|
|
</listitem>
|
|
|
|
|
</itemizedlist>
|
2019-09-19 18:17:30 +01:00
|
|
|
|
To see what channels are available, go to
|
|
|
|
|
<link xlink:href="https://nixos.org/channels"/>. (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.) Please note that
|
|
|
|
|
during the release process, channels that are not yet released will be
|
|
|
|
|
present here as well. See the Getting NixOS page
|
|
|
|
|
<link xlink:href="https://nixos.org/nixos/download.html"/> to find the newest
|
|
|
|
|
supported stable release.
|
2018-05-02 00:57:09 +01:00
|
|
|
|
</para>
|
|
|
|
|
<para>
|
2019-09-19 18:17:30 +01:00
|
|
|
|
When you first install NixOS, you’re automatically subscribed to the NixOS
|
|
|
|
|
channel that corresponds to your installation source. For instance, if you
|
2020-09-04 18:16:22 +01:00
|
|
|
|
installed from a 20.09 ISO, you will be subscribed to the
|
|
|
|
|
<literal>nixos-20.09</literal> channel. To see which NixOS channel you’re
|
2019-09-19 18:17:30 +01:00
|
|
|
|
subscribed to, run the following as root:
|
2014-08-24 18:18:18 +01:00
|
|
|
|
<screen>
|
2020-09-22 23:38:47 +01:00
|
|
|
|
<prompt># </prompt>nix-channel --list | grep nixos
|
2014-08-24 18:18:18 +01:00
|
|
|
|
nixos https://nixos.org/channels/nixos-unstable
|
|
|
|
|
</screen>
|
2018-05-02 00:57:09 +01:00
|
|
|
|
To switch to a different NixOS channel, do
|
2014-08-24 18:18:18 +01:00
|
|
|
|
<screen>
|
2020-09-22 23:38:47 +01:00
|
|
|
|
<prompt># </prompt>nix-channel --add https://nixos.org/channels/<replaceable>channel-name</replaceable> nixos
|
2014-08-24 18:18:18 +01:00
|
|
|
|
</screen>
|
2019-09-19 18:17:30 +01:00
|
|
|
|
(Be sure to include the <literal>nixos</literal> parameter at the end.) For
|
2020-09-04 18:16:22 +01:00
|
|
|
|
instance, to use the NixOS 20.09 stable channel:
|
2014-12-30 21:31:01 +00:00
|
|
|
|
<screen>
|
2020-09-04 18:16:22 +01:00
|
|
|
|
<prompt># </prompt>nix-channel --add https://nixos.org/channels/nixos-20.09 nixos
|
2014-12-30 21:31:01 +00:00
|
|
|
|
</screen>
|
2018-05-02 00:57:09 +01:00
|
|
|
|
If you have a server, you may want to use the “small” channel instead:
|
2014-08-24 18:18:18 +01:00
|
|
|
|
<screen>
|
2020-09-04 18:16:22 +01:00
|
|
|
|
<prompt># </prompt>nix-channel --add https://nixos.org/channels/nixos-20.09-small nixos
|
2014-08-24 18:18:18 +01:00
|
|
|
|
</screen>
|
2018-05-02 00:57:09 +01:00
|
|
|
|
And if you want to live on the bleeding edge:
|
2014-08-24 18:18:18 +01:00
|
|
|
|
<screen>
|
2020-09-22 23:38:47 +01:00
|
|
|
|
<prompt># </prompt>nix-channel --add https://nixos.org/channels/nixos-unstable nixos
|
2014-08-24 18:18:18 +01:00
|
|
|
|
</screen>
|
2018-05-02 00:57:09 +01:00
|
|
|
|
</para>
|
|
|
|
|
<para>
|
2019-09-19 18:17:30 +01:00
|
|
|
|
You can then upgrade NixOS to the latest version in your chosen channel by
|
|
|
|
|
running
|
2014-08-24 18:18:18 +01:00
|
|
|
|
<screen>
|
2020-09-22 23:38:47 +01:00
|
|
|
|
<prompt># </prompt>nixos-rebuild switch --upgrade
|
2014-08-24 18:18:18 +01:00
|
|
|
|
</screen>
|
2019-09-19 18:17:30 +01:00
|
|
|
|
which is equivalent to the more verbose <literal>nix-channel --update nixos;
|
|
|
|
|
nixos-rebuild switch</literal>.
|
2018-05-02 00:57:09 +01:00
|
|
|
|
</para>
|
|
|
|
|
<note>
|
|
|
|
|
<para>
|
2019-09-19 18:17:30 +01:00
|
|
|
|
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>
|
2018-05-02 00:57:09 +01:00
|
|
|
|
</para>
|
|
|
|
|
</note>
|
|
|
|
|
<warning>
|
|
|
|
|
<para>
|
2019-09-19 18:17:30 +01:00
|
|
|
|
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.
|
2018-05-02 00:57:09 +01:00
|
|
|
|
</para>
|
|
|
|
|
</warning>
|
2018-09-01 20:49:04 +01:00
|
|
|
|
<section xml:id="sec-upgrading-automatic">
|
2018-05-02 00:57:09 +01:00
|
|
|
|
<title>Automatic Upgrades</title>
|
|
|
|
|
|
|
|
|
|
<para>
|
2019-09-19 18:17:30 +01:00
|
|
|
|
You can keep a NixOS system up-to-date automatically by adding the following
|
|
|
|
|
to <filename>configuration.nix</filename>:
|
2015-09-02 14:38:06 +01:00
|
|
|
|
<programlisting>
|
2018-04-05 09:43:56 +01:00
|
|
|
|
<xref linkend="opt-system.autoUpgrade.enable"/> = true;
|
2019-10-12 21:23:53 +01:00
|
|
|
|
<xref linkend="opt-system.autoUpgrade.allowReboot"/> = true;
|
2015-09-02 14:38:06 +01:00
|
|
|
|
</programlisting>
|
2019-09-19 18:17:30 +01:00
|
|
|
|
This enables a periodically executed systemd service named
|
2019-10-12 21:23:53 +01:00
|
|
|
|
<literal>nixos-upgrade.service</literal>. If the <literal>allowReboot</literal>
|
|
|
|
|
option is <literal>false</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>.)
|
|
|
|
|
If <literal>allowReboot</literal> is <literal>true</literal>, then the
|
|
|
|
|
system will automatically reboot if the new generation contains a different
|
|
|
|
|
kernel, initrd or kernel modules.
|
|
|
|
|
You can also specify a channel explicitly, e.g.
|
2015-09-02 14:38:06 +01:00
|
|
|
|
<programlisting>
|
2020-09-04 18:16:22 +01:00
|
|
|
|
<xref linkend="opt-system.autoUpgrade.channel"/> = https://nixos.org/channels/nixos-20.09;
|
2015-09-02 14:38:06 +01:00
|
|
|
|
</programlisting>
|
2018-05-02 00:57:09 +01:00
|
|
|
|
</para>
|
|
|
|
|
</section>
|
2014-08-24 18:18:18 +01:00
|
|
|
|
</chapter>
|