AgentSkillsCN

skill-debug-eval

诊断和修复 Nix 求值错误、构建失败和模块冲突。

SKILL.md
--- frontmatter
name: skill-debug-eval
description: Diagnose and fix Nix evaluation errors, build failures, and module conflicts.
tags: [nixos, debug, eval, build, error]
when_to_use: Build fails, eval errors, infinite recursion, attribute not found
blast_radius: LOW

Debug Nix Eval/Build Failure

Load fact-nix for module patterns if needed.

Quick Start

bash
# Capture full trace (don't lose root cause)
nix build .#nixosConfigurations.<host>.config.system.build.toplevel --show-trace 2>&1 | tee /tmp/nix-error.log

# Find repo-specific lines
grep "serenitea-pot" /tmp/nix-error.log

# Interactive debugging
nix develop .#repl

Common Errors

ErrorLikely CauseFix
attribute 'X' missingTypo, missing importCheck spelling, verify module loaded
attribute 'codgician' missingWrong builderUse lib.codgician.mkNixosSystem
infinite recursionSelf-referential optionCheck defaults, circular mkIf
expected X but got YWrong option typeCheck type in REPL
assertion failedConstraint violationEnable required dependency
builder failedDerivation errorCheck nix log, deps, tests

Debugging Patterns

Attribute Missing

nix
# Wrong scope (config not available in options)
options.myOption = lib.mkOption {
  default = config.other.option;  # ERROR
};

# Correct: use in config section
config = lib.mkIf cfg.enable {
  value = config.some.option;  # OK
};

Infinite Recursion

nix
# Self-referential default
myOption = lib.mkOption {
  default = config.myOption;  # RECURSION
};

# Circular mkIf
(lib.mkIf config.a.enable { b.enable = true; })
(lib.mkIf config.b.enable { a.enable = true; })  # RECURSION

Add Traces

nix
config = lib.mkIf (builtins.trace "evaluating mymodule" cfg.enable) { };
myValue = lib.traceValSeq myValue;

Diagnostic Commands

bash
# REPL inspection
nix develop .#repl
# Then: nixosConfigurations.<host>.config.services.nginx
# Then: nixosConfigurations.<host>.config ? codgician

# Build log for derivation failures
nix log /nix/store/XXX-mypackage.drv

# Binary search with git bisect
git bisect start && git bisect bad HEAD && git bisect good <working>

Exit Criteria

  • Error message understood
  • Root cause identified (not just symptom)
  • Fix applied
  • nix flake check passes
  • nix build succeeds

Note: Do not commit — present fix to user.