Updating NixOS: Difference between revisions

Klinger (talk | contribs)
Roxwize (talk | contribs)
rm numbers
Line 1: Line 1:
== 1. Introduction ==
== Introduction ==
[[NixOS]] stands out due to its declarative configuration and atomic updates, which ensure that system updates are predictable, reversible, and don’t risk breaking the setup. This approach guarantees consistency across versions, allowing any changes to be easily rolled back. NixOS also offers flexibility, multi-version support, and advanced dependency management, making it an excellent choice for developers and system administrators.
[[NixOS]] stands out due to its declarative configuration and atomic updates, which ensure that system updates are predictable, reversible, and don’t risk breaking the setup. This approach guarantees consistency across versions, allowing any changes to be easily rolled back. NixOS also offers flexibility, multi-version support, and advanced dependency management, making it an excellent choice for developers and system administrators.


Line 5: Line 5:


All commands below are executed in a Terminal application (Shell: Bash).
All commands below are executed in a Terminal application (Shell: Bash).
== 2. Rebuilding the system after editing configuration.nix file ==
== Rebuilding the system after editing configuration.nix file ==
If you want 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="bash">
If you want 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="bash">
sudo nixos-rebuild switch
sudo nixos-rebuild switch
</syntaxhighlight>
</syntaxhighlight>


== 3. Updating channels and rebuilding the system ==
== Updating channels and rebuilding the system ==


=== 3.1 Updating NixOS channels ===
=== Updating NixOS channels ===
<syntaxhighlight lang="bash">
<syntaxhighlight lang="bash">
sudo nix-channel --update
sudo nix-channel --update
</syntaxhighlight>
</syntaxhighlight>


=== 3.2 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="bash">
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="bash">
sudo nixos-rebuild switch --upgrade
sudo nixos-rebuild switch --upgrade
</syntaxhighlight>
</syntaxhighlight>


== 4. Changing Nixpkgs version ==
== Changing Nixpkgs version ==
https://channels.nixos.org/
https://channels.nixos.org/


== 5. Deleting old generations ==
== Deleting old generations ==
<syntaxhighlight lang="bash">
<syntaxhighlight lang="bash">
sudo nix-collect-garbage -d
sudo nix-collect-garbage -d
</syntaxhighlight>
</syntaxhighlight>


== 6. Summary: Automating system updating and deleting old generations ==
== Summary: Automating system updating and deleting old generations ==
<syntaxhighlight lang="bash">
<syntaxhighlight lang="bash">
sudo nix-channel --update && sudo nixos-rebuild switch --upgrade && sudo reboot
sudo nix-channel --update && sudo nixos-rebuild switch --upgrade && sudo reboot