Files
komorebi/nix/tests/default.nix
T
LGUG2Z 3a3a0f8f24 feat(wm): JSON schemas, and the module's typed options
komorebi.json is described as a JSON Schema, made from the Rust types that read
it: komorebic prints the schema of komorebi.json, of an applications.json, of a
notification and of a message, and the daemon answers the same four questions on
its socket. schema.json and schema.asc.json are committed (just jsonschema).

The module's config option is typed from the schema: schemars-nixgen makes
nix/komorebi-options.nix from schema.json (just nixgen), so a layout komorebi
does not have, or a value of the wrong kind, does not evaluate. The module
writes config as a komorebi.json and gives it to the daemon with --config.
configFile and the file the module writes are checked against the schema when
the system is built. applicationSpecificConfiguration takes files from GitHub,
and there are none by default, since no community file for Plasma is known.

Two checks keep the generated files honest without the tools that make them.
schema-fresh compares the schemas with what komorebic prints, and the hash on
the first line of the options with the schema. nix-options-validation evaluates
the options against the example configuration, written in Nix and in JSON.

nixos-module-eval also evaluates the module with the sources turned off: with
applicationSpecificConfiguration.enable = false the sources are left out of the
config that is written, and with no config either there is nothing to write and
the unit passes no --config. ARCHITECTURE has the guarantee row that names the
two checks.
2026-10-28 07:20:37 -07:00

58 lines
1.7 KiB
Nix

# `nix-options-validation`: the options `just nixgen` makes from `schema.json`, evaluated against
# the example configuration, whose JSON is checked against the schema, and against the example
# file of the docs. Run with `nix build -f nix/tests/default.nix`, or as a check of the flake.
{
pkgs ? import <nixpkgs> { },
}:
let
lib = pkgs.lib;
# the Nix module system uses null for an optional field that is not set, and the schema wants
# the field to be absent
filterNulls =
value:
if value == null then
null
else if builtins.isList value then
map filterNulls (builtins.filter (x: x != null) value)
else if builtins.isAttrs value then
lib.filterAttrs (_n: v: v != null) (builtins.mapAttrs (_n: v: filterNulls v) value)
else
value;
evaluated =
(lib.evalModules {
modules = [
(import ../komorebi-options.nix)
(import ./komorebi-example.nix)
];
}).config.komorebi;
evaluatedJson = pkgs.writeText "komorebi-example-from-nix.json" (
builtins.toJSON (filterNulls evaluated)
);
exampleJson = ../../docs/komorebi.example.json;
schema = ../../schema.json;
in
pkgs.runCommand "nix-options-validation"
{
nativeBuildInputs = [
pkgs.check-jsonschema
pkgs.jq
];
}
''
echo "Validating the example, written in Nix, against the schema..."
check-jsonschema --schemafile ${schema} ${evaluatedJson}
echo "Validating the example file of the docs against the schema..."
check-jsonschema --schemafile ${schema} ${exampleJson}
echo "Checking that the two examples say the same..."
jq -e --slurpfile example ${exampleJson} 'contains($example[0])' ${evaluatedJson} > /dev/null
echo "All validations passed!"
touch $out
''