Home NixOS How To Upgrade NixOS 23.11 To 24.05 [Step-by-Step]

How To Upgrade NixOS 23.11 To 24.05 [Step-by-Step]

By sk
4.4K views

NixOS 24.05, codenamed Uakari, has been released a few days ago. One of the key strengths of NixOS is its simple and straight-forward upgrade process, ensuring your system remains up-to-date while maintaining stability and reliability. In this step-by-step tutorial, we will discuss how to upgrade NixOS to latest available version.

For the purpose of this guide, I will demonstrate how to upgrade NixOS 23.11 (Tapir) to 24.05 (Uakari). Here is the current version details of my NixOS 23.11:

$ cat /etc/os-release 
BUG_REPORT_URL="https://github.com/NixOS/nixpkgs/issues"
BUILD_ID="23.11.5541.56528ee42526"
DOCUMENTATION_URL="https://nixos.org/learn.html"
HOME_URL="https://nixos.org/"
ID=nixos
LOGO="nix-snowflake"
NAME=NixOS
PRETTY_NAME="NixOS 23.11 (Tapir)"
SUPPORT_END="2024-06-30"
SUPPORT_URL="https://nixos.org/community.html"
VERSION="23.11 (Tapir)"
VERSION_CODENAME=tapir
VERSION_ID="23.11"
Check NixOS Version
Check NixOS Version

Backup Data

This should be the first step regardless of the operating system you use. Make sure you have backed up all important data that you can't afford to lose.

Update NixOS Channels

At the core of the NixOS upgrade process lies the concept of Channels. NixOS Channels are curated repositories that distribute Nix expressions and their associated binaries, meticulously tested and built to ensure a seamless experience. The available channels include:

  • Stable Channels (e.g., nixos-24.05): These channels receive conservative bug fixes and package upgrades, such as minor kernel updates from 6.1 to 6.2, ensuring a stable and reliable experience.
  • Unstable Channel (nixos-unstable): For the adventurous, this channel reflects NixOS's active development branch, offering the latest cutting-edge features and updates, albeit with potential instability.
  • Small Channels (e.g., nixos-24.05-small): Identical to their regular counterparts but with fewer pre-built binary packages, these channels are ideal for server environments, providing faster updates when critical security patches are released.

To learn more about Nix channels usage, check the following guide:

Getting Started With Nix Package Manager

Upgrade to NixOS 24.05 from 23.11

When you first install NixOS (E.g. 23.11), you're automatically subscribed to the channel corresponding to your installation source.

To check your current channel, run the following command as root or sudo user:

$ sudo nix-channel --list | grep nixos
nixos https://nixos.org/channels/nixos-23.11
Check Current Channel in NixOS
Check Current Channel in NixOS

As you see in the output above, my current channel is 23.11. Meaning, I am using NixOS 23.11.

To switch channels to the latest version, simply use nix-channel --add https://channels.nixos.org/channel-name nixos.

For example, to move to the stable 24.05 channel, we use:

$ sudo $nix-channel --add https://channels.nixos.org/nixos-24.05 nixos

Once subscribed to your desired channel, upgrading is as easy as running:

$ sudo nixos-rebuild switch --upgrade

This command is equivalent to nix-channel --update nixos; nixos-rebuild switch, seamlessly updating your system to the latest version in the selected channel.

If the upgrade is successful, you will see the following output:

[...]
updating GRUB 2 menu...
Warning: os-prober will be executed to detect other bootable partitions.
Its output will be used to detect bootable binaries on them and create new boot entries.
lsblk: /dev/mapper/no*[0-9]: not a block device
lsblk: /dev/mapper/raid*[0-9]: not a block device
lsblk: /dev/mapper/disks*[0-9]: not a block device
installing the GRUB 2 boot loader on /dev/sda...
Installing for i386-pc platform.
Installation finished. No error reported.
[...]

Reboot your NixOS system.

$ sudo reboot

After logging in to the newly upgraded system, check its version to verify if the upgrade is successful.

[ostechnix@nixos:~]$ cat /etc/os-release 
ANSI_COLOR="1;34"
BUG_REPORT_URL="https://github.com/NixOS/nixpkgs/issues"
**BUILD_ID="24.05.803.b3b2b28c1daa"**
DOCUMENTATION_URL="https://nixos.org/learn.html"
HOME_URL="https://nixos.org/"
ID=nixos
IMAGE_ID=""
IMAGE_VERSION=""
LOGO="nix-snowflake"
NAME=NixOS
PRETTY_NAME="NixOS 24.05 (Uakari)"
SUPPORT_END="2024-12-31"
SUPPORT_URL="https://nixos.org/community.html"
VERSION="24.05 (Uakari)"
VERSION_CODENAME=uakari
**VERSION_ID="24.05"**
Check NixOS Version and Codename
Check NixOS Version and Codename

As you see in the above output, we have successfully upgraded to NixOS 24.05.

Upgrade NixOS to Bleeding Edge

If you want to try bleeding edge (latest), you can switch to nixos-unstable channel and perform the upgrade as shown above. Here are the steps to upgrade NixOS to the latest version.

First, switch to the NixOS unstable channel using the following command:

$ sudo nix-channel --add https://channels.nixos.org/nixos-unstable nixos

This command tells the Nix package manager to add the URL of the unstable channel (https://channels.nixos.org/nixos-unstable) and associate it with the nixos channel name.

You can check which channel you're currently subscribed to using the following command:

$ sudo nix-channel --list | grep nixos

This will show the channel URL and name associated with your current NixOS installation.

After adding the nixos-unstable channel, you can then upgrade your NixOS installation to the latest version in the unstable channel by running:

$ sudo nixos-rebuild switch --upgrade

This will download and install all the latest packages and updates from the unstable channel.

It's important to note that the unstable channel, as the name implies, contains the latest bleeding-edge updates and changes from NixOS's main development branch.

While it provides access to the newest features and packages, it may also introduce instabilities or breakages. Therefore, it's generally not recommended to use the unstable channel on production systems or mission-critical environments.

If you want to switch back to a stable channel later, you can use a similar nix-channel --add command with the desired stable channel URL (e.g., https://channels.nixos.org/nixos-24.05 for the NixOS 24.05 stable channel).

Automatic Upgrades

For ultimate convenience, NixOS offers an automatic upgrade option. By adding the following lines to your configuration.nix:

{
  system.autoUpgrade.enable = true;
  system.autoUpgrade.allowReboot = true;
}

You enable the nixos-upgrade.service, which periodically checks for and applies updates from your subscribed channel.

If allowReboot is set to true, the system will automatically reboot when the new generation includes kernel, initrd, or kernel module changes.

You can even specify a custom channel for automatic upgrades:

{
  system.autoUpgrade.channel = "https://channels.nixos.org/nixos-24.05";
}

Conclusion

With NixOS, upgrading your system has never been more straightforward. Whether you prefer the stability of the latest stable channel or the bleeding edge of the unstable channel, the process is quite easy!

You May Also Like

Leave a Comment

* By using this form you agree with the storage and handling of your data by this website.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

This website uses cookies to improve your experience. By using this site, we will assume that you're OK with it. Accept Read More