Updating NixOS: Difference between revisions
rm numbers |
` |
||
(4 intermediate revisions by 3 users not shown) | |||
Line 4: | Line 4: | ||
As part of this process, only repository channels are updated or removed during updates. The system '''requires an internet connection''' to download the latest changes, and users '''cannot''' directly modify the system. For optimal stability, security, and access to new features, regular updates — ideally '''once a week''' — are recommended. | As part of this process, only repository channels are updated or removed during updates. The system '''requires an internet connection''' to download the latest changes, and users '''cannot''' directly modify the system. For optimal stability, security, and access to new features, regular updates — ideally '''once a week''' — are recommended. | ||
== Rebuilding the system after editing configuration.nix file == | == Rebuilding the system after editing configuration.nix file == | ||
To apply the configuration changes made in <code>/etc/nixos/configuration.nix</code> without updating the channels, [[Nixpkgs]] and package versions. This is typically used when you've edited the system configuration, and you just want to apply those changes:<syntaxhighlight lang="console"> | |||
# nixos-rebuild switch | |||
</syntaxhighlight> | </syntaxhighlight> | ||
== | == For non-flake configurations == | ||
=== Updating NixOS channels === | === Updating NixOS channels === | ||
<syntaxhighlight lang=" | |||
<syntaxhighlight lang="console"> | |||
# 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=" | 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> | |||
=== Changing Nixpkgs version === | |||
To see what is the latest channel available, see https://channels.nixos.org<syntaxhighlight lang="console"># nix-channel --add https://channels.nixos.org/nixos-<version> nixos</syntaxhighlight> | |||
=== Deleting old generations === | |||
<syntaxhighlight lang="console"> | |||
# nix-collect-garbage -d | |||
</syntaxhighlight> | |||
=== Example of a system update === | |||
<syntaxhighlight lang="console"> | |||
# nix-channel --update && nixos-rebuild switch && reboot | |||
</syntaxhighlight> | |||
== 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> | </syntaxhighlight> | ||
Finally, rebuild the system configuration to apply the changes: | |||
<syntaxhighlight lang="console"> | |||
<syntaxhighlight lang=" | # nixos-rebuild switch | ||
</syntaxhighlight> | </syntaxhighlight> | ||
== | == Tips and tricks == | ||
<syntaxhighlight lang=" | |||
=== 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: | |||
<syntaxhighlight lang="console"> | |||
# nixos-rebuild switch --option max-jobs 8 | |||
</syntaxhighlight>To make the change permanent, add the following to your configuration.nix:<syntaxhighlight lang="nix"> | |||
nix = { | |||
settings = { | |||
max-jobs = 8; | |||
}; | |||
}; | |||
</syntaxhighlight> | </syntaxhighlight> | ||
[[Category:NixOS]] | [[Category:NixOS]] |