Skip to content

fix: supply nixpkgs lib as a base module argument to schema kinds - #689

Merged
sini merged 9 commits into
mainfrom
fix/687-schema-module-lib-arg
Sep 22, 2026
Merged

sini merged 9 commits into
mainfrom
fix/687-schema-module-lib-arg

Conversation

@sini

@sini sini commented Sep 21, 2026 •

Copy link
Copy Markdown
Collaborator

#687

Summary

  • Serves nixpkgs lib to schema kinds as a base module argument through gen-schema's specialArgs inlet, so a module written { host, lib, ... }: no longer reads the config fixpoint it is part of.
  • Drops den.schema.conf._module.args.lib, the line the issue was filed against, as the base argument leaves it with no reader.
  • Injects at den's schema boundary rather than at each call site, since the number of gen-schema constructors is a property of gen-schema and threading per site is one edit from reintroducing the defect.
  • Bumps the gen pin to the rev that threads every constructor on den's path, which has to land with the fix because specialArgs refuses by name against an earlier one.

_module.args is not the channel nixpkgs uses. nixpkgs' evalModules injects lib as a base argument at every level including nested submodules; gen's module system ships no nixpkgs lib by construction, so supplying it is den's job. gen-merge resolves _module.args by folding over every module's config, so a module that forces lib while producing its own top-level attrset re-enters itself. The result was an uncatchable infinite recursion encountered naming neither the module nor the argument, which is how this reached a user rather than a CI run.

Validation

  • The configuration from the issue evaluates unmodified. unazikx/flake at its own HEAD, no edits, resolving den through the fetchTarball fallback: all five nixosConfigurations enumerate, and blackmamba and jetpure evaluate through to derivations. Three hosts then fail on unrelated missing-attribute errors originating in that tree and in a third-party module, none of them this defect; they were unreachable before, because the recursion aborted the flake ahead of them.
  • just ci ⇒ 1244/1244, exit 0, no override, on the exact committed state. The anchored baseline was 1240/1242 at den af28b1e4 / pin 0004f3c9, the only failures being the regression cells this branch adds; the total moves because the branch adds cells, so the durable form of the bar is no failures rather than a number.
  • The defect has three arms and each is pinned with a control. An instantiated kind recurses. A kind with no instances recurses too, so mkInstanceType is not on that path. And the same module passes when a declared option is read but refuses when id_hash is forced, because identity reflection reaches the kind's option set through a constructor that took no specialArgs. The third is the one the reported configuration takes, and no synthetic cell found it — every cell here read a declared option, which is why a green suite did not see it.
  • The kind-tree cell reads options.<opt>.default, never attrNames/isAttrs over options: a missing formal is a thunk, so the key set comes back intact over a kind that diverges only on use. Its paired control fires a throw from the same position, so the cell cannot pass by ceasing to force.
  • lib.optionalAttrs rather than lib.mkIf as the forcing wrapper in that cell. Both force lib at the module's own WHNF, but a top-level mkIf carries only config and drops its options.
  • Dropping the _module.args channel was verified by diffing the failure sets: identical with and without it, so nothing read lib through a path the base argument does not reach.
  • The eight templates/ci/provider cells are what prove this on the path consumers take. That sub-flake declares no gen input, so den inside it takes the fetchTarball fallback and reads lock.nodes.gen — which no --override-input touches. They were red for every member-override arm and turn only on a real pin bump.
  • den's eval cost is unchanged by the bump. performance suite at the shipped pin, interleaved against origin/main at the previous one, both arms 31/31 green: 2.73-2.80s versus 2.88-2.94s.

Red until the fix lands. A den.schema module that forces its `lib` module
argument while producing its own top-level attrset diverges with `infinite
recursion encountered`, because gen-merge resolves `_module.args` by folding
over every module's config and so re-enters the module being called. The green
cell is the same module with the `lib` read moved into a lazy position, which
holds the pair to the argument position rather than to den.schema.

Reported at #687 and reproduced on the
reporter's own configuration. Bisected to 6c11a13, which supplied nixpkgs
`lib` on `den.schema.conf._module.args` after the port to gen-schema, where
the previous gen-schema revision had evaluated kinds on nixpkgs `evalModules`
and got `lib` as a base argument.
The recursion has two arms and an instance-only fix leaves one red. A kind
with no instances recurses on the same module shape, so `mkInstanceType` is
not on that path: the kind's own option tree is enough. Measured with the
control below, which fires a throw from the same position and proves the
forcing expression forces.

The control stays in the suite rather than being run once and discarded. An
earlier version of the second cell forced `den.schema._kindNames`, which does
not force a kind's modules, so it passed green while proving nothing. This
control fails the moment that happens again.
The cell read `builtins.isAttrs <kind>.options`, which is a dead predicate:
module application succeeds and a missing formal is a thunk, so the key set
comes back intact over a kind that only diverges on use. It meant something
solely because the sibling control fires a throw from the same position, which
is a coupling nothing named and one edit could break. It now declares an option
and reads its `default`.

`lib.optionalAttrs` rather than `lib.mkIf` as the forcing wrapper. Both force
`lib` at the module's own WHNF, which is the defect shape, but a top-level
`mkIf` carries only `config` and drops its `options`, so the sharper cell
failed with `attribute 'probe' missing` instead of on the defect. Measured
rather than reasoned.

Verified in both directions with the same cell: it detonates on the unfixed
engine and passes on gen-schema c5785978 with den wired to the base-arg
channel.
A schema module written `{ host, lib, ... }:` is den's documented shape at five
sites. Since the port to gen-schema it has been served from
`den.schema.conf._module.args.lib`, which is not the channel nixpkgs uses: a
module that forces `lib` while producing its own top-level attrset then reads
the config fixpoint it is part of, and gen-merge resolves `_module.args` by
folding over every module's config. The result is an uncatchable `infinite
recursion encountered` naming neither the module nor the argument, which is how
issue #687 reached a user rather than a CI run.

nixpkgs' `evalModules` injects `lib` as a BASE argument at every level,
including inside every nested submodule, with no caller ceremony. gen's module
system ships no nixpkgs lib by construction, so supplying it is den's job, and
gen-schema's `specialArgs` inlet is the admissible channel.

Injected at den's schema boundary rather than at each call site. den threaded
four sites by hand first — three `mkInstanceType` and one `mkSchemaOption` —
and that is one edit away from reintroducing the defect, since the site count
is a property of gen-schema rather than of den. A caller's own `specialArgs`
still win, so a kind can shadow `lib`.

INERT UNTIL THE PIN MOVES, and it must land with the bump rather than before
it. `specialArgs` exists on those constructors only from gen-schema c5785978.
Against the currently pinned engine this refuses with `called with unexpected
argument 'specialArgs'` on every host-instantiating cell reached through
`templates/ci/provider`, which declares no gen input and so takes the
`fetchTarball` fallback: measured, 1234/1242 with eight such cells red. Against
c5785978 the four cells of issue-687-schema-module-lib-arg pass.

`den.schema.conf._module.args.lib` is left in place. It is dead weight once the
base argument lands, because gen-merge resolves a formal from the base args
before consulting `_module.args`, but removing it is a separate change to make
once the pin is in the field.
This is the line #687 was filed against. It served nixpkgs `lib` to schema
kinds from `den.schema.conf._module.args.lib`, and a module that forces `lib`
while producing its own top-level attrset then reads the config fixpoint it is
part of, because gen-merge resolves `_module.args` by folding over every
module's config. The base argument supplied at den's schema boundary replaces
it: gen-merge resolves a formal from the base args before consulting
`_module.args`, so the channel has no remaining reader.

Measured on the flake arm against gen-schema c5785978: the failure set is
IDENTICAL with and without it, 1234/1242 both ways, the eight cells being the
`templates/ci/provider` ones that take the fetchTarball fallback and so still
resolve the pinned engine. So nothing in den read `lib` through a path the base
argument does not reach — in particular not through gen-schema's two
module-eval entry points that take no `specialArgs`.

That evidence covers the flake arm only. The provider cells cannot speak to it
until `lock.nodes.gen` moves, which is the same reason this lands with the pin
bump rather than ahead of it.
den names one rev, `lock.nodes.gen`, and the hub's own `ci/flake.lock` picks
every member, so this is the only edit that moves the engine for a consumer.
Taken with `nix flake update gen` inside `templates/ci` rather than by pinning
members, which tears out the hub's `follows` and is what left three gen-prelude
revisions in one lock before den moved to the hub.

This is the half that makes the two preceding commits function. `specialArgs`
exists on gen-schema's constructors only from the relocked hub, so the base
argument is inert without it and refuses by name against the previous pin.
Measured at this rev: `just ci` 1242/1242, exit 0, no override — including the
eight `templates/ci/provider` cells that take the `fetchTarball` fallback and
so are the only instrument in the suite that reads `lock.nodes.gen`.

The hub's own `perf-bench` is red at these pins on gen's fixtures
(`schemaHosts n=1600` thunks 1.171 against a 0.90 bar), which the relock
surfaced rather than caused. den's own cost is unchanged: the `performance`
suite measured interleaved against `origin/main` at the previous pin, both arms
31/31 green, 4.39-4.87s versus 4.53-4.88s.
@sini
sini requested a review from vic as a code owner September 21, 2026 22:36
@github-actions github-actions Bot added the allow-ci allow all CI integration tests label Sep 21, 2026
Red until gen-schema threads it. The reporter's own flake still refuses on the
branch that fixes the other two arms, and this is the shape it takes: the same
kind module passes when a declared option is read and refuses when `id_hash`
is forced.

Identity reflection reaches the kind's option set through
`identityKeysForKind`, whose `merge.evalModuleTree` takes no `specialArgs` at
gen-schema 9c141ec, so the base argument never arrives and the module falls
back to `_module.args`. It is the one entry point of four still unthreaded:
instance.nix, entry-type.nix and eval-schema.nix all carry the formal.

The paired control reads a declared option from the same module and is green,
so the cell cannot pass by ceasing to exercise reflection. Every other cell in
this file reads a declared option, which is why a 1242/1242 suite did not see
this and only the reporter's configuration did.
The comment asserted in the present tense that `identityKeysForKind` takes no
`specialArgs`. That was true at gen-schema 9c141ecc, which this tree pins, and
is false at 8a6d3f6, where it gained the defaulted formal. A present-tense
claim about a pinned dependency goes stale the moment the pin moves, and this
one went stale while the cell it explains stayed correct.

States the rev it was measured at, and names the upstream fix the hub does not
yet carry, so the next reader can tell a live defect from a pending bump.
The previous pin reached `identityKeysForKind` with no `specialArgs`, so a kind
module forcing `lib` at its own WHNF still refused when `id_hash` was forced —
which is the path the reported configuration takes and the reason the earlier
pin left it broken while den's suite read green.

gen `5f58e7bf` pins gen-schema `5da15b1`, which carries `8a6d3f6` threading the
defaulted formal. Verified by ancestry with both controls: forward rc 0,
reverse rc 1, orphan `commit-tree` control rc 1, and the four commits between
are relock bumps with no content change.

Measured at this pin: `just ci` 1244/1244 exit 0, the six cells of
issue-687-schema-module-lib-arg green including the identity-reflection arm,
and the reporter's own flake from the issue evaluating unmodified — five
nixosConfigurations, and `blackmamba` through to a derivation.
@sini
sini merged commit 4d69112 into main Sep 22, 2026
16 checks passed
@sini
sini deleted the fix/687-schema-module-lib-arg branch September 22, 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.

1 participant