Skip to content

fix: don't force aspect content during key classification (#580) - #581

Merged
theutz merged 1 commit into
denful:mainfrom
sini:fix/580-classification-self-output-recursion
May 31, 2026
Merged

theutz merged 1 commit into
denful:mainfrom
sini:fix/580-classification-self-output-recursion

Conversation

@sini

@sini sini commented May 31, 2026

Copy link
Copy Markdown
Collaborator

Problem

Fixes #580. Consuming a flake self-output from an unregistered aspect key threw infinite recursion encountered:

den.default.nixpkgs.overlays = builtins.attrValues self.outputs.overlays;

Worked in v0.16; regressed with the fx-pipeline rewrite (#475). Present on main — independent of #575.

Root cause

key-classification.nix decided whether an unregistered key was a nested sub-aspect by descending through its value with builtins.isAttrs (val.${sk} or null), which forces every sub-value to WHNF. Classification runs while the flake output set is being assembled, so forcing a value that reads self.outputs re-enters the flake self fixpoint (outputs = flake.outputs (inputs // { self = result; })) → infinite recursion.

Registered class keys (nixos/darwin/homeManager) bypass this path and stay lazy until NixOS-module build time (after the self fixpoint resolves), which is why only unregistered keys like nixpkgs cycled. builtins.tryEval cannot guard it — it does not catch infinite recursion.

Fix

Detect nested aspects from recognized key names (class / pipe / structural like includes) at the value's top level, forcing a sub-value only when its name matches a registered class — never under arbitrary content keys.

This is sound because nested sub-aspects are never auto-walked (see compile-static); they activate via explicit includes, so every nested aspect exposes a recognized key at its own top level. The value-forcing descent was unnecessary.

Notes on the original report

Verified empirically: the forwarder and the homeManager user were incidental — the minimal trigger is just an unregistered key reading self.outputs.*. Also confirmed this is not the stack-overflow addressed by #579 (distinct error class; the recursion persists with #579 merged).

Validation

  • New regression test deadbugs/issue-580-self-output-classification-recursion.nix (repro + a registered-key boundary guard): infinite recursion → ✅ 2/2
  • Real-world repro flake (musjj/recursion-bug, full forwarder + homeManager + self.outputs.overlays): infinite recursion → evaluates
  • Full CI: 837/837 ✅

Classifying an unregistered aspect key as nested-or-content walked the
value with `builtins.isAttrs (val.${sk} or null)`, forcing every sub-value
to WHNF. Classification runs while the flake output set is assembled, so a
value reading the flake's own `self.outputs` (e.g.
`nixpkgs.overlays = builtins.attrValues self.outputs.overlays`) re-entered
the `self` fixpoint and threw "infinite recursion encountered". Registered
class keys bypass this path, so only unregistered keys cycled.

Detect nested aspects from recognized key names (class / pipe / structural
like `includes`) at the value's top level, forcing a sub-value only when its
name matches a registered class. Sub-aspects are never auto-walked — they
activate via explicit `includes` — so every nested aspect exposes a
recognized key at its own top level, making the value-forcing descent
unnecessary.

The forwarder and homeManager user in the original report were incidental;
neither is required to trigger the recursion.
@sini
sini requested a review from vic as a code owner May 31, 2026 01:30
@github-actions github-actions Bot added the allow-ci allow all CI integration tests label May 31, 2026
@theutz
theutz enabled auto-merge (squash) May 31, 2026 06:15
@theutz
theutz merged commit f0b1cfa into denful:main May 31, 2026
44 of 51 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

allow-ci allow all CI integration tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BUG: Recursion error when consuming self.outputs.overlays

2 participants