Generate JSON Schema for Nix modules https://module-schema.pages.git.fediversity.eu/
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
toonn cfe2196f84
All checks were successful
Regenerate documentation git-pages / pages (push) Successful in 5s
Treefmt / treefmt (push) Successful in 5s
Checks / checks (push) Successful in 54s
Merge pull request 'Fix isEmpty on integer intervals with fractional bounds' (#79) from toonn/module-schema:integer-isempty-fractional into main
Reviewed-on: #79
Reviewed-by: Kiara Grouwstra <kiara@fediversity.eu>
2026-10-09 13:12:04 +02:00
.forgejo add a monthly workflow that makes npins update pull requests 2026-09-23 10:44:24 +02:00
docs module-schema: keep Nix code defaults as strings 2026-10-05 23:12:38 +02:00
lib interval: Fix isEmpty for integer interval with fractional bounds 2026-10-08 16:06:08 +02:00
npins npins: update nixpkgs 2026-10-01 02:03:00 +02:00
.gitignore gitignore: Ignore local .vimrc 2026-06-17 14:23:42 +02:00
default.nix allow overriding nixpkgs' lib in entrypoint from pkgs 2026-09-02 10:33:16 +02:00
flake.lock Add a root default.nix and a flake 2026-09-01 18:42:31 +02:00
flake.nix flake: Instantiate the entrypoint once per system 2026-09-01 18:42:31 +02:00
LICENSE LICENSE: Add 2026-06-16 19:07:34 +02:00
README.md docs: Address review of the manual 2026-09-16 15:36:55 +02:00
shell.nix shell.nix: Add treefmt.nix for formatting 2026-07-28 13:40:02 +02:00
treefmt.nix docs: describe the goal of typeToSchema and use neutral wording 2026-10-01 00:18:57 +02:00

Module-schema

A Nix library to generate JSON Schemas for modules as defined in the Nixpkgs manual.

Motivation

NixOS modules are a great way to configure software, however, they require interacting with Nix. This puts them out of reach of many non-technical users. Their options do declare types, so enough information is available for an alternative interface, such as a web form, to show the available options and to validate a configuration before Nix evaluates it.

This library generates a schema with that information. It opts for JSON Schema as defined in draft 2020-12: JSON is easy to process in many programming languages, and the validation vocabulary covers most of the constraints encoded in Nixpkgs' lib.types. The intent is for JSON data that passes validation against a generated schema to lead to a Nix value (using builtins.fromJSON) that passes all the checks of the option types involved. The manual elaborates on the motivation.

Usage

lib.module-schema.optionsToSchema takes an attrset of NixOS module system options and returns a Nix representation of a JSON Schema, ready for builtins.toJSON.

With npins, or any other way of getting the sources:

let
  module-schema = import sources.module-schema { };
in
builtins.toJSON (
  module-schema.lib.module-schema.optionsToSchema (pkgs.nixos { }).options.services.peertube
)

default.nix is the source of truth and takes system, sources, lib and pkgs as optional arguments, so a package set can be supplied instead of the pinned one.

As a flake input:

{
  inputs.module-schema.url = "git+https://git.fediversity.eu/fediversity/module-schema";

  outputs =
    { module-schema, ... }:
    {
      # ...
    };
}

The flake declares no inputs of its own: the pin in npins/sources.json is the only one, so inputs.nixpkgs.follows has no effect. Call default.nix with your own sources to override it.

Run unit tests with nix-shell --run 'nix-unit lib/tests'. To also build the docs use nix-build --no-out-link -A checks or nix flake check -- which show sub-tests only on failure.

Format all files by running nix-shell --run treefmt.

Documentation

The manual and reference documentation are available here, deployed from the main branch. The manual covers the motivation, usage, the types the library can represent, and related projects.

Note on the internal convention

Internal namespaces are a convention inherited from Haskell. Instead of hiding implementation details they are accessible for when the public API simply doesn't suffice. The contract is that anything in an internal namespace may change in any way, at any time. The burden of keeping implementation sites functional is on the user of such interfaces.