Updating NixOS: Difference between revisions
Add information about nixos-rebuild boot a tip to fix a hang during update |
follow commands template |
||
| 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> | ||
| Line 13: | Line 12: | ||
=== Updating NixOS channels === | === Updating NixOS channels === | ||
<syntaxhighlight lang=" | <syntaxhighlight lang="console"> | ||
# nix-channel --update | |||
</syntaxhighlight> | </syntaxhighlight> | ||
=== 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 --upgrade | |||
</syntaxhighlight> | </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> | ||
== Changing Nixpkgs version == | === Changing Nixpkgs version === | ||
https://channels.nixos.org/ | 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 == | === Deleting old generations === | ||
<syntaxhighlight lang=" | <syntaxhighlight lang="console"> | ||
# nix-collect-garbage -d | |||
</syntaxhighlight> | </syntaxhighlight> | ||
== | === Example of a system update === | ||
<syntaxhighlight lang=" | <syntaxhighlight lang="console"> | ||
# nix-channel --update && nixos-rebuild switch --upgrade && reboot | |||
</syntaxhighlight> | </syntaxhighlight> | ||
== Limiting the maximum number of running jobs == | == 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: | ||
<syntaxhighlight lang="console"> | |||
# nixos-rebuild switch --option max-jobs 8 | |||
</syntaxhighlight>configuration.nix<syntaxhighlight lang="nix"> | </syntaxhighlight>To make the change permanent, add the following to your configuration.nix:<syntaxhighlight lang="nix"> | ||
nix = { | nix = { | ||
settings = { | settings = { | ||