NixOS Cheat Sheet

Find details on Packages, NixOS options and Flakes: https://search.nixos.org

Flakes

OperationCommand
Installsudo nixos-rebuild switch
Upgradenix flake update
sudo nixos-rebuild switch --upgrade

Nix Commands

OperationCommand
Searchnix search nixpkgs 'package'

Nix-Env (pre nix-commands)

OperationCommand
Searchnix-env -qaP '.*package.*'
Installnix-env -i package-name
Upgradenix-channel --update nixpkgs
nix-env --upgrade '*'
Uninstallnix-env --uninstall package-name
Rollbacknix-env --rollback
Info (short)nix-env -qaP --description '.*package.*'
Info (full)nix-env -qaP --description --json --meta '.*package.*'
List packages in the current environment
(non-system packages)
nix-env -qa --installed "*"

Nix-Shell

OperationCommand
New shell with packagesnix-shell -p pandoc

Garbage Collection & Pruning

OperationCommand
Remove all generationsnix-env --delete-generations old
Remove specific generationsnix-env --delete-generations 10 11 14
Remove generagions by agenix-env --delete-generations 14d
Garbage collectnix-store --gc
Remove old & garbage collectnix-collect-garbage -d

Systemctl

Not NixOS specific.

OperationCommand
List running servicessystemctl --type=service --state=running
Show timerssystemctl list-timers

Mounting Drives

To permanently mount a drive, rebuild the hardware-configuration after the drive has been mounted. You many need to prune out Docker overlays before applying with nixos-rebuild.

$ nixos-regenerate-config
$ nixos-rebuild switch