Command Cheat Sheet

Updated

September 12, 2026

Command Cheat Sheet

Daily commands for developing, building, and operating Nix and NixOS.

Flakes and development

Command Purpose
nix develop Default project shell
nix develop .#backend Named shell
nix flake init Skeleton flake
nix flake check Eval + checks.*
nix flake update Refresh every input in flake.lock
nix flake update nixpkgs Refresh one input
nix flake show Outputs in this flake
nix flake metadata Locked revisions
nix fmt Formatter if formatter is set

Build, run, eval

Command Purpose
nix build .#pkg Build; symlink ./result
nix run .#app Build and run
nix eval .#attr Print a value
nix log ./result Build log
nix repl .# REPL on this flake

Inspect closures

Command Purpose
nix path-info -Shr ./result Closure size (the number that matters)
nix path-info ./result Output path only
nix-store -q --references P Direct runtime edges
nix-store -q --requisites P Full runtime closure
nix-store -q --referrers P Who points at P
nix-store -q --tree P ASCII graph
nix why-depends A B Why A’s closure contains B
nix-tree P Interactive tree (nix run nixpkgs#nix-tree)
nom build .#pkg nix build with a progress table

Fetchers

Command Purpose
nix-prefetch-url URL Hash a file (packed)
nix-prefetch-url --unpack URL Hash an unpacked archive
nix hash convert --to sri HASH Hex → SRI sha256-…

Copy and caches

Command Purpose
nix copy --to file://$PWD/nar P Directory cache
nix copy --to ssh://host P Copy closure over SSH
cachix push desk-cache ./result Upload to Cachix
nix show-config \| grep substituters Which caches this daemon queries

Remote builders

Command Purpose
nix build .#pkg --max-jobs 0 --builders 'ssh-ng://user@host system' Realise only remotely
sudo ssh -i /root/.ssh/id_builder user@host nix-store --version Daemon SSH must work without a password

NixOS

Command Purpose
sudo nixos-rebuild switch --flake .#host Build, activate, set boot default
sudo nixos-rebuild test --flake .#host Activate without changing the boot default
sudo nixos-rebuild boot --flake .#host Next reboot only
sudo nixos-rebuild dry-activate --flake .#host Show unit changes, do nothing
sudo nixos-rebuild switch --rollback Previous generation
sudo nix-env --list-generations --profile /nix/var/nix/profiles/system Generation list
nixos-version Running release

Home Manager

Command Purpose
home-manager switch --flake .#user Standalone user env
home-manager generations User generations
home-manager switch --rollback Previous user generation (standalone only)

GC and disk

Command Purpose
nix-store --gc --print-roots What is keeping paths alive
nix-collect-garbage Delete unreferenced paths; keep generations
nix-collect-garbage --delete-older-than 14d Drop old generations, then orphans
sudo nix-collect-garbage -d All old generations (incident)
nix-store --optimise Hard-link identical files
nix-store --verify --check-contents Rehash after disk trouble
df -h /nix /boot Store vs ESP — two different full-disk incidents

Backup (restic)

Command Purpose
sudo systemctl start restic-backups-desk Run the NixOS restic unit now
restic snapshots List snapshots (needs -r and password file)
restic restore latest --target /tmp/drill Restore drill