| name | nixos-debug |
| description | Debug NixOS build and evaluation failures. Use when nixos-rebuild fails, nix flake check errors, or module evaluation produces tracebacks. Covers common error patterns, trace analysis, and targeted fix strategies for the ShizNix configuration. |
| tags | ["nix","nixos","debug","error","troubleshooting"] |
NixOS Debug Skill
Diagnose and fix NixOS build and evaluation failures in the ShizNix configuration.
When to Use
nixos-rebuild fails with evaluation errors
nix flake check reports errors
- Module options conflict or are undefined
- Build fails with derivation errors
- Infinite recursion in evaluation
- Missing packages or broken dependencies
Common Error Patterns
1. "attribute '...' is not defined" or "undefined variable"
Cause: A module option or variable is referenced but not declared or imported.
Fix:
- Check if the module is imported in the category's
default.nix
- Check if the option path matches the declaration (e.g.,
config.modules.system.boot vs config.modules.boot)
- Check if the host imports the module in its
default.nix
- Run
nix-instantiate --eval --expr 'let pkgs = import <nixpkgs> {}; in ...' to test
2. "infinite recursion encountered"
Cause: An option references itself, directly or indirectly.
Fix:
- Look for circular
mkIf dependencies
- Check that
config references don't form a loop
- Use
lib.mkOverride or lib.mkDefault to break cycles
- Common pattern:
config.modules.X.Y.enable referencing config.modules.X.Y.someOption that depends on the same module
3. "cannot find attribute" in flake check
Cause: A new file wasn't git added before building.
Fix: git add <new-file> then rebuild. Nix flakes only see tracked files.
4. Build failure: "error: builder for ... failed"
Cause: A package derivation failed to build (compilation error, missing dependency, etc.).
Fix:
- Check the full build log:
nix log <derivation-path>
- For package overrides in
overlays/, check the patch or override logic
- For custom packages in
pkgs/, check the derivation
5. "option `modules.X.Y.enable' is used but not defined"
Cause: A module references an option that doesn't exist.
Fix:
- Check the option declaration path in the module file
- Ensure the module is imported before it's used
- Check for typos in the option path
6. "attribute '...' at ... does not have attribute '...'"
Cause: A nested option path is wrong.
Fix: Check the full option path. Common mistake: config.modules.system.boot when the module declares options.modules.boot.
Diagnostic Commands
nixos-rebuild build --flake .#bhairavi --show-trace
nix-instantiate --eval -E '(import ./flake.nix).outputs'
nix eval --file ./modules/nixos/system/boot.nix --json
nix eval nixos#modules.system.boot.enable
nix log /nix/store/<hash>-<name>.drv
nixos-rebuild dry-build --flake .#bhairavi
Workflow
- Reproduce the error with
--show-trace
- Read the trace from bottom to top (the actual error is usually at the bottom)
- Identify the error pattern from the list above
- Fix the root cause (not the symptom)
- Verify with
nixos-rebuild build --flake .#bhairavi
- Format with
alejandra after fixing