From 159198b81a15b30aa7c55e88d493b1a89ed98e48 Mon Sep 17 00:00:00 2001 From: Qubasa Date: Fri, 3 May 2024 18:22:20 +0200 Subject: [PATCH] Add jsonschema test case --- lib/jsonschema/example-data.json | 5 +++++ lib/jsonschema/example-interface.nix | 21 +++++++++++++++++++++ lib/jsonschema/example-schema.json | 21 +++++++++++++++++++++ pkgs/schemas/flake-module.nix | 2 +- 4 files changed, 48 insertions(+), 1 deletion(-) diff --git a/lib/jsonschema/example-data.json b/lib/jsonschema/example-data.json index 240016f7..8660027f 100644 --- a/lib/jsonschema/example-data.json +++ b/lib/jsonschema/example-data.json @@ -10,5 +10,10 @@ }, "services": { "opt": "this option doesn't make sense" + }, + "destinations": { + "test-backup": { + "name": "John Doe" + } } } diff --git a/lib/jsonschema/example-interface.nix b/lib/jsonschema/example-interface.nix index 97fe4145..0ba65018 100644 --- a/lib/jsonschema/example-interface.nix +++ b/lib/jsonschema/example-interface.nix @@ -50,5 +50,26 @@ ]; description = "A list of enabled kernel modules"; }; + destinations = lib.mkOption { + type = lib.types.attrsOf ( + lib.types.submodule ( + { name, ... }: + { + options = { + name = lib.mkOption { + type = lib.types.strMatching "^[a-zA-Z0-9._-]+$"; + default = name; + description = "the name of the backup job"; + }; + repo = lib.mkOption { + type = lib.types.str; + description = "the borgbackup repository to backup to"; + }; + }; + } + ) + ); + default = { }; + }; }; } diff --git a/lib/jsonschema/example-schema.json b/lib/jsonschema/example-schema.json index 62d68fb1..0073369e 100644 --- a/lib/jsonschema/example-schema.json +++ b/lib/jsonschema/example-schema.json @@ -45,6 +45,27 @@ "description": "A submodule option" } } + }, + "destinations": { + "additionalProperties": { + "properties": { + "name": { + "default": "‹name›", + "description": "the name of the backup job", + "type": "string" + }, + "repo": { + "description": "the borgbackup repository to backup to", + "type": "string" + } + }, + "required": [ + "repo" + ], + "type": "object" + }, + "default": {}, + "type": "object" } } } diff --git a/pkgs/schemas/flake-module.nix b/pkgs/schemas/flake-module.nix index e3f17a0e..c124f44a 100644 --- a/pkgs/schemas/flake-module.nix +++ b/pkgs/schemas/flake-module.nix @@ -46,7 +46,7 @@ checks = { module-schema = pkgs.runCommand "schema-checks" { } '' ${pkgs.check-jsonschema}/bin/check-jsonschema \ - --check-metaschema --fill-defaults ${packages.module-schema} + --check-metaschema ${packages.module-schema} touch $out ''; };