CLI Commands Reference
Quick reference for common Nix and nix-darwin commands.
Table of Contents
Section titled “Table of Contents”System Management
Section titled “System Management”darwin-rebuild
Section titled “darwin-rebuild”# Apply configuration changesdarwin-rebuild switch --flake .#hostname
# Build without applyingdarwin-rebuild build --flake .#hostname
# Test build (dry run)darwin-rebuild build --flake .#hostname --dry-run
# Build with trace (for errors)darwin-rebuild switch --flake .#hostname --show-trace
# List generationsdarwin-rebuild --list-generations
# Switch to generationdarwin-rebuild switch --switch-generation 5
# Rollback to previousdarwin-rebuild switch --rollback
# Delete specific generationsdarwin-rebuild delete-generations 1 2 3
# Delete old generations (30+ days)darwin-rebuild delete-generations +30
System Information
Section titled “System Information”# Show current systemls -l /run/current-system
# System configurationdarwin-option -r
# Specific optiondarwin-option programs.zsh.enable
# Show all optionsdarwin-option --list
Package Management
Section titled “Package Management”Searching Packages
Section titled “Searching Packages”# Search nixpkgsnix search nixpkgs python
# Search with JSON outputnix search nixpkgs --json python | jq
# Browse online# https://search.nixos.org/packages
Installing Packages
Section titled “Installing Packages”# Add to configuration file, then:darwin-rebuild switch --flake .#hostname
# Or install to user profilenix profile install nixpkgs#package-name
# List installed (in profile)nix profile list
# Remove from profilenix profile remove package-name
Package Information
Section titled “Package Information”# Show package metadatanix eval nixpkgs#python3.meta.description
# Show versionnix eval nixpkgs#python3.version
# Show package infonix-env -qa --description python3
Flake Commands
Section titled “Flake Commands”Flake Management
Section titled “Flake Management”# Update all inputsnix flake update
# Update specific inputnix flake lock --update-input nixpkgs
# Show flake infonix flake show
# Show flake metadatanix flake metadata
# Check flakenix flake check
# Archive flakenix flake archive --to file://backup.tar.gz
Flake Building
Section titled “Flake Building”# Build default packagenix build
# Build specific outputnix build .#ai-clis
# Build systemnix build .#darwinConfigurations.hostname.system
# Build and runnix run .#package-name
Flake Development
Section titled “Flake Development”# Enter dev shellnix develop
# Run command in dev shellnix develop --command bash
Store Operations
Section titled “Store Operations”Store Queries
Section titled “Store Queries”# List all store pathsnix-store --query --requisites /run/current-system
# Show references (runtime deps)nix-store --query --references /nix/store/path
# Show referrers (what depends on this)nix-store --query --referrers /nix/store/path
# Dependency treenix-store --query --tree /run/current-system
# Closure sizenix path-info -S /run/current-system
# All paths sorted by sizenix path-info -rS /run/current-system | sort -nk2
Store Maintenance
Section titled “Store Maintenance”# Garbage collectionnix-collect-garbage
# Delete old generations (30+ days)nix-collect-garbage --delete-older-than 30d
# Delete everything not in usenix-collect-garbage -d
# Optimize store (deduplicate)nix-store --optimise
# Verify storenix-store --verify --check-contents
# Repair storenix-store --verify --check-contents --repair
Store Comparison
Section titled “Store Comparison”# Diff two store pathsnix store diff-closures /run/current-system ./result
# Compare generationsnix store diff-closures \ /nix/var/nix/profiles/system-5-link \ /nix/var/nix/profiles/system-6-link
Development
Section titled “Development”Building
Section titled “Building”# Build packagenix build .#package-name
# Build with logsnix build .#package-name --print-build-logs
# Build with tracenix build .#package-name --show-trace
# Keep failed buildsnix build .#package-name --keep-failed
# Dry run (what would build)nix build .#package-name --dry-run
# Force rebuildnix build .#package-name --rebuild
Evaluation
Section titled “Evaluation”# Evaluate expressionnix eval .#package-name.version
# Evaluate with JSONnix eval --json .#package-name.meta
# Parse Nix filenix-instantiate --parse file.nix
# Evaluate Nix filenix-instantiate --eval file.nix
# Show derivationnix derivation show .#package-name
Testing
Section titled “Testing”# Enter shell with packagenix shell nixpkgs#python3
# Run command with packagenix run nixpkgs#hello
# Develop with packagenix develop
Troubleshooting
Section titled “Troubleshooting”Debugging
Section titled “Debugging”# Verbose outputdarwin-rebuild switch --flake .#hostname --verbose
# Show tracedarwin-rebuild switch --flake .#hostname --show-trace
# Debug evaluationnix eval --show-trace .#darwinConfigurations.hostname
# Check what's wrongnix flake check --show-trace
Repair
Section titled “Repair”# Repair storenix-store --verify --check-contents --repair
# Re-download from cachenix-store --verify --check-contents
# Delete and rebuildrm -rf resultnix build .#package-name
Cache Issues
Section titled “Cache Issues”# Build without cache (force local)nix build .#package-name --option substitute false
# Use specific cachenix build .#package-name \ --option substituters "https://cache.nixos.org"
# Check if path in cachenix path-info --store https://cache.nixos.org /nix/store/path
Quick Reference
Section titled “Quick Reference”Most Used Commands
Section titled “Most Used Commands”# Update and rebuildnix flake update && darwin-rebuild switch --flake .#hostname
# Test before applyingdarwin-rebuild build --flake .#hostnamenix store diff-closures /run/current-system ./result
# Rollback if brokendarwin-rebuild switch --rollback
# Clean up old stuffnix-collect-garbage --delete-older-than 30d
# Search for packagenix search nixpkgs package-name
# Check configurationnix flake check
Common Workflows
Section titled “Common Workflows”Update system:
cd ~/Confignix flake updatedarwin-rebuild build --flake .#hostnamenix store diff-closures /run/current-system ./resultdarwin-rebuild switch --flake .#hostname
Add package:
# Edit hosts/hostname.nixenvironment.systemPackages = [ pkgs.new-package ];
darwin-rebuild switch --flake .#hostname
Test package:
nix build .#package-name./result/bin/package-name
Recover from error:
darwin-rebuild switch --rollback# Ordarwin-rebuild switch --switch-generation 5
Environment Variables
Section titled “Environment Variables”# Nix configurationNIX_PATH="nixpkgs=/path/to/nixpkgs"
# Build coresNIX_BUILD_CORES=8
# Store directory (usually default)NIX_STORE_DIR="/nix/store"
# Remote buildersNIX_REMOTE_SYSTEMS="user@builder"
# Show all optionsnix show-config
Related Documentation
Section titled “Related Documentation”- Nix Fundamentals - Understanding Nix
- Troubleshooting - Common issues
- Testing Builds - Build testing
External References
Section titled “External References”- Nix Manual - Command reference
- nix-darwin Manual - Darwin commands
- Nix Pills - In-depth tutorials
Bookmark this page for quick command reference!