NixOS - Updating and Upgrading

For some time now I have been looking for an interesting lightweight linux distribution that could replace Ubuntu.

I have NixOS running and now also made this note about updating and upgrading NixOS.

Configuration update

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

sudo nixos-rebuild switch

If you want to revert the changes then use the following command:

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:

sudo nixos-rebuild boot --upgrade

Release upgrade

Make sure you read the release notes of the latest release. Sometimes there are instructions which need to be followed before upgrading the system.

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

sudo nix-channel --list

Add the channel of the new release:

sudo nix-channel --add nixos

Replace VERSION with the new version for example: 23.05

Then update the channel en upgrade the system:

sudo nix-channel --update
sudo nixos-rebuild boot --upgrade

Cleaning up

As described here, unused packages should be removed at some point. You can do this by running the Nix garbage collector. It will remove from the Nix store any package not used (directly or indirectly) by any generation of any profile.

Note however that as long as old generations reference a package, it will not be deleted. After all, we wouldn’t be able to do a rollback otherwise. So in order for garbage collection to be effective, you should also delete (some) old generations. Of course, this should only be done if you are certain that you will not need to roll back.

nix-collect-garbage -d

Read other notes


    No comments found for this note.

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


    Notes mentioning this note

    Notes Graph