Skip to content

fix: nested sub-aspects doubled when included and missed by guard hasAspect - #693

Merged
sini merged 2 commits into
mainfrom
fix/692-nested-provides-twice
Sep 23, 2026
Merged

sini merged 2 commits into
mainfrom
fix/692-nested-provides-twice

Conversation

@sini

@sini sini commented Sep 23, 2026 •

Copy link
Copy Markdown
Collaborator

Fixes two defects where a nested sub-aspect (den.aspects.foo.bar) behaves differently from the same aspect declared under provides..

Summary

A nested aspect's provides doubled when it is included (#692)

  • In the reported shape, foo.includes = [ den.aspects.foo.bar ] with foo.bar.provides.to-users.homeManager declaring an option, home-manager fails with The option `home-manager.users.tux.nested-marker' … is already declared in `homeManager@foo/bar/to-users'. The same aspect at the root (den.aspects.foo.provides.to-users) is unaffected.
  • The cause is in wrapperToAspect, in nix/lib/aspects/types.nix. Since fix: aspect provenance collisions and the nested _ alias (#670) #671 a nested aspect publishes provides and _ as one value, so either spelling reads the same children. When the aspect is included, wrapperToAspect hands that value to aspectSubmodule. The submodule's mkAliasOptionModule [ "_" ] [ "provides" ] takes the published _ as a second definition of provides, and every provides leaf ends up with two definitions. The declared foo.bar.provides.to-users.homeManager is a single raw lambda; the copy in foo.includes carried two __contentValues.
  • wrapperToAspect now drops _ when it carries __functor. That marks the published read view rather than something the author wrote; a written _ has already been folded into provides by foldUnderscoreIntoProvides, whose comment states the same rule: a _ read back off a wrapper "must stay out of provides". Nothing is lost, because the submodule builds its own _ from provides.

A guard's hasAspect misses a nested sub-aspect

  • A mutual-consent pattern guards a user half on host.hasAspect den.aspects.feature.host-part. With host-part declared under provides. the guard passes; with host-part as a plain nested key it fails and the user half is dropped silently, even though host-part does reach the host (its content is in the output either way).
  • A nested key reaches the guard as a content wrapper carrying __aspectChain = [ "feature" "host-part" ] and no name or meta. The guard-time lookup in mkPipelineHasAspect (nix/lib/aspects/fx/handlers/compile-conditional.nix) keyed it with identity.key, which names it <anon>. The path set does record feature/host-part, so the lookup always missed. A provides. child carries a name and keyed correctly.
  • The four guard hasAspect checks now key a reference that has __aspectChain and no name by its chain, and everything else by identity.key as before. The entity-surface hasAspect (has-aspect.nix refKey) already handles this shape; it isn't reused because it requires name and meta together, and guard references like { name = "dep-a"; } in fx-compile-conditional rely on identity.key accepting name alone.

Tests

  • issue-692-nested-provides-to-users-twice: the reporter's two cases, with the root-level provides.to-users as the control.
  • nested-ref-guard-hasaspect: the Matrix reporter's shape, nested and provides. forms, each with a mutual case and a host-opted-out case.

Validation

…des`

Since #671 a nested aspect publishes `provides` and `_` as the same value.
wrapperToAspect handed both to aspectSubmodule, whose `_` alias counted the
read view as a second `provides` definition, so a nested aspect reached
through `includes` delivered every provides leaf twice. Drop the
functor-bearing `_` before the submodule merge.

#692
@sini
sini requested a review from vic as a code owner September 23, 2026 15:30
@github-actions github-actions Bot added the allow-ci allow all CI integration tests label Sep 23, 2026
A nested sub-aspect reference (`den.aspects.foo.bar`) reaches a
`policy.when` guard as a content wrapper carrying only `__aspectChain`.
The guard keyed it with identity.key, which names it `<anon>`, so
`host.hasAspect den.aspects.foo.bar` was false even when bar was present
and the guarded include was silently dropped. The same aspect declared
under `provides.` carries a name and matched. Key a name-less ref by its
chain, as the entity-surface hasAspect already does.
@sini sini changed the title fix: keep a nested aspect's published _ out of its re-merged provides fix: nested sub-aspects doubled when included and missed by guard hasAspect Sep 23, 2026
@sini

sini commented Sep 23, 2026

Copy link
Copy Markdown
Collaborator Author

Vipul Tyagi on matrix was able to test and confirm the proves the fix worked for them

@sini
sini merged commit ba9ee3a into main Sep 23, 2026
16 checks passed
@sini
sini deleted the fix/692-nested-provides-twice branch September 23, 2026 16:00
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.

1 participant