Nix Best Practices
Flake Structure
Standard flake.nix structure:
Follows Pattern (Avoid Duplicate Nixpkgs)
When adding overlay inputs, use follows to share the parent nixpkgs and avoid downloading multiple versions:
All inputs must be listed in outputs function even if not directly used:
Applying Overlays
Overlays modify or add packages to nixpkgs:
Handling Unfree Packages
Option 1: nixpkgs-unfree (Recommended for Teams)
Use numtide/nixpkgs-unfree for EULA-licensed packages without requiring user config:
This chains: proprietary-tool → nixpkgs-unfree → nixpkgs
Option 2: User Config
Users add to ~/.config/nixpkgs/config.nix:
Option 3: Specific Packages (Flake)
Note: config.allowUnfree in flake.nix doesn't work with nix develop - use nixpkgs-unfree or user config.
Creating Binary Overlay Repos
When nixpkgs builds a community version lacking features (common with open-core tools), create an overlay that fetches official binaries.
Pattern (see 0xBigBoss/atlas-overlay, 0xBigBoss/bun-overlay)
Getting SHA256 Hashes
Or use SRI directly:
Dev Shell Patterns
Basic Shell
With Environment Variables
Native Dependencies (C Libraries)
Direnv Integration
.envrc for flake projects:
For unfree packages without nixpkgs-unfree:
Common Commands
Troubleshooting
"unexpected argument" Error
All inputs must be listed in outputs function:
Unfree Package Errors with nix develop
config.allowUnfree in flake.nix doesn't propagate to nix develop. Use:
- nixpkgs-unfree input (recommended)
- User's
~/.config/nixpkgs/config.nix NIXPKGS_ALLOW_UNFREE=1 nix develop --impure
Duplicate Nixpkgs Downloads
Use follows to chain inputs to a single nixpkgs source.
Overlay Not Applied
Ensure overlay is in the overlays list when importing nixpkgs:
Hash Mismatch
Re-fetch with nix-prefetch-url and update the hash. Hashes change when upstream updates binaries at the same URL.


