Comprehensive Nix best practices for flakes, NixOS, home-manager, nix-darwin, devshells, package management, and system configuration. Use this skill when working with Nix flakes, NixOS configuration, home-manager dotfiles, nix-darwin macOS setup, development shells (nix develop/nix-shell), package searching, testing, overlays, or any Nix-related tasks including debugging derivations and garbage collection.
Comprehensive Nix best practices for flakes, NixOS, home-manager, nix-darwin, devshells, package management, and system configuration. Use this skill when working with Nix flakes, NixOS configuration, home-manager dotfiles, nix-darwin macOS setup, development shells (nix develop/nix-shell), package searching, testing, overlays, or any Nix-related tasks including debugging derivations and garbage collection.
Nix Best Practices Skill
This skill provides best practices and patterns for working with Nix, including flakes, NixOS, home-manager, nix-darwin, and development environments.
Configurations build up in layers, each can override the previous:
Linux: flake.nix → systems → modules/nixos → modules/home
macOS: flake.nix → systems → modules/darwin → modules/home
5. Avoid Common Anti-patterns
# BAD: Implicit scope with `with`
environment.systemPackages = with pkgs; [ git vim wget ];
# GOOD: Explicit references
environment.systemPackages = [ pkgs.git pkgs.vim pkgs.wget ];
# Or use a let binding
environment.systemPackages = let p = pkgs; in [ p.git p.vim p.wget ];
Essential Commands
# Build and switch NixOS configurationsudo nixos-rebuild switch --flake .#hostname
# Build and switch nix-darwin
darwin-rebuild switch --flake .#hostname
# Build home-manager standalone
home-manager switch --flake .#user@hostname
# Update all flake inputs
nix flake update
# Update specific input
nix flake update nixpkgs
# Search packages
nix search nixpkgs packagename
# Enter development shell
nix develop
# Garbage collection (with generation cleanup)sudo nix-collect-garbage -d --delete-older-than 7d
# Show flake outputs
nix flake show
# Check flake for errors
nix flake check