Updating NixOS: Difference between revisions

follow commands template
Reference to NixOS manual and re-introduce nixos-rebuild switch --upgrade as a shortcut.
 
(3 intermediate revisions by 2 users not shown)
Line 9: Line 9:
</syntaxhighlight>
</syntaxhighlight>


== Updating channels and rebuilding the system ==
== For non-flake configurations ==
 
What follows is a short set of instructions. Further details can be found in the [https://nixos.org/manual/nixos/stable/#sec-upgrading NixOS Manual.]


=== Updating NixOS channels ===
=== Updating NixOS channels ===
<syntaxhighlight lang="console">
<syntaxhighlight lang="console">
# nix-channel --update
# nix-channel --update
</syntaxhighlight>
</syntaxhighlight>
For more information on channels, see the main [[Channel branches]] page.


=== Rebuilding the system after updating channels ===
=== Rebuilding the system after updating channels ===
If you want to not only apply your configuration changes but also update the packages and system environment to the latest versions available from the Nixpkgs repository. This is typically used when you want to ensure you are using the latest versions of your software and system services:<syntaxhighlight lang="console">
If you want to not only apply your configuration changes but also update the packages and system environment to the latest versions available from the Nixpkgs repository. This is typically used when you want to ensure you are using the latest versions of your software and system services:<syntaxhighlight lang="console">
# nixos-rebuild switch
</syntaxhighlight>To apply configuration changes and new package updates only '''after''' rebooting the system, use the following command instead:<syntaxhighlight lang="console">
# nixos-rebuild boot
</syntaxhighlight>
=== Updating channel and rebuilding the system ===
The below command is a shortcut equivalent to running '''nix-channel --update nixos; nixos-rebuild switch''' previously described:
<syntaxhighlight lang="console">
# nixos-rebuild switch --upgrade
# nixos-rebuild switch --upgrade
</syntaxhighlight>To apply configuration changes and new package updates only '''after''' rebooting the system, use the following command instead:<syntaxhighlight lang="console">
# nixos-rebuild boot --upgrade
</syntaxhighlight>
</syntaxhighlight>


Line 33: Line 46:
=== Example of a system update ===
=== Example of a system update ===
<syntaxhighlight lang="console">
<syntaxhighlight lang="console">
# nix-channel --update && nixos-rebuild switch --upgrade && reboot
# nix-channel --update && nixos-rebuild switch && reboot
</syntaxhighlight>
</syntaxhighlight>


== Limiting the maximum number of running jobs ==
== For flake based configurations ==
 
Because [[Flakes]] do not use channels and instead rely on explicitly defined inputs, updating a configuration involves modifying the system’s <code>flake.nix</code> to reference the desired versions of inputs. For example:
 
{{file|flake.nix|nix|
<nowiki>
{
  inputs = {
    nixpkgs.url = "github:nixos/nixpkgs/nixos-25.05"; # update version
    ...
  };
  ...
}
</nowiki>
}}
 
Once the input URLs have been updated, refresh the flake lockfile with:
 
<syntaxhighlight lang="console">
# nix flake update
</syntaxhighlight>
 
Finally, rebuild the system configuration to apply the changes:
 
<syntaxhighlight lang="console">
# nixos-rebuild switch
</syntaxhighlight>
 
== Tips and tricks ==
 
=== Limiting the maximum number of running jobs ===
 
Sometimes, the update process may hang when the system CPU has a high number of cores. You can limit the maximum number of running jobs:
Sometimes, the update process may hang when the system CPU has a high number of cores. You can limit the maximum number of running jobs:


Line 48: Line 92:
};
};
</syntaxhighlight>
</syntaxhighlight>
[[Category:NixOS]]
[[Category:NixOS]]