Repository navigation
fix: nested includes scoping and content wrapper callability - #527
Merged
Merged
Conversation
When an aspect's includes list references its own nested sub-keys, suppress auto-walk so only explicitly included sub-aspects are active. This aligns direct nesting behavior with provides, where forwarded keys are excluded from classification via __providesForwarded. Also make single-function content wrappers callable by adding __functor. Without this, den.aspects.X.Y where Y is a function (parametric aspect) can't be invoked as (den.aspects.X.Y arg) unless using provides (_.Y).
Addresses code review: compare full provider path instead of just leaf name to prevent theoretical false positives when unrelated aspects share names. Also adds cross-aspect name collision test.
Collaborator
Author
|
Fixing another regression I found during implementation. |
drupol
approved these changes
May 13, 2026
Nested sub-aspects are no longer auto-walked. They must be explicitly
included to emit class modules, matching provides behavior and making
activation explicit.
Multi-def merge is fixed at the source: aspectContentType.merge now
produces per-key merged values instead of lossy shallow-merge. This
eliminates the need for mergeContentValuesPerKey in the pipeline —
every consumer sees properly merged keys regardless of code path.
Also removes emitNestedAspect (dead code with nestedToWalk always [])
and mergeContentValuesPerKey from content-util (no longer needed).
Single-function content wrappers get __functor for callability without
provides (den.aspects.X.Y = fn: {...} is now callable).
|
Found an issue with deeply nested sub-aspects that are defined in separate files. test-something = denTest (
{ den, igloo, ... }:
{
# fails
imports = [
{ den.aspects.root.sub1.sub2.a.nixos.environment.variables.FROM_A = "yes"; }
];
# passes
# den.aspects.root.sub1.sub2.a.nixos.environment.variables.FROM_A = "yes";
den.aspects.root.sub1.sub2.b.nixos.environment.variables.FROM_B = "yes";
den.hosts.x86_64-linux.igloo.users.tux = { };
den.aspects.igloo.includes = [
den.aspects.root.sub1.sub2.a
den.aspects.root.sub1.sub2.b
];
expr = {
hasA = igloo.environment.variables ? FROM_A;
hasB = igloo.environment.variables ? FROM_B;
};
expected = {
hasA = true;
hasB = true;
};
}
); |
When a host aspect has a nested key matching a declared user name (e.g., den.aspects.igloo.tux where tux is a user), the host-to-users policy now emits a policy.include for it. This activates entity-named sub-aspects without auto-walk — the policy layer handles it. Keys already in __providesForwarded are excluded to prevent double activation (provides path already handles those via mkCrossPolicy).
Remove unwrapContentValuesRaw (no longer imported after emitNestedAspect removal) and unreachable else branch in aspectContentType per-key merge.
aspectContentType.merge: skip per-key merge when there's only one attrset definition (the common case). Avoids eager key enumeration via lib.unique/concatMap on the hot path. host-to-users policy: hoist forwarded set above concatMap so it's computed once per host instead of per user. Inline entityAspectChild as lib.optional for directness.
Collaborator
Author
When a per-key merge produces a __contentValues wrapper (multi-def case), shallow-forward the attrset sub-keys onto it so deeper nested access works (e.g., den.aspects.root.sub1.sub2.a where sub2 is defined across separate module imports).
Collaborator
Author
|
The above commit is a band-aid that fixes this edge case, but the right solution is going to be a refactor of the wrapping mechanism. At the expense of some scope creep, I'm going to try and tackle the refactor. |
Collaborator
Author
|
Okay, I've confirmed that the scope for this refactor is going to actually scope creep to nearly the size of the already designed flake-aspect 2.0 library extraction effort scheduled for next week/after we do this point release so I'm going to leave the band-aid for now. We know what to replace, and we now have these tests to make sure we don't reintroduce the regression. Going to merge this. |
charlesfire
pushed a commit
to charlesfire/den
that referenced
this pull request
May 16, 2026
) ## Summary Three fixes for users migrating from `provides`/`_` to direct nesting: **1. Nested sub-aspects no longer auto-walk.** They must be explicitly included to emit class modules. This matches provides behavior and makes activation explicit. `den.aspects.root = { includes = [ den.aspects.root.a ]; a.nixos...; b.nixos...; }` now correctly includes only `a`. **2. Multi-def merge fixed at the source.** `aspectContentType.merge` now produces per-key merged values instead of lossy shallow-merge (`foldl' //`). When multiple modules define `den.aspects.system.base.nixos`, all definitions contribute. This eliminates `mergeContentValuesPerKey` from the pipeline — every consumer sees properly merged keys regardless of code path. **3. Single-function content wrappers are callable.** `den.aspects.X.Y = fn:` now gets `__functor` so `(den.aspects.wm.gnome-autologin "benjamin")` works without `provides`. ### Changes - `nix/lib/aspects/types.nix` — per-key merge in `aspectContentType.merge`, `__functor` for single-function wrappers - `nix/lib/aspects/fx/handlers/compile-static.nix` — remove auto-walk (`nestedToWalk`, `emitNestedAspect`), net -80 lines - `nix/lib/aspects/fx/content-util.nix` — remove now-unused `mergeContentValuesPerKey` - 6 test files — update expectations, add explicit includes ### Known limitation `nested-aspects.test-direct-nesting-basic` fails — entity-linked nested keys (`igloo.tux` where `tux` is a declared user) previously relied on auto-walk for activation. Policy-driven activation for these is a separate design topic. ## Test plan - [x] 784/785 CI tests pass (1 known: entity-linked activation) - [x] Multi-def merge: `deadbugs.nested-aspect-merge`, `deadbugs.content-wrapper-functor` - [x] No auto-walk: `deadbugs.nested-includes-scoping` - [x] Explicit includes: `nested-aspects`, `structural-detection` - [x] Formatted with `just fmt` 🤖 Generated with [Claude Code](https://claude.com/claude-code)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Summary
Three fixes for users migrating from
provides/_to direct nesting:1. Nested sub-aspects no longer auto-walk. They must be explicitly included to emit class modules. This matches provides behavior and makes activation explicit.
den.aspects.root = { includes = [ den.aspects.root.a ]; a.nixos...; b.nixos...; }now correctly includes onlya.2. Multi-def merge fixed at the source.
aspectContentType.mergenow produces per-key merged values instead of lossy shallow-merge (foldl' //). When multiple modules defineden.aspects.system.base.nixos, all definitions contribute. This eliminatesmergeContentValuesPerKeyfrom the pipeline — every consumer sees properly merged keys regardless of code path.3. Single-function content wrappers are callable.
den.aspects.X.Y = fn:now gets__functorso(den.aspects.wm.gnome-autologin "benjamin")works withoutprovides.Changes
nix/lib/aspects/types.nix— per-key merge inaspectContentType.merge,__functorfor single-function wrappersnix/lib/aspects/fx/handlers/compile-static.nix— remove auto-walk (nestedToWalk,emitNestedAspect), net -80 linesnix/lib/aspects/fx/content-util.nix— remove now-unusedmergeContentValuesPerKeyKnown limitation
nested-aspects.test-direct-nesting-basicfails — entity-linked nested keys (igloo.tuxwheretuxis a declared user) previously relied on auto-walk for activation. Policy-driven activation for these is a separate design topic.Test plan
deadbugs.nested-aspect-merge,deadbugs.content-wrapper-functordeadbugs.nested-includes-scopingnested-aspects,structural-detectionjust fmt🤖 Generated with Claude Code