forked from clan/clan-core
Merge pull request 'Add jsonschema test case' (#1309) from Qubasa-main into main
This commit is contained in:
commit
f8e08a610e
@ -17,7 +17,7 @@ let
|
||||
location: ${lib.concatStringsSep "." option.loc}
|
||||
'';
|
||||
|
||||
# Exclude the option if it's type is in the excludedTypes list
|
||||
# Exclude the option if its type is in the excludedTypes list
|
||||
# or if the option has a defaultText attribute
|
||||
isExcludedOption =
|
||||
option: ((lib.elem (option.type.name or null) excludedTypes) || (option ? defaultText));
|
||||
@ -26,6 +26,9 @@ let
|
||||
|
||||
filterExcludedAttrs = lib.filterAttrs (_name: opt: !isExcludedOption opt);
|
||||
|
||||
# Filter out options where the visible attribute is set to false
|
||||
filterInvisibleOpts = lib.filterAttrs (_name: opt: opt.visible or true);
|
||||
|
||||
allBasicTypes = [
|
||||
"boolean"
|
||||
"integer"
|
||||
@ -50,7 +53,7 @@ rec {
|
||||
parseOptions =
|
||||
options':
|
||||
let
|
||||
options = filterExcludedAttrs (clean options');
|
||||
options = filterInvisibleOpts (filterExcludedAttrs (clean options'));
|
||||
# parse options to jsonschema properties
|
||||
properties = lib.mapAttrs (_name: option: parseOption option) options;
|
||||
# TODO: figure out how to handle if prop.anyOf is used
|
||||
|
@ -10,5 +10,11 @@
|
||||
},
|
||||
"services": {
|
||||
"opt": "this option doesn't make sense"
|
||||
},
|
||||
"destinations": {
|
||||
"test-backup": {
|
||||
"name": "John Doe",
|
||||
"repo": "test-backup"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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 = { };
|
||||
};
|
||||
};
|
||||
}
|
||||
|
@ -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"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -7,7 +7,7 @@
|
||||
|
||||
# Uncomment if you only want one module to be available
|
||||
# clanModules = {
|
||||
# syncthing = self.clanModules.syncthing;
|
||||
# borgbackup = self.clanModules.borgbackup;
|
||||
# };
|
||||
|
||||
baseModule = {
|
||||
@ -30,6 +30,7 @@
|
||||
];
|
||||
};
|
||||
in
|
||||
# Filter out "injected" options that are not part of the module
|
||||
if (evaled.options.clan ? "${modulename}") then evaled.options.clan.${modulename} else { };
|
||||
|
||||
clanModuleSchemas = lib.mapAttrs (
|
||||
@ -46,7 +47,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
|
||||
'';
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user