refactor assertions
This commit is contained in:
parent
fe8d00b2c2
commit
0580ad02bd
3 changed files with 29 additions and 19 deletions
|
|
@ -11,20 +11,8 @@ let
|
|||
;
|
||||
t = lib.types;
|
||||
cfg = config.dynamicism;
|
||||
|
||||
settingsFormat = pkgs.formats.yaml { };
|
||||
|
||||
assertionFor = submodName: unitName: let
|
||||
optName = [ "dynamicism" "for" submodName "systemd-services-updated" ];
|
||||
in {
|
||||
assertion = config.systemd.units.${unitName}.enable or false;
|
||||
message = "'${showOption optName}' specified non-existentant unit '${unitName}'";
|
||||
};
|
||||
|
||||
assertionsFor =
|
||||
submodName:
|
||||
submod:
|
||||
lib.map (assertionFor submodName) submod.systemd-services-updated;
|
||||
opts = options.dynamicism;
|
||||
subOpts = lib.mapAttrs (_: metaAttr: metaAttr.configuration.options) options.dynamicism.for.valueMeta.attrs;
|
||||
|
||||
finalSettingsFor = { ... }@submod: lib.foldl (acc: optPath: let
|
||||
next =
|
||||
|
|
@ -52,14 +40,31 @@ in
|
|||
};
|
||||
};
|
||||
|
||||
config.assertions = lib.foldlAttrs (acc: name: submod: let
|
||||
next = lib.optionals submod.enable (assertionsFor name submod);
|
||||
in acc ++ next) [ ] cfg.for;
|
||||
config.assertions = let
|
||||
unitsExist = lib.foldl' (acc: submod: let
|
||||
next = lib.map (unit: assert lib.isString unit; {
|
||||
assertion = config.systemd.units.${unit}.enable or false;
|
||||
message = ''
|
||||
'${showOption submod.systemd-services-updated.loc}' specified non-existent unit '${unit}'
|
||||
'';
|
||||
}) submod.systemd-services-updated.value;
|
||||
in acc ++ lib.optionals submod.enable.value next) [ ] (lib.attrValues subOpts);
|
||||
|
||||
optsExist = lib.foldl' (acc: submod: let
|
||||
next = lib.map (optPath: {
|
||||
assertion = lib.hasAttrByPath optPath options;
|
||||
message = "'${showOption submod.source-options.loc}' specified non-existent option '${showOption optPath}'";
|
||||
}) submod.source-options.value;
|
||||
in acc ++ lib.optionals submod.enable.value next) [ ] (lib.attrValues subOpts);
|
||||
in lib.concatLists [
|
||||
unitsExist
|
||||
optsExist
|
||||
];
|
||||
|
||||
config.dynamicism.for = {
|
||||
gotosocial = {
|
||||
source-options = [
|
||||
"services.gotosocial.settings"
|
||||
"services.gotosocial.setting"
|
||||
];
|
||||
systemd-services-updated = [
|
||||
"gotosocial.service"
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ let
|
|||
in
|
||||
{
|
||||
options = {
|
||||
enable = mkEnableOption "Enable dynamicism for '${name}'";
|
||||
enable = mkEnableOption "dynamicism for '${name}'";
|
||||
|
||||
source-options = mkOption {
|
||||
type = t.listOf convenientAttrPath;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue