Keep an escape route.
If the new configuration misbehaves but your machine is still usable, switch to the previous retained generation with the command below. You can also select an older NixOS generation in the boot menu when available.
A rollback changes the system profile and activates that configuration. Your configuration source files are not automatically reverted; restore the intended version in Git before rebuilding, or you may recreate the unwanted change.
sudo nixos-rebuild switch --rollback
# Inspect the current system target:
readlink -f /run/current-system
Garbage collection follows references.
Nix retains store objects that are reachable from garbage-collection roots, including retained profiles and generations. Unreferenced objects can be collected. Deleting generations removes recovery choices.
Do not manually remove files from /nix/store. Choose a retention policy deliberately, and remember that rolling back system packages does not reverse changes to mutable service data. Keep backups independently.
A rollback selects an old configuration, not an old copy of all disk state.