nix Cheatsheet
#
nix is a package manager for Linux and other Unix systems that allows users to manage packages and configurations in a reproducible manner. It uses a declarative configuration language and provides isolation for different environments.
Basic Commands
#
Command/Option | Example | Description |
---|
nix-env -i | nix-env -i package-name | Install a package |
nix-env -e | nix-env -e package-name | Uninstall a package |
nix-env -u | nix-env -u package-name | Upgrade a package |
nix-env -q | nix-env -q package-name | Query information about a package |
nix-env -l | nix-env -l | List all installed packages |
nix-env -iA | nix-env -iA nixpkgs.package-name | Install a package from a specific attribute |
nix-shell | nix-shell | Start a new shell with a specific environment |
nix-build | nix-build | Build a package or configuration |
nix-collect-garbage | nix-collect-garbage | Remove old and unused packages |
Configuration Management
#
Command/Option | Example | Description |
---|
nixos-rebuild switch | sudo nixos-rebuild switch | Apply a new system configuration |
nixos-rebuild test | sudo nixos-rebuild test | Test a new system configuration |
nixos-rebuild boot | sudo nixos-rebuild boot | Update system configuration for next boot |
nix-copy-closure | nix-copy-closure --to ssh://remote | Copy closures to a remote machine |
Package Management
#
Command/Option | Example | Description |
---|
nix-store --gc | nix-store --gc | Perform garbage collection on the Nix store |
nix-store --verify | nix-store --verify | Verify the integrity of the Nix store |
nix-store --query | nix-store --query --requisites /path/to/store | List the dependencies of a store path |
Advanced Commands
#
Command/Option | Example | Description |
---|
nix-ops | nix-ops deploy | Deploy configuration with NixOps |
nix-shell -p | nix-shell -p package-name | Start a shell with a specified package |
nix-prefetch-url | nix-prefetch-url https://example.com/file | Fetch and hash a file from a URL |
Environment Management
#
Command/Option | Example | Description |
---|
nix-env --switch-profile | nix-env --switch-profile /path/to/profile | Switch to a different user profile |
nix-env --set | nix-env --set package-name | Set a specific package version |
This cheatsheet covers the essential nix
commands for package management, configuration, and advanced operations in the Nix ecosystem.