Commit 3932adf
authored
fix: derive class-content emit ctx from authoritative scope state (#624)
## Problem
A **static** (constant-name) aspect included via
`den.schema.<kind>.includes` whose host-class (`nixos`/`darwin`) content
**names an entity kind** — e.g. `nixos = { user, ... }: …` — collapsed
**N sibling entities → 1** at the shared host merge. With three users on
a host, only one user's content survived; the other two were dropped
*before evaluation* by `dedupByKey` on a sid-free aspect identity.
### Root cause
`emit-classes` derived its emit `ctx` from the per-aspect
`aspect.__scopeHandlers` attribute. That attribute is only populated for
**parametric** aspects (bind augmentation) or for includes
**propagated** from a parent that already has it — and is **absent** for
a static aspect reached through a static include chain. So such content
was emitted with an **empty ctx**, collapsing to a base identity. The
same content delivered from multiple scopes (e.g. a host aspect that
also has `homeManager` content, reaching both the host scope and the
user scopes) keyed **inconsistently** (base vs context-qualified),
surfacing as duplicate unique-option definitions
(`programs.steam.package defined multiple times`) the moment any
per-context keying was applied.
The authoritative scope context was always present in pipeline state
right next to the drop point — `state.scopeContexts.${currentScope}` —
and is exactly what `bind.nix` already reads.
## Fix (one handler, a unification)
1. **Authoritative ctx.** `emit-classes` now reads the scope's context
from pipeline state (the same source/pattern as `bind.nix`), layering
the aspect's own `__scopeHandlers` on top so fan-out child bindings
still win. Gated to child scopes; the root scope keeps the historic
handler-only path.
2. **Key by named args.** Each class-content entry is keyed by the
entity kinds its function **names** and that are present in ctx:
- `nixos = { user, ... }:` → `{user=<u>}` → **fans per user**
- `nixos = { host, ... }:` → `{host=<h>}` → **dedups** across every
scope it's delivered from
- `nixos = { persist, ... }:` / `_:` → no entity kind → **singular**
(shared infra aspects keep deduping; no double option declaration)
## Validation
- `just ci`: **1044/1044** (adds `user-scoped-host-class-fanout`
regression suite — the missing coverage that let this through).
- **Byte-identical** existing output: real nixos + k8s hosts produce the
same toplevel derivation pre/post fix (drvPath diff). Only
previously-miskeyed per-user content changes.1 parent 11866c1 commit 3932adf
2 files changed
Lines changed: 145 additions & 3 deletions
File tree
- nix/lib/aspects/fx/handlers
- templates/ci/modules/features
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
| 12 | + | |
12 | 13 | | |
13 | 14 | | |
14 | 15 | | |
| |||
20 | 21 | | |
21 | 22 | | |
22 | 23 | | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
23 | 58 | | |
24 | 59 | | |
25 | 60 | | |
| |||
50 | 85 | | |
51 | 86 | | |
52 | 87 | | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
53 | 92 | | |
54 | 93 | | |
55 | | - | |
| 94 | + | |
56 | 95 | | |
57 | 96 | | |
58 | 97 | | |
59 | 98 | | |
60 | 99 | | |
61 | 100 | | |
62 | | - | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
63 | 104 | | |
64 | 105 | | |
65 | 106 | | |
| |||
93 | 134 | | |
94 | 135 | | |
95 | 136 | | |
96 | | - | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
97 | 158 | | |
98 | 159 | | |
99 | 160 | | |
| |||
Lines changed: 81 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
0 commit comments