Generate JSON schema for Nix modules
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
cinereal 057adb0d55
Emit a carried JSON Schema verbatim
Every branch of `typeToSchema'` converts an option type into a schema, which
works because the option type is the source of truth and the schema is derived
from it. For a service that publishes the schema of its own configuration file
the direction is reversed: the schema is upstream's, the option type is ours,
and converting the schema into option types loses whatever the option-type
vocabulary cannot express -- `pattern` most plainly, a Nix regex predicate
having no faithful translation, but also every keyword from a draft that
postdates the converter.

Let a type say it was built from a schema, by carrying that schema in
`functor.payload.jsonSchema`, and emit the carried schema instead of converting
the type. The carry wins over the name-keyed branches: a type built from a
schema may still answer to a familiar `name`, and the schema is the more
faithful of the two answers.

`$defs` are the one thing not carried verbatim. A `$ref` is anchored at the
root of the document it ends up in, so carried definitions have to join the
ones the surrounding walk accumulated, at the top level, under the names their
`$ref`s already use. Two differing definitions sharing a name cannot both
survive that lift, so the clash is refused rather than silently resolved.

Assisted-by: Claude:claude-opus-5
2026-08-17 00:06:22 +02:00
lib Emit a carried JSON Schema verbatim 2026-08-17 00:06:22 +02:00
notes Add moduleToSchema to wrap a module into an object root 2026-07-19 16:56:10 +02:00
npins npins: Add nixpkgs pin 2026-06-17 12:12:41 +02:00
.gitignore gitignore: Ignore local .vimrc 2026-06-17 14:23:42 +02:00
LICENSE LICENSE: Add 2026-06-16 19:07:34 +02:00
README.md Initial commit 2026-06-16 19:01:12 +02:00
shell.nix shell.nix: Add nix-unit nixfmt and npins utilities 2026-06-17 12:12:45 +02:00

module-schema

Generate JSON schema for NixOS modules