Some NixOS commands for managing a system
NixOS is not yet unified under the "command-api", so here are some commands for system management as of the time of writing.
Getting the current system nixpkgs revision
$ nixos-version
23.11.20231117.c757e9b (Tapir)
The part after the last `.` is the git hash to the revision of nixpkgs that's currently in use.
Overriding specific lock file input
$ nix flake update --override-input nixpkgs 'github:NixOS/nixpkgs/c757e9bd77b16ca2e03c89bf8bc9ecb28e0c06ad'
Update flake input to latest
$ nix flake update nixpkgs
Get the hash of a tarball
$ nix-prefetch-url --unpack https://github.com/NixOS/nix/archive/1f795f9f44607cc5bec70d1300150bfefcef2aae.tar.gz
This will show you the hash that nix expects when doing a
builtins.fetchTarball
Building locally and deploying remotely
$ nixos-rebuild switch --flake .#name --target-host $hostname --build-host localhost
Building any target locally
$ nixos-rebuild build --flake .#target
This doesn't activate it, so you can build targets other than the host system without installing enabling anything in the host bootloader. Mainly useful for debugging builds for other targets locally, on machines that are way faster at building.
Get all generations
$ nix profile history --profile /nix/var/nix/profiles/system
Delete old generations
$ nix-collect-garbage -d