Skip to content

fix: forwarded content overwritten across scopes (#583) - #585

Merged
sini merged 1 commit into
mainfrom
fix/issue-583-forward-overwrite
Jun 1, 2026
Merged

sini merged 1 commit into
mainfrom
fix/issue-583-forward-overwrite

Conversation

@sini

@sini sini commented Jun 1, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

Fixes #583. When two aspects contribute to the same forward source class and the forward fires at a child (user) scope while routing into a parent (host) class, the host's own contribution is silently dropped:

den.aspects.atuin = {
  includes = [ atuinClass ];   # forwards `atuin` → nixos programs.atuin
  atuin.flags = [ "--hello" ];
};
den.aspects.igloo = {
  provides.to-users.includes = [ den.aspects.atuin ];
  atuin.flags = [ "--world" "--baz" ];
};

Produces programs.atuin.flags = [ "--hello" ] instead of the merged [ "--hello" "--world" "--baz" ].

Worked in v0.16; regressed with the fx-pipeline rewrite (#475).

Root cause

route/apply.nix:getCollectedSource merges a complex forward's own-scope source modules with the root (host) scope's fromClass content, but filtered the root content unconditionally through isDenDefaultModule — keeping only @default-keyed modules. The host's own atuin content (module key atuin@igloo) is not a den.default module, so it was filtered out, leaving only the user-scope --hello.

That @default-only filter is correct for entity-owned classes: the home-manager battery's homeManager → nixos forward must not implicitly pull a host's own homeManager config into every user's home — that projection is opt-in via host-aspects. It is wrong for a custom forward-only class like atuin, whose host-scope content exists solely to be aggregated.

Fix

Restrict root content to @default only when fromClass is a class an entity in the scope chain owns (user.classes, host.class, home.class, read from scopeContexts); otherwise keep the root content in full. The owned-class set is total over all three entity kinds so the decision never falls open for a non-user-owned scope.

The discriminator keys on fromClass rather than intoClass deliberately — host-aspects.test-opt-in-only and user-host-mutual-config.test-host-owned-unidirectional both forward homeManager into nixos yet must keep their opt-in projection semantics.

Validation

  • New regression test deadbugs/issue-583-forwarding-overwrite.nix (mirrors the report): overwrite → ✅ 1/1
  • host-aspects ✅ 10/10 and user-host-mutual-config ✅ 9/9 — opt-in projection unchanged
  • Full CI: 839/839 ✅
  • Formatting clean

A complex forward firing at a child (user) scope merges its own-scope
source modules with the root (host) scope's `fromClass` content. The
root content was unconditionally filtered to `@default`-keyed modules,
silently dropping the host's own contribution.

That filter is correct for entity-owned classes — the home-manager
battery's `homeManager` forward must not implicitly pull a host's own
home config into every user (that projection is opt-in via host-aspects).
It is wrong for a custom forward-only class like `atuin`, whose host-scope
content exists solely to be aggregated.

Filter root modules to `@default` only when `fromClass` is owned by an
entity in the scope chain (`user.classes`, `host.class`, `home.class`);
otherwise pull the root content in full.
@sini
sini requested a review from vic as a code owner June 1, 2026 16:29
@github-actions github-actions Bot added the allow-ci allow all CI integration tests label Jun 1, 2026
@sini
sini requested review from drupol and theutz June 1, 2026 17:48
@sini
sini enabled auto-merge (squash) June 1, 2026 17:56
@sini
sini disabled auto-merge June 1, 2026 17:56
@sini
sini enabled auto-merge (squash) June 1, 2026 17:56
@sini
sini merged commit 9deef6d into main Jun 1, 2026
46 of 71 checks passed
@sini
sini deleted the fix/issue-583-forward-overwrite branch June 1, 2026 18:01
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: Forwarding can overwrite each other

2 participants