Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.
 
 
 
 
 
 

140 wiersze
6.1 KiB

  1. <chapter xmlns="http://docbook.org/ns/docbook"
  2. xmlns:xlink="http://www.w3.org/1999/xlink"
  3. version="5.0"
  4. xml:id="sec-upgrading">
  5. <title>Upgrading NixOS</title>
  6. <para>
  7. The best way to keep your NixOS installation up to date is to use one of the
  8. NixOS <emphasis>channels</emphasis>. A channel is a Nix mechanism for
  9. distributing Nix expressions and associated binaries. The NixOS channels are
  10. updated automatically from NixOS’s Git repository after certain tests have
  11. passed and all packages have been built. These channels are:
  12. <itemizedlist>
  13. <listitem>
  14. <para>
  15. <emphasis>Stable channels</emphasis>, such as
  16. <literal
  17. xlink:href="https://nixos.org/channels/nixos-20.03">nixos-20.03</literal>.
  18. These only get conservative bug fixes and package upgrades. For instance,
  19. a channel update may cause the Linux kernel on your system to be upgraded
  20. from 4.19.34 to 4.19.38 (a minor bug fix), but not from
  21. 4.19.<replaceable>x</replaceable> to 4.20.<replaceable>x</replaceable> (a
  22. major change that has the potential to break things). Stable channels are
  23. generally maintained until the next stable branch is created.
  24. </para>
  25. <para></para>
  26. </listitem>
  27. <listitem>
  28. <para>
  29. The <emphasis>unstable channel</emphasis>,
  30. <literal
  31. xlink:href="https://nixos.org/channels/nixos-unstable">nixos-unstable</literal>.
  32. This corresponds to NixOS’s main development branch, and may thus see
  33. radical changes between channel updates. It’s not recommended for
  34. production systems.
  35. </para>
  36. </listitem>
  37. <listitem>
  38. <para>
  39. <emphasis>Small channels</emphasis>, such as
  40. <literal
  41. xlink:href="https://nixos.org/channels/nixos-20.03-small">nixos-20.03-small</literal>
  42. or
  43. <literal
  44. xlink:href="https://nixos.org/channels/nixos-unstable-small">nixos-unstable-small</literal>.
  45. These are identical to the stable and unstable channels described above,
  46. except that they contain fewer binary packages. This means they get
  47. updated faster than the regular channels (for instance, when a critical
  48. security patch is committed to NixOS’s source tree), but may require
  49. more packages to be built from source than usual. They’re mostly
  50. intended for server environments and as such contain few GUI applications.
  51. </para>
  52. </listitem>
  53. </itemizedlist>
  54. To see what channels are available, go to
  55. <link xlink:href="https://nixos.org/channels"/>. (Note that the URIs of the
  56. various channels redirect to a directory that contains the channel’s latest
  57. version and includes ISO images and VirtualBox appliances.) Please note that
  58. during the release process, channels that are not yet released will be
  59. present here as well. See the Getting NixOS page
  60. <link xlink:href="https://nixos.org/nixos/download.html"/> to find the newest
  61. supported stable release.
  62. </para>
  63. <para>
  64. When you first install NixOS, you’re automatically subscribed to the NixOS
  65. channel that corresponds to your installation source. For instance, if you
  66. installed from a 20.03 ISO, you will be subscribed to the
  67. <literal>nixos-20.03</literal> channel. To see which NixOS channel you’re
  68. subscribed to, run the following as root:
  69. <screen>
  70. <prompt># </prompt>nix-channel --list | grep nixos
  71. nixos https://nixos.org/channels/nixos-unstable
  72. </screen>
  73. To switch to a different NixOS channel, do
  74. <screen>
  75. <prompt># </prompt>nix-channel --add https://nixos.org/channels/<replaceable>channel-name</replaceable> nixos
  76. </screen>
  77. (Be sure to include the <literal>nixos</literal> parameter at the end.) For
  78. instance, to use the NixOS 20.03 stable channel:
  79. <screen>
  80. <prompt># </prompt>nix-channel --add https://nixos.org/channels/nixos-20.03 nixos
  81. </screen>
  82. If you have a server, you may want to use the “small” channel instead:
  83. <screen>
  84. <prompt># </prompt>nix-channel --add https://nixos.org/channels/nixos-20.03-small nixos
  85. </screen>
  86. And if you want to live on the bleeding edge:
  87. <screen>
  88. <prompt># </prompt>nix-channel --add https://nixos.org/channels/nixos-unstable nixos
  89. </screen>
  90. </para>
  91. <para>
  92. You can then upgrade NixOS to the latest version in your chosen channel by
  93. running
  94. <screen>
  95. <prompt># </prompt>nixos-rebuild switch --upgrade
  96. </screen>
  97. which is equivalent to the more verbose <literal>nix-channel --update nixos;
  98. nixos-rebuild switch</literal>.
  99. </para>
  100. <note>
  101. <para>
  102. Channels are set per user. This means that running <literal> nix-channel
  103. --add</literal> as a non root user (or without sudo) will not affect
  104. configuration in <literal>/etc/nixos/configuration.nix</literal>
  105. </para>
  106. </note>
  107. <warning>
  108. <para>
  109. It is generally safe to switch back and forth between channels. The only
  110. exception is that a newer NixOS may also have a newer Nix version, which may
  111. involve an upgrade of Nix’s database schema. This cannot be undone easily,
  112. so in that case you will not be able to go back to your original channel.
  113. </para>
  114. </warning>
  115. <section xml:id="sec-upgrading-automatic">
  116. <title>Automatic Upgrades</title>
  117. <para>
  118. You can keep a NixOS system up-to-date automatically by adding the following
  119. to <filename>configuration.nix</filename>:
  120. <programlisting>
  121. <xref linkend="opt-system.autoUpgrade.enable"/> = true;
  122. <xref linkend="opt-system.autoUpgrade.allowReboot"/> = true;
  123. </programlisting>
  124. This enables a periodically executed systemd service named
  125. <literal>nixos-upgrade.service</literal>. If the <literal>allowReboot</literal>
  126. option is <literal>false</literal>, it runs <command>nixos-rebuild switch
  127. --upgrade</command> to upgrade NixOS to the latest version in the current
  128. channel. (To see when the service runs, see <command>systemctl list-timers</command>.)
  129. If <literal>allowReboot</literal> is <literal>true</literal>, then the
  130. system will automatically reboot if the new generation contains a different
  131. kernel, initrd or kernel modules.
  132. You can also specify a channel explicitly, e.g.
  133. <programlisting>
  134. <xref linkend="opt-system.autoUpgrade.channel"/> = https://nixos.org/channels/nixos-20.03;
  135. </programlisting>
  136. </para>
  137. </section>
  138. </chapter>