Skip to content

fix: route wrapping merge semantics and forward ordering - #574

Merged
sini merged 3 commits into
denful:mainfrom
sini:fix/572-packages-merge-clobber
May 29, 2026
Merged

sini merged 3 commits into
denful:mainfrom
sini:fix/572-packages-merge-clobber

Conversation

@sini

@sini sini commented May 29, 2026 •

Copy link
Copy Markdown
Collaborator

Closes #572, closes #567

Summary

Three route application fixes in the fx pipeline:

#572 — Multiple aspects defining the same flake output class clobber each other. wrapRouteModules evaluated each source module independently through nestWithAdaptArgs, producing separate config definitions. The flake submodule's freeform unspecified type shallow-merged them with //, keeping only the last.

#567 — Class forwarder with each breaks when imported from a mutual provider. Forward routes like nix→homeManager registered after the HM battery route homeManager→nixos. The consumer fired first and collected from homeManager before the producer had written to it.

Audit — nestPlain had the same shallow merge, freeform type was too permissive, and duplicate instantiate specs were silently dropped.

Changes

  • route/wrap.nix: Combine all source modules into a single evalModules call for the nestWithAdaptArgs path. Align nestPlain to also use evalModules instead of recursiveUpdate. Introduce mergeableType — a custom freeform type that deep-merges attrsets, concatenates lists, and errors on conflicting scalar/derivation values (matching NixOS module system semantics).
  • route/apply.nix: Add topoSortRoutes — partitions complex forward routes so producers (whose intoClass feeds another forward's fromClass) fire before consumers.
  • resolve.nix: Add lib.warnIf when multiple instantiate specs target the same output path on the same system.
  • Regression tests: 4 new tests across 2 files.

Test plan

  • 833/833 CI tests pass
  • flake-parts-modules template passes (previously failed with raw freeform type)
  • All other templates pass just check-all (same results as main)
  • Formatting clean

…enful#572)

wrapRouteModules previously wrapped each source module independently
through nestWithAdaptArgs, producing separate config definitions at the
same flake output path. The freeform `unspecified` type shallow-merged
these with `//`, so only the last aspect's values survived.

Combine all source modules into a single evalModules call for the
nestWithAdaptArgs path so the module system merges them properly.
@sini
sini requested a review from vic as a code owner May 29, 2026 20:10
@github-actions github-actions Bot added the allow-ci allow all CI integration tests label May 29, 2026
@sini sini changed the title fix: merge multiple aspect emissions per route instead of clobbering fix: route wrapping merge semantics and forward ordering May 29, 2026
…ul#567)

When a class forwarder with `each` is imported from a provide aspect,
it registers multiple forward routes (e.g. nix→homeManager and
nix→nixos). The HM battery route (homeManager→nixos) was firing before
nix→homeManager, so it consumed from the homeManager class before the
forward had produced into it.

Add topoSortRoutes to partition complex forwards: routes whose
intoClass feeds another forward's fromClass fire first.

Also switch nestWithAdaptArgs freeform type from `unspecified` to `raw`
so overlapping keys from different aspects error instead of silently
clobbering.
@sini
sini force-pushed the fix/572-packages-merge-clobber branch from bf229ab to fc267ea Compare May 29, 2026 20:44

@theutz theutz left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pending passing CI, LGTM!

else
# Same entity via multiple policy paths: keep last.
[ (lib.last entries) ];
# Same entity via multiple policy paths: deduplicate.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Image

@sini
sini force-pushed the fix/572-packages-merge-clobber branch 2 times, most recently from 764ee10 to 242192f Compare May 29, 2026 21:22
disambiguatedModules silently kept only the last instantiate spec when
multiple targeted the same output path on the same system. Add a
lib.warnIf so users are alerted when one entity's config shadows another.
@sini
sini force-pushed the fix/572-packages-merge-clobber branch from 242192f to 85b20cc Compare May 29, 2026 22:01
@sini
sini merged commit 9dfaf74 into denful:main May 29, 2026
15 checks passed
sini added a commit that referenced this pull request Sep 4, 2026
Closes #674

## Summary

`mergeableType` — the freeform type route nesting evaluates modules
under — deep-merges attrsets, concatenates lists, and throws on
everything else. Derivations are deliberately excluded from the attrset
branch so they stay opaque, so two aspects producing the same package
fell to the conflict throw even though the definitions agreed. Same for
the reported `enable = true` shape, where deep-merging descends to a
scalar leaf with two definitions.

- Accepts all-equal definitions before the conflict throw, matching
NixOS's `mergeEqualOption`. Checked last, so it forces values only on
the path that already threw.

#574 introduced the type claiming NixOS module semantics, but
`mergeEqualOption` accepts agreeing definitions and only throws on
disagreement — so the divergence is latent from #574, and #671 made the
path reachable, which is the reporter's own reading of the bisect. This
is the same collapse-agreeing-definitions rule #671 applied to
`meta.provider`, now on the route freeform type.

Testing:

- Adds the reported case verbatim (two aspects, one shared derivation),
the reported symptom shape (a scalar leaf reached by deep-merging an
`apps` attrset defined by two aspects), and a negative control pinning
that disagreeing definitions still throw.

## Validation

- `nix develop -c just ci`: 1118/1118, exit 0, zero failures and zero
errors. `nix develop -c just fmt` a no-op at the final rev.
- Reproduced first on an unfixed `origin/main` worktree at 36c8ba5: the
issue's test verbatim fails with `den: the option 'shared' has
conflicting definitions from multiple aspects`, so the fix is measured
against a red baseline rather than a green assumption.
- Probed the negative control rather than trusting its pass. Forcing the
value without `tryEval` prints that same conflict error, so it fails for
the guard's reason and not incidentally.
- Confirmed the new suite is discovered by the CI harness with `just ci
deadbugs-issue-674` (3/3). The background `just ci` log truncates to 42
lines, so the suite's absence from that log is not evidence either way
and was not read as such.

## Known limitation

The equality check cannot reach function-valued leaves. Measured against
this nixpkgs:

| expression | result |
| --- | --- |
| `(x: x) == (x: x)` | `false` |
| `let f = x: x; in f == f` | `false` |
| `{ a = 1; f = x: x; } == { a = 1; f = x: x; }` | `false` |

A lambda never compares equal, not even to itself, and one lambda
anywhere in an attrset makes the whole comparison false. So two aspects
delivering the same *function* at one option still conflict, and no
`==`-level rule can fix that — it needs identity carried alongside the
value. Derivations are unaffected because Nix short-circuits their
comparison on `outPath`, which is why the reported case is fully fixable
here.
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: Class forwarder breaks when imported from mutual provider

3 participants