Nixos-rebuild: Difference between revisions

added note, that all flake files need to be tracked by the repo to rebuild successfully
Add note about using nixos-rebuild to switch to a specific generation
Line 45: Line 45:


For a full list of sub-commands and options, see the <code>nixos-rebuild</code> man page.
For a full list of sub-commands and options, see the <code>nixos-rebuild</code> man page.
===Rolling back to a specific generation===
As noted earlier, it possible to switch to the previous generation using the command <code>nixos-rebuild switch --rollback</code>
As of December 2024, <code>nixos-rebuild</code> doesn't have built-in functionality to switch to a generation earlier than the previous. However, there is an [https://github.com/NixOS/nixpkgs/pull/105910/files open pull request] that adds this functionality.
It is possible to manually simulate the behavior from this PR in the meantime. Run the following command to list your generations:
<syntaxHighlight lang=console>
$ nixos-rebuild list-generations
Generation    Build-date          NixOS version          Kernel  Configuration Revision  Specialisation
1054 current  2024-12-02 08:47:16  24.11.20241130.62c435d  6.12.1                          *
1053          2024-12-02 08:44:23  24.11.20241130.62c435d  6.12.1                          *
1052          2024-12-02 08:25:54  24.11.20241130.62c435d  6.12.1                          *
...
</syntaxHighlight>
Run the command <code>/nix/var/nix/profiles/system-N-link/bin/switch-to-configuration switch</code> where <code>N</code> is the generation number you want to switch to.
You can manually see that <code>/nix/var/nix/profiles/</code> contains symlinks to the system closures associated with the listed generations by <code>nixos-rebuild list-generations</code> above:
<syntaxHighlight lang=console>
$ ls -l /nix/var/nix/profiles/
lrwxrwxrwx - root root  2 12月 08:25 system-1052-link -> /nix/store/a5sh1kam9j42gcgca11ax5wg0iaiccab-nixos-system-onyx-24.11.20241130.62c435d
lrwxrwxrwx - root root  2 12月 08:44 system-1053-link -> /nix/store/nhba65kybj6y0gyd307mf9wj3089rf08-nixos-system-onyx-24.11.20241130.62c435d
lrwxrwxrwx - root root  2 12月 08:47 system-1054-link -> /nix/store/97wrfk1dmgbivw35wrkmrg0d0c1zhviw-nixos-system-onyx-24.11.20241130.62c435d
</syntaxHighlight>


===Specifying a different configuration location===
===Specifying a different configuration location===