Skip to content

improve: migrate to gen-schema's options-first API; strict mode as a property of the kind - #717

Merged
vic merged 7 commits into
mainfrom
chore/gen-schema-options-first
Oct 12, 2026
Merged

vic merged 7 commits into
mainfrom
chore/gen-schema-options-first

Conversation

@sini

@sini sini commented Oct 7, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Moves den to gen-schema's options-first API and redesigns strict mode, which the same gen bump broke.

Options-first migration

  • templates/ci pins gen 591758a.
  • gen-schema now takes the options first and the kind last: mkInstanceType { … } kind. den's mkInstanceType wrapper (nix/lib/schema.nix) and the host, user and home entity types follow.
  • host, user and home get conf through inherits = [ den.schema.conf ]. Importing the kind value is the deprecated spelling, and gen-schema now warns on it.
  • fleet-demo builds its registry entry types with den.lib.schema.mkInstanceType. Importing a kind value into a plain types.submodule still works at this gen pin (checked for user, host, conf and a custom environment kind), but that submodule stays open when the kind is strict.

Strict mode

den.lib.strict used to be a second freeform type stacked on the kind's open one. Its typeMerge returns { merge = …throw… }, which is not a type, and it only worked because nixpkgs takes a custom typeMerge result on trust. Even so, nixpkgs refuses the order den builds it in ("already declared"). den main passed only because an older gen-merge folded these types in the other order. gen-merge now folds the way nixpkgs does, and it refuses the join because the join drops attrsOf's check.

Strictness is now a property of the kind:

  • den.schema.<kind>.isStrict is a schema collection, and den.lib.strict is the entry { isStrict = true; }. flakeModules.strict is unchanged.
  • host, user and home pass it to mkInstanceType's strict.
  • The aspect submodule replaces its open freeform with gen-schema's mkStrictModule, and the flake submodule drops its freeform. The closed type replaces the open one rather than being merged with it.
  • Refusals use gen-schema's text, for example STRICT MODE: "arbitrary" is not declared on host (instance at den.hosts.x86_64-linux.igloo, …), and the tests expect it.
  • The docs (explanation/entities.mdx) describe per-kind strictness. den.lib.strict is assigned to the entry itself.

Compatibility

Both old spellings keep working and warn:

  • den.schema.<kind>.imports = [ den.lib.strict ] still makes the kind strict. Without the shim it was silently a no-op. computed.isStrict recognises den.lib.strict listed directly in an entry's imports. Strict instances declare a hidden isStrict option, because the import also leaves isStrict = true on each instance and the closed type would refuse it.
  • den.lib.schema.mkInstanceType kind opts still works. The options are a closed key set (extraModules, strict, specialArgs), so any other first argument is treated as a kind and the arguments are flipped.

Each warning includes migration instructions. The strict one names the file that declares the import. The mkInstanceType one names the kind; Nix can't report the caller's file. For example:

den: `imports = [ den.lib.strict ]` on a schema entry is deprecated (in /home/me/flake/modules/strict-host.nix).
den.lib.strict is now a schema entry, not a module. Migrate:
  - den.schema.<kind>.imports = [ den.lib.strict ];
  + den.schema.<kind>.isStrict = true;   # or: den.schema.<kind> = den.lib.strict;

den: `den.lib.schema.mkInstanceType` called kind-first for kind 'user' is deprecated.
gen-schema takes the options first. Swap the arguments:
  - den.lib.schema.mkInstanceType den.schema.user { … }
  + den.lib.schema.mkInstanceType { … } den.schema.user

Tests for both are in deprecated/strict-imports.nix.

User-facing API changes

  • New: the den.schema.<kind>.isStrict collection. den reads it for host, user, home, aspect and flake. A registry of your own kind follows it only when it passes strict = den.schema.<kind>.isStrict to mkInstanceType.
  • Changed: den.lib.strict is the entry { isStrict = true; }, not a module.
  • Changed: den.lib.schema.mkInstanceType takes the options first. The kind-first order is deprecated.
  • Changed: host, user and home get conf through inherits. Importing a kind value is deprecated in gen-schema and warns.
  • Changed: strict refusal text. For host, user, home and aspect it's gen-schema's STRICT MODE: "x" is not declared on <kind> (instance at …), naming every undeclared key. For flake it's the module system's The option `flake.x' does not exist.
  • Requires: gen 591758a or later for consumers that pin their own inputs.gen.

Docs: reference/lib (new den.lib.strict and den.lib.schema sections), reference/lib-deprecated, reference/schema (isStrict and inherits rows), explanation/entities and guides/acl-environments (registry types rewritten to mkInstanceType with isStrict).

Validation

templates/ci pins gen hub 4ab2a94, which includes the gen-schema and gen-aspects fixes for the __reservedKeys and __keyEq marker leaks into nixpkgs-mounted kinds.

  • nix-unit --flake ./templates/ci#.tests: 1270/1270 (the unmodified PR head gives 1264/1264 on the same machine), including strict-mode 10/10, strict-imports 5/5 and mkInstanceType-kind-first 1/1.
  • The acl guide's registry code was run in a throwaway test, open and with den.schema.environment.isStrict = true. Both behaved as documented.
  • A strict aspect still refuses the class keys den adds for a host (for example nixos). main does the same. The refusal now names every undeclared key instead of one.
  • test-strict-mode-flake-customisable passed before only by accident: den.lib.strict inside imports never made the flake strict. It now uses den.schema.flake.isStrict = true.

sini added 2 commits October 6, 2026 22:00
- bump gen in templates/ci to 591758a
- mkInstanceType takes its options first and the kind last, matching
  gen-schema (`mkInstanceType { … } kind`)
- host, user and home take conf through `inherits`, replacing the
  deprecated kind-value import
- fleet-demo builds its registry types with den.lib.schema.mkInstanceType;
  a kind value is no longer importable into a plain types.submodule

Known failing: strict-mode (7 cells under nix-unit). gen-merge now refuses
to merge den.lib.strict's freeform type with the non-strict instance's
attrsOf anything.
den.lib.strict was a fake freeform type stacked on the kind's open
freeform, relying on nixpkgs letting a custom typeMerge return a non-type.
gen-merge refuses that join by name (it drops attrsOf's check), and nixpkgs
itself refuses the order den builds it in ("already declared").

- den.schema.<kind>.isStrict is a schema collection; den.lib.strict is the
  entry `{ isStrict = true; }`
- host, user and home instance types pass it to gen-schema's
  mkInstanceType `strict`
- the aspect submodule swaps its open freeform for gen-schema's
  mkStrictModule; the flake submodule drops its freeform
- strict-mode expectations follow gen-schema's refusal text

Known failing: four strict-mode cells (aspect x2, flake x2). gen-schema
and gen-aspects add a gen-merge-only `__reservedKeys` marker to the kind
modules; it leaks into nixpkgs-mounted kinds, and a closed kind refuses it
before the planted key.
@github-actions github-actions Bot added the allow-ci allow all CI integration tests label Oct 7, 2026
sini added 4 commits October 7, 2026 01:23
With the gen marker leak fixed, a strict aspect names its undeclared keys
(including class keys den adds for a host, as before) and a strict flake
refuses an undeclared option. Expectations now match that text.
…arnings

- `den.schema.<kind>.imports = [ den.lib.strict ]` makes the kind strict again.
  It was silently a no-op after den.lib.strict became a schema entry. Strict
  instances declare a hidden `isStrict` option to absorb the stray definition
  the import leaves on each instance.
- `den.lib.schema.mkInstanceType kind opts` dispatches on the closed option key
  set and flips to the options-first order.
- reference/lib: den.lib.strict (per-kind refusal text) and
  den.lib.schema.mkInstanceType (options-first, strict follows isStrict only when passed).
- reference/lib-deprecated: the imports-form strict and kind-first mkInstanceType.
- reference/schema: isStrict and inherits collections; host/user/home inherit conf.
- acl-environments: registry types built with mkInstanceType, passing isStrict.
@sini sini changed the title chore: migrate to gen-schema's options-first API; strict mode as a property of the kind improve: migrate to gen-schema's options-first API; strict mode as a property of the kind Oct 7, 2026
@sini
sini marked this pull request as ready for review October 7, 2026 15:27
The strict-import warning names the file that declares the import. The
kind-first mkInstanceType warning names the kind. Both show the old and new
spelling as a diff.

@vic vic left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

works on my local config

@vic
vic merged commit dd59a4c into main Oct 12, 2026
@vic
vic deleted the chore/gen-schema-options-first branch October 12, 2026 23:04
vic pushed a commit that referenced this pull request Oct 13, 2026
) (#720)

Fixes #719.

## Cause

Since #717, gen-schema mints a kind's identity from the contents of its
schema collections when an instance is imported. `includes` and
`excludes` hold aspect references, and an aspect reference can reach
back into the host being built. Hashing the collection therefore forced
that host during its own import. The result was an infinite recursion,
or an exclusion that silently did nothing.

## Fix

- `den.schema` declares `includes` and `excludes` with `identity =
false`. gen-schema keeps a collection declared this way out of the kind
identity. These collections are policy over aspects, not part of the
kind's shape.
- `templates/ci` pins gen at `6427d42`, which carries gen-schema
`10f4d12` with `identity = false` support. Only the `gen` input moved
(`nix flake update gen`).

## Tests


`templates/ci/modules/deadbugs/issue-719-schema-excludes-aspect-ref.nix`
now has 5 cells:
- the 3 cells from the reproduction commit, which put a direct
reference, a bracket reference and a nested bracket reference in
`den.schema.host.excludes`;
- 2 cells that put the same references in the parent kind's
`den.schema.conf.excludes` / `includes`.

The 2 `conf` cells expect the values den produced before #717, where
`conf`'s collections do not apply to a host instance. I checked them
against `65c9fd4` and all 5 cells pass there.

`nix-unit --override-input den . --flake ./templates/ci#tests`:

| tree | #719 suite | full suite |
|---|---|---|
| reproduction commit `39c4833` (old gen pin) | 0/3, infinite recursion
| 1270/1273. The only failures are the 3 #719 cells |
| this PR | 5/5 | 1275/1275 |
| this PR without the `identity = false` lines | 0/5, infinite recursion
| 1270/1275. The only failures are the 5 #719 cells |

`just fmt` makes no changes.
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