Skip to content

How to update and upgrade NixOS

Introduction

I’ve recently set up NixOS and have it running smoothly, including the configuration and transition to Podman. I’ve compiled this note on how to update and upgrade NixOS.

How To

Configuration update

The following command will rebuild the system, activate the new generation immediately and make it the default boot option:

# Open your terminal application
sudo nixos-rebuild switch

To revert the changes, you can use the following command:

# Open your terminal application
sudo nixos-rebuild switch --rollback

System update

With the --upgrade option you can update the NixOS channel of the root user before building the configuration:

# Open your terminal application
sudo nixos-rebuild boot --upgrade

Release upgrade

Before proceeding with a system upgrade, it’s crucial to review the release notes of the most recent version. These notes often contain important instructions and steps that need to be followed to ensure a smooth and successful upgrade process.

You can check the current NixOS channel with the following command:

# Open your terminal application
sudo nix-channel --list

Add the channel of the new release:

# Open your terminal application
sudo nix-channel --add https://nixos.org/channels/nixos-<version> nixos
# IMPORTANT: Please read the instructions below
Instructions:
  • Required Replace VERSION with the new version for example 24.11

Then update the channel en upgrade the system:

# Open your terminal application
sudo nix-channel --update
sudo nixos-rebuild boot --upgrade

Cleaning up

As outlined here, it’s important to periodically remove unused packages by running the Nix garbage collector. This tool will clear out any packages in the Nix store that are not being used, either directly or indirectly, by any current profile generation.

Keep in mind that packages referenced by older generations won’t be deleted since the system needs them to enable rollbacks. Therefore, for garbage collection to be truly effective, you should also consider deleting some of the older generations. Naturally, you should only do this if you’re confident that you won’t need to perform any rollbacks.

# Open your terminal application
nix-collect-garbage -d

Favorites

Comments

    No comments found for this note.

    Join the discussion for this note on Github. Comments appear on this page instantly.

    Copyright 2021- Fiction Becomes Fact