This skill helps you configure NixOS with flakes and overlays correctly, ensuring useGlobalPkgs boundaries and proper host structure for reliable changes.
npx playbooks add skill lihaoze123/my-claude-code --skill nixos-best-practices
Configure NixOS systems with flakes, manage overlays properly, and structure configurations for maintainability.
BEFORE making ANY NixOS configuration changes, you MUST:
Do NOT start coding until you've read the applicable documentation.
Most configuration errors happen from not reading the rules first. The 5 minutes you spend reading will save hours of debugging.
Understand the interaction between NixOS system configuration and Home Manager overlays.
When useGlobalPkgs = true, overlays must be defined at the NixOS configuration level, not in Home Manager configuration files.
useGlobalPkgs = true with custom overlaysDon't use for:
| Topic | Rule File |
|-------|-----------|
| Overlay scope and useGlobalPkgs | [overlay-scope](rules/overlay-scope.md) |
| Flakes configuration structure | [flakes-structure](rules/flakes-structure.md) |
| Host configuration organization | [host-organization](rules/host-organization.md) |
| Package installation best practices | [package-installation](rules/package-installation.md) |
| Common configuration mistakes | [common-mistakes](rules/common-mistakes.md) |
| Debugging configuration issues | [troubleshooting](rules/troubleshooting.md) |
# ❌ WRONG: Overlay in home.nix (doesn't apply)
# home-manager/home.nix
{
nixpkgs.overlays = [ inputs.claude-code.overlays.default ]; # Ignored!
home.packages = with pkgs; [ claude-code ]; # Not found!
}
# ✅ CORRECT: Overlay in NixOS home-manager block
# hosts/home/default.nix
{
home-manager.useGlobalPkgs = true;
home-manager.useUserPackages = true;
home-manager.users.chumeng = import ./home.nix;
home-manager.extraSpecialArgs = { inherit inputs pkgs-stable system; };
# Overlay must be HERE when useGlobalPkgs = true
nixpkgs.overlays = [ inputs.claude-code.overlays.default ];
}
| Task | Solution |
|------|----------|
| Add flake input | Add to inputs in flake.nix |
| Add overlay for system packages | Define in nixpkgs.overlays in system configuration |
| Add overlay for home-manager (useGlobalPkgs=true) | Define in home-manager.nixpkgs.overlays in host config |
| Add overlay for home-manager (useGlobalPkgs=false) | Define in home.nix with nixpkgs.overlays |
| Pass inputs to modules | Use specialArgs in nixosSystem or home-manager |
| Multiple host configurations | Create separate host files in hosts/ |
| Shared configuration modules | Create modules in modules/ and import in each host |
| Package not found after overlay | Check overlay scope vs useGlobalPkgs setting |
| useGlobalPkgs | Overlay Definition Location | Affects |
|---------------|---------------------------|---------|
| true | home-manager.nixpkgs.overlays | System + Home Manager packages |
| true | home.nix with nixpkgs.overlays | Nothing (ignored!) |
| false | home.nix with nixpkgs.overlays | Home Manager packages only |
| false | home-manager.nixpkgs.overlays | Home Manager packages only |
| Any | System nixpkgs.overlays | System packages only |
/etc/nixos/configuration.nix or host files)Read individual rule files for detailed explanations and code examples:
rules/overlay-scope.md # The core overlay scope issue
rules/flakes-structure.md # How to organize flake.nix
rules/host-organization.md # How to structure host configs
rules/common-mistakes.md # Pitfalls and how to avoid them
Each rule file contains:
For the complete guide with all rules expanded: AGENTS.md
Weekly roundup of top Claude Code skills, MCP servers, and AI coding tips.