NixOS: Difference between revisions

imported>HLandau
imported>HLandau
Line 219: Line 219:


=== Generations ===
=== Generations ===
Environments are versioned via generation, every change to an environment will create a new generation. With this structure it is possible to revert changes with the help of the nix package manager. This is also true for the booted system, however a restart is required for changing the kernel.
Every time the system state is rebuilt using <code>nixos-rebuild switch</code>, a new generation is created. You can revert to the previous generation at any time, which is useful if a configuration change (or system update) turns out to be detrimental.
 
You can roll back via:


Rolling back can be done via:
<syntaxHighlight lang=shell>
<syntaxHighlight lang=shell>
$ nix-env --rollback # roll back a user environment
$ nix-env --rollback               # roll back a user environment
$ nixos-rebuild switch --rollback # roll back a system environment
$ nixos-rebuild switch --rollback # roll back a system environment
</syntaxHighlight>
 
NixOS also places entries for previous generations in the bootloader menu, so as a last resort you can always revert to a previous configuration by rebooting.
 
Because NixOS keeps previous generations of system state available in case rollback is desired, old package versions aren't deleted from your system immediately after an update. You can delete old generations manually:
 
<syntaxHighlight lang=shell>
# delete generations older than 30 days
$ nix-collect-garbage --delete-older-than 30d
 
# delete ALL previous generations - you can no longer rollback after running this
$ nix-collect-garbage -d                     
</syntaxHighlight>
</syntaxHighlight>


You can configure automatic garbage collection by setting the [https://nixos.org/nixos/options.html#nix.gc nix.gc] options in <code>/etc/nixos/configuration.nix</code>. This is recommended, as it keeps the size of the Nix store down.


== See also ==
== See also ==