| name | Nix Helper |
| description | This skill should be used when the user asks to "add a new package", "configure a new program", "troubleshoot Nix build errors", "update flake inputs", "add a new host", "manage secrets with SOPS", "create out-of-store symlink", "use nvfetcher", "use claude-code-overlay", or mentions Nix, Home Manager, or nix-darwin configuration in this dotfiles repository. |
Nix Helper
Provide guidance for managing Nix configurations in this dotfiles repository.
Configuration Overview
This dotfiles repository uses:
- Nix Flakes as the primary configuration entry point
- nix-darwin for macOS system-level configuration
- Home Manager for user-level configuration
- SOPS for secrets management
- nvfetcher for external packages not in nixpkgs
- claude-code-overlay for the claude-code package
Directory Structure
.
โโโ flake.nix # Entry point (inputs, outputs, host configurations)
โโโ hosts/ # Machine-specific configurations
โ โโโ kohei-m4-mac-mini/ # Personal machine config
โ โโโ SC-N-843/ # Work machine config
โโโ nix-darwin/ # System-level macOS configurations
โ โโโ default.nix # Full configuration (personal machines)
โ โโโ minimum-for-work.nix # Minimal configuration (work machines)
โโโ home-manager/ # User-level configurations
โ โโโ programs/ # Individual program configurations
โ โโโ pkgs/ # Package list (default.nix)
โ โโโ services/ # User-level services
โ โโโ files.nix # Out-of-store symlink configuration
โโโ configs/ # Raw configuration files (Neovim, WezTerm, etc.)
โโโ secrets/ # SOPS-encrypted secrets
โโโ _sources/ # Auto-generated by nvfetcher
Common Tasks
Adding a New Package
Edit home-manager/pkgs/default.nix:
home.packages = with pkgs; [
# ... existing packages
new-package-name
];
See references/package-management.md for nvfetcher and external package patterns.
Adding a New Program Configuration
- Create directory:
home-manager/programs/<program-name>/
- Create
default.nix:
{ pkgs, ... }:
{
programs.<program-name> = {
enable = true;
# Configuration options
};
}
- Import in
home-manager/programs/default.nix:
let
new-program = import ./new-program { inherit pkgs; };
in
[
# ... existing programs
new-program
]
See examples/new-program.nix.example for complete examples.
Adding Config Files with Out-of-Store Symlinks
Use out-of-store symlinks for configs that need editing without Nix rebuild.
- Place files in
configs/.config/<app-name>/
- Edit
home-manager/files.nix:
xdg.configFile."app-name" = {
source = symlink /${rootDir}/.config/app-name;
recursive = true;
};
See examples/out-of-store-symlink.nix.example for patterns.
Working with Secrets
Edit encrypted secrets:
sops secrets/default.yaml
Define in module:
sops.secrets.my-secret = { };
Use the secret path:
config.sops.secrets.my-secret.path
See references/secrets-management.md for detailed SOPS workflow.
Building and Applying Changes
sudo darwin-rebuild switch --flake .#kohei-m4-mac-mini
sudo darwin-rebuild switch --flake .#SC-N-843
nix fmt
nix run .#update
nix develop -c pre-commit run --all-files
Key Patterns
userConfig Pattern
Each host defines a userConfig object passed to all modules:
userConfig = {
username = "thinceller";
homeDir = "/Users/${username}";
hostname = "kohei-m4-mac-mini";
dotfilesDir = homeDir + "/.dotfiles";
};
Access in modules via specialArgs:
{ userConfig, ... }:
{
home.username = userConfig.username;
}
Module Import Pattern
Programs return lists for flexible composition:
# home-manager/default.nix
imports = programs ++ files ++ packages ++ services;
External Package Pattern (nvfetcher)
- Define in
nvfetcher.toml
- Run
nvfetcher to generate _sources/generated.nix
- Import and use:
sources = pkgs.callPackage ../_sources/generated.nix { };
package = sources.package-name;
See references/package-management.md for detailed examples.
Troubleshooting
Build Errors
nix flake check
nix build --show-trace
darwin-rebuild build --flake .#<hostname>
Common Issues
| Issue | Solution |
|---|
| Package not found | Verify name in nixpkgs or use nvfetcher |
| Import errors | Check module path and return type (list vs attrset) |
| Symlink conflicts | Remove existing files before rebuild |
| SOPS decryption fails | Verify age key at ~/.config/sops/age/keys.txt |
Flake Lock Updates
nix flake lock --update-input <input-name>
nix run .#update
Adding a New Host
- Create
hosts/<hostname>/default.nix
- Define
userConfig:
userConfig = {
username = "username";
homeDir = "/Users/${username}";
hostname = "<hostname>";
dotfilesDir = homeDir + "/.dotfiles";
};
- Choose nix-darwin module (full or minimum-for-work)
- Add to
flake.nix darwinConfigurations
See examples/new-host.nix.example for complete template.
Additional Resources
references/package-management.md - nvfetcher, claude-code-overlay, external packages
references/secrets-management.md - SOPS workflow and best practices
references/home-manager-patterns.md - Program configuration patterns
examples/new-program.nix.example - Program configuration template
examples/new-host.nix.example - Host configuration template
examples/out-of-store-symlink.nix.example - Symlink configuration patterns