nix-executor
Use when you need to test Nix expressions, validate Nix configuration syntax before applying, debug Nix code or understand evaluation results, inspect derivation attributes, or evaluate flake outputs and inputs
$ Installieren
git clone https://github.com/kitsunoff/Nix /tmp/Nix && cp -r /tmp/Nix/dotfiles/skills/nix-executor ~/.claude/skills/Nix// tip: Run this command in your terminal to install the skill
name: nix-executor description: Use when you need to test Nix expressions, validate Nix configuration syntax before applying, debug Nix code or understand evaluation results, inspect derivation attributes, or evaluate flake outputs and inputs license: MIT
Nix Code Executor
This skill provides safe execution and evaluation of Nix code, including expressions, derivations, and configuration validation.
What This Skill Does
This skill helps you:
- Evaluate Nix expressions and see their results
- Test Nix derivations before building
- Validate Nix configuration syntax
- Debug Nix code issues
- Inspect Nix store paths and attributes
When to Use This Skill
Use this skill when you need to:
- Test a Nix expression to see what it evaluates to
- Validate Nix configuration syntax before applying
- Debug Nix code or understand evaluation results
- Inspect derivation attributes
- Evaluate flake outputs or inputs
Instructions
When this skill is activated, follow these steps:
1. Determine the Execution Type
Identify what kind of Nix operation is needed:
- Expression evaluation: Use
nix evalfor simple expressions - Instantiation: Use
nix-instantiateto build derivations - Flake evaluation: Use
nix evalwith flake references - Build testing: Use
nix build --dry-runfor dry runs - Configuration check: Use
nix-instantiate --evalfor config validation
2. Choose the Appropriate Command
For simple expressions:
nix eval --expr 'EXPRESSION'
For file-based expressions:
nix-instantiate --eval FILE.nix
For flake outputs:
nix eval .#OUTPUT_PATH
For pretty JSON output:
nix eval --json --expr 'EXPRESSION' | jq
For dry-run builds:
nix build --dry-run .#PACKAGE
For checking derivation attributes:
nix derivation show .#PACKAGE
3. Safety Considerations
- Use
--dry-runwhen you don't want to actually build anything - Use
--read-onlyflag when evaluating untrusted code - Wrap expressions in
--exprto avoid file system modifications - Check for evaluation errors before proceeding with builds
4. Common Use Cases
Evaluate a simple expression:
nix eval --expr '1 + 1'
nix eval --expr 'builtins.toString (map (x: x * 2) [1 2 3])'
Check flake configuration:
nix eval .#nixosConfigurations.HOSTNAME.config.system.build.toplevel
Test attribute existence:
nix eval --expr 'builtins.hasAttr "attr" { attr = 1; }'
Inspect package metadata:
nix eval --json nixpkgs#package.meta | jq
Validate Nix file syntax:
nix-instantiate --parse FILE.nix
5. Error Handling
When evaluation fails:
- Check the error message for syntax issues
- Use
--show-tracefor detailed error traces - Validate individual subexpressions
- Check for infinite recursion with
--max-call-depth
Example with trace:
nix eval --show-trace --expr 'EXPRESSION'
6. Output Formatting
Control output format based on needs:
- Default: Nix expression format
--json: JSON format (parseable)--raw: Raw output without quotes--apply: Transform output with a function
7. Working with Files
Evaluate specific attributes:
nix-instantiate --eval --strict --attr attrPath file.nix
Import and evaluate:
nix eval --expr 'import ./file.nix'
Examples
Example 1: Test a Nix Expression
nix eval --expr 'let pkgs = import <nixpkgs> {}; in pkgs.lib.version'
Example 2: Validate Flake Output
nix eval .#darwinConfigurations.MacBook-Pro-Maxim.system
Example 3: Debug Configuration Value
nix eval --json .#nixosConfigurations.hostname.config.services.openssh.enable
Example 4: Check Package Availability
nix eval --expr 'builtins.hasAttr "opencode" (import <nixpkgs> {})'
Example 5: Inspect Derivation
nix derivation show nixpkgs#hello
Best Practices
- Start Simple: Test small expressions before complex ones
- Use --dry-run: Avoid unintended builds during testing
- Check Syntax First: Use
nix-instantiate --parseto validate syntax - Use --show-trace: Get detailed error information when debugging
- Format Output: Use
--jsonwithjqfor readable structured output - Test Incrementally: Break complex expressions into smaller testable parts
Troubleshooting
Common Issues
Infinite Recursion:
# Use --max-call-depth to prevent runaway evaluation
nix eval --max-call-depth 1000 --expr 'EXPRESSION'
Path Not Found:
# Ensure you're in the right directory for relative imports
# Or use absolute paths
nix eval --expr 'import /absolute/path/to/file.nix'
Attribute Missing:
# Check if attribute exists first
nix eval --expr 'builtins.attrNames (import ./file.nix)'
References
Repository
