debugging
Troubleshoot Nix evaluation and build errors
Installation
Suivez les instructions du dépôt pour votre agent. Consultez les fichiers et dépendances avant l’installation.
Voir la source ↗GuidesInstructions
Debugging
Evaluation Debugging
Using builtins.trace
Add trace statements to see values during evaluation:
let
myValue = builtins.trace "myValue is: ${toString someVar}" someVar;
in
# myValue will print during evaluation
For complex values:
builtins.trace (builtins.toJSON someAttrSet) someAttrSet
Using nix eval
Test expressions without building:
# Evaluate a specific option
nix eval .#nixosConfigurations.nixdev.config.networking.hostName
# Check if something evaluates
nix eval .#nixosConfigurations.nixdev.config.services.nginx.enable
# Evaluate with trace output visible
nix eval .#nixosConfigurations.nixdev.config.system.build.toplevel --apply 'x: "ok"'
Show trace on error
nix build .#nixosConfigurations.nixdev.config.system.build.toplevel --show-trace
Common Errors
Infinite recursion
Error: infinite recursion encountered
Causes:
- Circular imports between modules
- Option depending on itself
- Config referencing options that reference config
Fix: Check for circular dependencies in imports or option definitions.
Attribute not found
Error: attribute 'foo' missing
Causes:
- Typo in attribute name
- Missing import
- Wrong option path
Fix:
# List available attributes
nix eval .#nixosConfigurations.nixdev.config.services --apply 'builtins.attrNames'
Type mismatch
Error: value is a string while a list was expected
Causes:
- Wrong type for option
- Incompatible merge of values
Fix: Check option type definition and provided value.
Assertion failed
Error: assertion ... failed
Causes:
- Configuration constraint not met
- Missing required option
Fix: Read the assertion message, provide required configuration.
Build Debugging
View build logs
# For a failed derivation
nix log /nix/store/...-derivation.drv
# Or from error output
nix log <drv-path-from-error>
Build with verbose output
nix build .#package -L
Enter build environment
nix develop .#nixosConfigurations.nixdev.config.system.build.toplevel
Module Debugging
Check if module is imported
nix eval .#nixosConfigurations.nixdev.config.services.myService.enable
List all options in a namespace
nix eval .#nixosConfigurations.nixdev.options.services.myService --apply 'builtins.attrNames'
Check option definition location
nix eval .#nixosConfigurations.nixdev.options.services.nginx.enable.definitionsWithLocations
Flake Debugging
Check flake syntax
nix flake check --no-build
Show flake structure
nix flake show
Evaluate specific output
nix eval .#nixosConfigurations --apply 'builtins.attrNames'
nix eval .#homeConfigurations --apply 'builtins.attrNames'
Quick Diagnostics
| Problem | Command |
|---|---|
| Does it evaluate? | nix eval .#... --apply 'x: "ok"' |
| What options exist? | nix eval .#...options --apply 'builtins.attrNames' |
| What's the value? | nix eval .#...config.<path> |
| Where's the error? | nix build --show-trace |
| What went wrong in build? | nix log <drv> |
| Is syntax valid? | nix flake check --no-build |
Exemples
Consultez les exemples du dépôt source.
Voir la source ↗Historique source
- Date d’indexation
- 2026-01-20
- Mise à jour de l’index
- 2026-01-26
- Branch
- main
Les dates concernent ce répertoire. Consultez le dépôt pour l’historique du code.
GitHub ↗chat Comments (0)
Sign in to join the discussion and leave a comment.
No comments yet. Be the first to share your thoughts!