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",...
Provide guidance for managing Nix configurations in this dotfiles repository.
This dotfiles repository uses:
.
āāā 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
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.
home-manager/programs/<program-name>/default.nix:{ pkgs, ... }:
{
programs.<program-name> = {
enable = true;
# Configuration options
};
}
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.
Use out-of-store symlinks for configs that need editing without Nix rebuild.
configs/.config/<app-name>/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.
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.
# Apply configuration for specific host
sudo darwin-rebuild switch --flake .#kohei-m4-mac-mini
sudo darwin-rebuild switch --flake .#SC-N-843
# Format all Nix and Lua files
nix fmt
# Update all flake inputs
nix run .#update
# Run pre-commit hooks
nix develop -c pre-commit run --all-files
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;
}
Programs return lists for flexible composition:
# home-manager/default.nix
imports = programs ++ files ++ packages ++ services;
nvfetcher.tomlnvfetcher to generate _sources/generated.nixsources = pkgs.callPackage ../_sources/generated.nix { };
package = sources.package-name;
See references/package-management.md for detailed examples.
# Validate flake
nix flake check
# Show detailed error
nix build --show-trace
# Test configuration without applying
darwin-rebuild build --flake .#<hostname>
| 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 |
# Update specific input
nix flake lock --update-input <input-name>
# Update all inputs
nix run .#update
hosts/<hostname>/default.nixuserConfig:userConfig = {
username = "username";
homeDir = "/Users/${username}";
hostname = "<hostname>";
dotfilesDir = homeDir + "/.dotfiles";
};
flake.nix darwinConfigurationsSee examples/new-host.nix.example for complete template.
references/package-management.md - nvfetcher, claude-code-overlay, external packagesreferences/secrets-management.md - SOPS workflow and best practicesreferences/home-manager-patterns.md - Program configuration patternsexamples/new-program.nix.example - Program configuration templateexamples/new-host.nix.example - Host configuration templateexamples/out-of-store-symlink.nix.example - Symlink configuration patterns