nixos-best-practices
Use when configuring NixOS with flakes, managing overlays with home-manager useGlobalPkgs, structuring NixOS configurations, or facing issues where configuration changes don't apply
What this skill does
# Configuring NixOS Systems with Flakes
Configure NixOS systems with flakes, manage overlays properly, and structure configurations for maintainability.
## ⚠️ CRITICAL: Read Before Making Changes
**BEFORE making ANY NixOS configuration changes, you MUST:**
1. **Review relevant rule files** from the Quick Reference below
2. **Check common-mistakes.md** to avoid known pitfalls
3. **Check troubleshooting.md** for systematic debugging approach
4. **Follow existing patterns** in the codebase
**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.
## Red Flags - STOP BEFORE CODING
- **"I can just try this option"** → Check if it exists in nixpkgs/Home Manager first
- **"Let me experiment with different approaches"** → Read the docs, don't guess
- **"This should work"** → Verify syntax and availability in nixpkgs
- **Making multiple rebuild attempts** → You're missing systematic debugging
- **"I remember this works"** → Docs change, verify current approach
## Core Principle
**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.
## When to Use
- Configuring NixOS with flakes and Home Manager
- Adding overlays that don't seem to apply
- Using `useGlobalPkgs = true` with custom overlays
- Structuring NixOS configurations across multiple hosts
- Package changes not appearing after rebuild
- Confused about where to define overlays
**Don't use for:**
- Packaging new software (use nix-packaging-best-practices)
- Simple package installation without overlays
- NixOS module development (see NixOS module documentation)
## Quick Reference
| 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) |
## Essential Pattern: Overlay with useGlobalPkgs
```nix
# ❌ 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 ];
}
```
## Common Tasks
| 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 |
## Overlay Scope Decision Matrix
| 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 |
## Configuration Layers (Bottom to Top)
1. **System configuration** (`/etc/nixos/configuration.nix` or host files)
- System-wide services
- System packages
- System overlays only affect this layer
2. **Home Manager (useGlobalPkgs=true)**
- Uses system pkgs (includes system overlays)
- Home Manager overlays affect both system and user packages
- Most efficient for single-user systems
3. **Home Manager (useGlobalPkgs=false)**
- Creates separate pkgs instance
- Home Manager overlays affect user packages only
- Useful for multi-user systems with different needs
## Red Flags - STOP
- "Overlay in home.nix isn't working" → Check if useGlobalPkgs=true, move to host config
- "I'll just add overlays everywhere" → Define once at appropriate scope
- "Package works in nix repl but not installed" → Check overlay scope
- "Changes don't apply after rebuild" → Verify overlay is in correct location
- "useGlobalPkgs=false for no reason" → Use true unless you need separate package sets
## How to Use
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:
- Brief explanation of why it matters
- Incorrect code example with explanation
- Correct code example with explanation
- Additional context and references
## Full Compiled Document
For the complete guide with all rules expanded: `AGENTS.md`
Related in General
modeling-omnistudio-epc-catalog
IncludedSalesforce Industries CME EPC product-modeling skill for Product2-based catalog creation. Use when creating EPC products, configuring product attributes, building offer bundles with Product Child Items, or reviewing EPC DataPack JSON metadata for product catalog changes. TRIGGER when: user creates or updates Product2 EPC records, AttributeAssignment payloads, AttributeMetadata/AttributeDefaultValues, Offer bundles, or ProductChildItem relationships. DO NOT TRIGGER when: designing OmniScripts/FlexCards/Integration Procedures (use building-omnistudio-omniscript, building-omnistudio-flexcard, or building-omnistudio-integration-procedure), implementing Apex business logic (use generating-apex), or troubleshooting deployment pipelines (use deploying-metadata).
relationship-science-coach
IncludedUse this skill for direct, practical adult relationship coaching: couples conflict, repair, trust, marriage, dating, flirting, attachment patterns, emotional connection, sex, desire differences, eroticism, kink negotiation, affection, love languages, breakups, and long-term passion. Draw on Gottman, EFT and Hold Me Tight, attachment science, modern sex research, Perel, Nagoski, Kerner, Schnarch, Love and Stosny, and flexible love-language tools. Be concrete and low-hedge. Redirect only for imminent danger, abuse, coercive control, minors, non-consent, self-harm, stalking, or medical/legal/psychiatric decisions.
building-sf-integrations
IncludedSalesforce integration architecture and runtime plumbing with 120-point scoring. Use this skill to set up Named Credentials, External Credentials, External Services, REST/SOAP callout patterns, Platform Events, and Change Data Capture. TRIGGER when: user sets up Named Credentials, External Services, REST/SOAP callouts, Platform Events, CDC, or touches .namedCredential-meta.xml files. DO NOT TRIGGER when: Connected App/OAuth config (use configuring-connected-apps), Apex-only logic (use generating-apex), or data import/export (use handling-sf-data).
venue-templates
IncludedAccess comprehensive LaTeX templates, formatting requirements, and submission guidelines for major scientific publication venues (Nature, Science, PLOS, IEEE, ACM), academic conferences (NeurIPS, ICML, CVPR, CHI), research posters, and grant proposals (NSF, NIH, DOE, DARPA). This skill should be used when preparing manuscripts for journal submission, conference papers, research posters, or grant proposals and need venue-specific formatting requirements and templates.
let-fate-decide
IncludedDraws the 12 Houses of the Zodiac Tarot spread to inject entropy into planning when prompts are vague, ambiguous, or casually delegated. Interprets the spread to guide next steps. Use when the user says 'let fate decide', 'YOLO', 'whatever', 'idk', or other nonchalant phrases, makes Yu-Gi-Oh references, or when you are about to arbitrarily pick between multiple reasonable approaches. Prefer over ask-questions-if-underspecified when the user's tone is casual or playful rather than precision-seeking.
net-ops
IncludedCross-platform network troubleshooting (Windows, macOS, Linux) via local or remote shell. Use for: DNS broken, can't resolve hostnames, nslookup/dig works but apps fail, NRPT, WFP, scutil, /etc/resolver, systemd-resolved, /etc/resolv.conf, NetworkManager, VPN DNS leak residue (ProtonVPN/Mullvad/WireGuard/AnyConnect), AV/firewall blocking DNS or DoH, Tailscale DNS interaction, intermittent connectivity, remote diagnostics over SSH.