Generate JSON schema for Nix modules
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
cinereal 3899e03418
Add moduleToSchema to wrap a module into an object root
`optionsToSchema` returns the bare per-option property map, with the
`$schema`/`$defs` meta keys mixed in at the top level -- not itself a valid
object schema. Every consumer that wants a standalone schema (to validate a
whole configuration, or to feed a form renderer) had to wrap that map into the
object root by hand, re-deriving `required` from scratch.

`moduleToSchema` upstreams that wrap step: fed `(moduleType.getSubOptions [ ])`,
it returns `{ "$schema" = ...; type = "object"; additionalProperties = false;
properties = <options>; required = <options-without-default>; "$defs" = <defs>; }`
directly. It strips the module-system bookkeeping options
`_module`/`_freeformOptions` that `getSubOptions` surfaces, so a caller can pass
that output verbatim without them leaking in as properties.

The wrap logic already existed inside the `submodule` branch (which produces
exactly this object root for a submodule type) but was unreachable from the
top-level option-map entry. Factor it into a shared `wrapAsObject` helper (with a
shared `hasDefault`) that both the `submodule` branch and `moduleToSchema` call,
so there is a single source of truth for the object root a module validates as.
The submodule branch stays byte-identical (2900/2900 tests, golden `services.*`
included); `matchesSubmoduleBranch.test` pins the equivalence.

Assisted-by: Claude:claude-opus-4-8
2026-07-19 16:56:10 +02:00
lib Add moduleToSchema to wrap a module into an object root 2026-07-19 16:56:10 +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