Manages Nix flakes, inputs, dependency resolution, and performance optimization. Use when working with flake.nix, updating inputs, debugging evaluation errors, optimizing flake performance, or composing multi-flake architectures.
Installation
Details
Usage
After installing, this skill will be available to your AI coding assistant.
Verify installation:
skills listSkill Instructions
name: managing-flakes description: Manages Nix flakes, inputs, dependency resolution, and performance optimization. Use when working with flake.nix, updating inputs, debugging evaluation errors, optimizing flake performance, or composing multi-flake architectures.
Managing Flakes
Flake Schema & Evaluation
Master the Nix flake schema, evaluation mechanics, and advanced patterns.
Evaluation Phases
- Input resolution: Lock file generation (
flake.lock) - System parameters: Flake function evaluation
- Output construction:
packages,apps,devShells - Lazy boundaries: Only evaluate what is requested
Common Outputs
packages.${system}.default: Main packagedevShells.${system}.default: Development environmentnixosConfigurations.${hostname}: System configapps.${system}.default: Runnable applications
Composition Patterns
Multi-Flake Architecture
- Separation of concerns: Split monolithic flakes into logical components
- Shared configuration: Use centralized flakes for common settings
- Inheritance: Pass inputs from parent to child flakes
Modular Design
- Components: Break flakes into
modules/ - Reusability: Export reusable functions in
liboutput - Extension: Use generic flake inputs for plugins
Common Tasks
Task 1: Update a single input
# Update specific input
nix flake update nixpkgs
# Or update all inputs
nix flake update
Task 2: Add a new input
# In flake.nix
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
# Add new input
new-input = {
url = "github:owner/repo";
inputs.nixpkgs.follows = "nixpkgs"; # Deduplicate nixpkgs
};
};
Why follows?: Prevents multiple nixpkgs versions in closure, speeds up
evaluation.
Task 3: Use a local development flake
# Point to local directory during development
nix registry add my-flake path:/home/user/my-flake
# Now can reference without full path
nix shell my-flake#package
Task 4: Debug slow evaluation
# Show evaluation trace
nix eval .#nixosConfigurations.<host>.config --show-trace
# Profile evaluation
NIX_SHOW_STATS=1 nix eval .#nixosConfigurations.<host>.config
# Look for:
# - Large imports (can these be lazy-loaded?)
# - Repeated nixpkgs imports (use follows?)
# - Unnecessary full-package-set evaluations
Input Management & Follows
Input Management Decision Tree
Adding a new dependency:
-
Is it in nixpkgs already?
- Yes → No new input needed, just reference
pkgs.package-name - No → Continue to step 2
- Yes → No new input needed, just reference
-
Does it depend on nixpkgs?
- Yes → Add
inputs.nixpkgs.follows = "nixpkgs"to deduplicate - No → Skip follows
- Yes → Add
-
Is it from GitHub?
- Yes → Use
github:owner/repo(faster, cached) - No → Use appropriate URI scheme (git+ssh, path, file)
- Yes → Use
-
Is this for development only?
- Yes → Consider registry instead of hard input
- No → Add as regular input
Example: Adding home-manager
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
home-manager = {
url = "github:nix-community/home-manager";
inputs.nixpkgs.follows = "nixpkgs"; # Step 2: Deduplicate
};
};
Optimization
- Deduplication: Use
inputs.<name>.followsto share dependencies - Circular dependencies: Avoid loops in follows chains
- Registry: Map local flakes for development (
nix registry add)
URI Schemes
github:owner/repo: GitHub repositorygit+ssh://...: Private Git repositorypath:.: Local directory (requires absolute path or git tracking)file:///...: Local file system (no git requirement)
Performance Optimization
Best Practices
- Laziness: Avoid
importof unused large files - Filtering: Use
nix-filterorlib.cleanSourceto reduce context - Caching: Utilize
eval-cachewhere possible - Profiling: Use
nix build --show-traceto find bottlenecks
Anti-Patterns
- Eagerly evaluating full package sets
- Importing
nixpkgsmultiple times withoutfollows - Checking in massive
flake.lockfiles generated by poor input management
See Also
- Validation: See validating-nix for debugging evaluation errors and build failures
More by khaneliman
View allCreate development environment templates and project scaffolding with Nix flakes. Use when creating new project templates, setting up dev shells, configuring language-specific environments, or integrating with CI/CD.
Manages encrypted secrets using sops-nix and age. Use when adding new secrets, rotating keys, debugging secret access, or setting up secret management for new hosts/users.
Conduct thorough, actionable code reviews focusing on critical issues. Use when reviewing pull requests, analyzing code changes, identifying bugs, security vulnerabilities, or suggesting improvements that developers will actually implement.
khanelinix directory structure and module placement. Use when creating new modules, deciding where files belong, or understanding the modules/ organization. Covers platform separation (nixos/darwin/home/common) and auto-discovery.
