Repository navigation
fix: a schema-included parametric aspect keeps its own identity, so excludes match it - #728
Merged
Merged
Conversation
theutz
approved these changes
Oct 15, 2026
sini
added a commit
that referenced
this pull request
Oct 15, 2026
…ts in includes (#729) ## Summary This is the second excludes gap: `den.lib.policy.exclude <aspect>`, returned by a policy that sits in an aspect's `includes`, was ignored. It was traced from a nix-config host: a microVM guest whose `tailscale` aspect, pulled in through a role, still declared its age secret. ```nix den.aspects.role.includes = [ den.aspects.feat ]; den.policies.drop-feat = { host, ... }: [ (den.lib.policy.exclude den.aspects.feat) ]; den.aspects.igloo.includes = [ den.policies.drop-feat den.aspects.role ]; # feat's nixos content and quirk emits still applied ``` The aspect-level form, `den.aspects.igloo.excludes = [ den.aspects.feat ]`, already worked through the role. #728 is the other gap: a schema-included parametric aspect losing its identity. That's a different cause in a different file. The two PRs are independent and don't conflict. ## Root cause Two problems, both in how a policy's exclude was registered. 1. **Timing.** A policy in `includes` is only *registered* during the include walk (`register-aspect-policy`). It *fires* at the scope's `dispatch-policies`, after the aspect's static includes have already passed `gate` → `check-constraint`. The trace shows `check feat` with no entry, then `register-constraint owner=policy identity=feat`. 2. **Reach.** Even if it registered in time, the entry records the policy's own include chain as `ownerChain`, and `filterByScope` applies a subtree exclude only under that chain. It would cover only what the policy itself includes. (`issue-540-exclude-guard` passes only because its include and exclude come from one policy.) ## Fix `registerConstraints` (`nix/lib/aspects/fx/aspect/children.nix`) already registers an aspect's own `excludes` before its includes are walked. It now does the same for the policies in that aspect's `includes`: - It evaluates each one against the scope's context: `scopeContexts` plus the aspect's scope handlers, and `self`, as dispatch binds it. - It registers their `exclude` effects as subtree constraints alongside the aspect's own. The result is the same timing and the same reach as `excludes = [ … ]`. A policy whose required arguments the scope doesn't supply yet is skipped here and left to its dispatch, which behaves as before. The later dispatch re-registers the same exclude, which is harmless. ## Tests New file `templates/ci/modules/deadbugs/policy-exclude-reaches-includer-subtree.nix`: - **Exclusion cases:** a direct include; through a role with the policy first; through a role with the policy last. - **Quirk emits:** dropped too. - **Controls:** - the aspect-level `excludes` through a role; - a sibling host that includes the role without the policy keeps the aspect, so the exclude stays the includer's. | check | main | this PR | |---|---|---| | new test file | 2/6 (the 4 exclusion cases fail) | 6/6 | | nix-config's independent file `features/exclude-nested-role.nix` (branch `test/policy-exclude-reach`, 658f9a8) | not run | 6/6 | | full `templates/ci` suite (local) | not run | 1303/1303 | ## Cost Each policy listed in an aspect's `includes` is now evaluated once more, at constraint registration, in addition to its dispatch. Only its `exclude` effects are used. I didn't measure the cost.
…xcludes match it
A parametric nested aspect (den.aspects.a.b = { host, ... }: …) reaches the
pipeline as a functor-bearing wrapper carrying __aspectChain but no name.
wrapChild sent it down the function branch, which never derived the name from
__aspectChain; the content-wrapper branch that did was unreachable for it. So
an include of it through den.schema.<kind>.includes resolved as an anonymous
<parent>/<anon>:N: excludes naming it (on the host aspect or the host instance)
never matched, and it was not deduplicated against the same aspect included
by the host aspect.
withChainIdentity now derives name + meta.aspect-chain from __aspectChain for
both branches.
…ontent stays per host The first fix named the functor-bearing wrapper from __aspectChain but left it on the function branch. Its functor only re-applies the merged aspect, so the parametric functions inside __contentValues were resolved under the wrapper's identity with no entity arguments recorded. The emitted class modules were then keyed by the aspect alone (class@kuma/observed), and a flake-scope instantiate that merges several hosts kept only the first host's module. Content wrappers now take the content-wrapper branch first: chain identity plus the parametric functions as includes, resolved with the scope's entity arguments. Adds a test that a flake-scope class keeps every host's content.
… aspect's chain
den.aspects.<host> = { host, ... }: { excludes = [ … ]; } is coerced to
{ includes = [ fn ]; }, so its body is walked as an anonymous child one chain
segment below the aspect. Its excludes registered at that deeper chain and so
reached only the body's own subtree, missing everything the host scope
includes beside it (a schema include, for one), while the static form of the
same aspect excluded it.
The coercion sites mark the function as the aspect's own body (ownBody), and
registerConstraints registers that body's constraints at the owning aspect's
chain.
sini
force-pushed
the
fix/exclude-parametric-schema-include
branch
from
October 15, 2026 16:27
322c9d3 to
a887c8a
Compare
sini
enabled auto-merge (squash)
October 15, 2026 16:28
theutz
approved these changes
Oct 15, 2026
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
@theutz reported this in Matrix:
den.aspects.<host>.excludes = [ den.aspects.kuma.observed ]had no effect whenkuma.observedwas a parametric nested aspect ({ host, ... }: …) included throughden.schema.host.includes. Its content still reached the excluded host. That includednixosmodules, and content routed to a flake-scope class.I measured on main
631b034an aspect excluded on one host of two, by inclusion route and by aspect shape:den.schema.host.includesden.default.includesincludesden.hosts.<sys>.<host>.excludesfailed the same way for the schema/parametric cell.Root cause
A parametric nested aspect reaches
wrapChild(nix/lib/aspects/fx/aspect/normalize.nix) as a functor-bearing wrapper. It carries__aspectChainbut noname.__functor,lib.isFunctionis true and it goes towrapFunctorChild. That function never derived a name.name+meta.aspect-chainfrom__aspectChain. It existed for exactly this reason, so that an aspect keeps its own identity whatever path includes it. But the function branch caught these wrappers first, so it was unreachable for them.host/<anon>:N.Traced at
check-constraint: for the schema/parametric case,kuma/observedwas never checked. Onlyhost/<anon>:Nnodes were.Two symptoms followed from that:
kuma/observednever matched.Fix
withChainIdentityderivesname+meta.aspect-chainfrom__aspectChainwhen the child has no name. It is applied in the functor branch, beforewrapFunctorChild, and reused by the content-wrapper branch, so both paths assign identity one way.Tests
New file
templates/ci/modules/deadbugs/schema-included-parametric-exclude.nix, with users on both hosts:test-host-aspect-excludestest-host-instance-excludestest-excluded-host-adds-nothing-to-flake-scope-class: a flake-scopeinstantiateof a custom class gets only the observed host.test-schema-and-host-include-dedup: the same aspect included by the schema and by the host aspect is applied once.Red control: 0/4 against main's
normalize.nix. On main the dedup test reads[ "igloo" "igloo" ].Full suite: with the fix, the full
templates/cisuite passes locally, 1301/1301.Not changed
With
den.default.includes, an exclude on the host aspect does not remove the aspect's contribution from the host's user scopes.den.defaultalso applies at user scope, and an aspect-level exclude covers the declaring aspect's subtree only. The instance-levelden.hosts.<sys>.<host>.excludesdoes cover it. I left this alone because it looks like the intended scoping. Flag it if not.