Skip to content

fix: order simple routes before forwards that consume their class#584

Merged
theutz merged 1 commit into
mainfrom
fix/route-homeenv-class-ordering
Jun 3, 2026
Merged

fix: order simple routes before forwards that consume their class#584
theutz merged 1 commit into
mainfrom
fix/route-homeenv-class-ordering

Conversation

@sini
Copy link
Copy Markdown
Collaborator

@sini sini commented May 31, 2026

Problem

A simple den.lib.policy.route injecting into a home-env class (homeManager, or a custom hjem class) was silently dropped when the source class lived on a user aspect. Reported against a config whose hjemLinux → hjem policy never forwarded the user's class data.

Root cause

Home-env classes are not assembled in the pipeline pass where the route runs. home-env.nix:makeHomeEnv carries the class to its host output via userForward — a __complexForward (fromClass = homeManager, into host.class at home-manager.users.<n>). applyComplexRoute reads from the accumulating fold state, so any route producing into its fromClass must run first.

topoSortRoutes only registered __complexForward routes in its producerMap. A simple route producing into homeManager was invisible, so the consuming forward was never ordered after it — and when it ran first, the injected content was already gone.

This is why route → nixos (a host-terminal class) always worked while route → homeManager never did, regardless of scope, schema, or policy signature.

Fix

Treat every route as a producer in topoSortRoutes, so a complex forward consuming a class is ordered after any route producing into it. Self-references are excluded when computing dependencies (also removes a latent spurious self-dependency).

Verification

  • New regression suite deadbugs/netadr-hjem-route.nix covers the user-scope-signature and user-self-provide (the reported config's exact shape) cases — both fail before, pass after.
  • Full CI green: 837/837, including the #567 forward-ordering, route, and forward-* suites.

@sini sini requested a review from vic as a code owner May 31, 2026 23:12
@github-actions github-actions Bot added the allow-ci allow all CI integration tests label May 31, 2026
@sini sini force-pushed the fix/route-homeenv-class-ordering branch from 82186ec to 39d5dbc Compare May 31, 2026 23:23
@sini
Copy link
Copy Markdown
Collaborator Author

sini commented May 31, 2026

Scope-generality verification

Confirmed the fix is not user-scope-specific. The producerMap/hasDeps keying is intoClass@sourceScopeId, so it orders a simple-route producer before any complex-forward consumer at whatever scope they share.

Added test-route-standalone-home-scope covering a standalone den.homes entity (the home resolving scope). Characterization by reverting only apply.nix:

Case Resolving scope Base With fix
test-route-user-scope-usersig host-attached user
test-route-user-scope-provide host-attached user (self-provide)
test-route-standalone-home-scope standalone home

The host-attached-user path delivers homeManager via makeHomeEnv's userForward — a __complexForward that reads the route-application fold state, so it's order-sensitive (the bug). The standalone-home path assembles via the home entity's own instantiate + extractSubtreeModules (direct class extraction, no complex-forward consumer), so it was already correct. The new test guards that scope.

@theutz theutz enabled auto-merge (squash) May 31, 2026 23:31
A simple `policy.route` injecting into a home-env class (homeManager, or a
custom `hjem` class) was silently dropped. Home-env classes are carried to
their host output by makeHomeEnv's `userForward` — a `__complexForward` that
reads from the route-application fold state. The route toposort only treated
`__complexForward` routes as producers, so the consuming forward could run
before the simple route injected its content, losing it.

Treat every route as a producer in `topoSortRoutes` so a complex forward that
consumes a class is ordered after any route producing into it. Exclude
self-references when computing dependencies.

Fixes hjemLinux→hjem (and any srcClass→homeManager) routing where the source
class lives on a user aspect.
@sini sini force-pushed the fix/route-homeenv-class-ordering branch from 39d5dbc to 6378fbd Compare June 3, 2026 02:27
@theutz theutz merged commit b093746 into main Jun 3, 2026
15 checks passed
@theutz theutz deleted the fix/route-homeenv-class-ordering branch June 3, 2026 02:33
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.

2 participants