refactor assertions
This commit is contained in:
parent
fe8d00b2c2
commit
0580ad02bd
3 changed files with 29 additions and 19 deletions
|
|
@ -45,10 +45,15 @@ in dynix.overrideAttrs (final: prev: let
|
||||||
self = final.finalPackage;
|
self = final.finalPackage;
|
||||||
in lib.recursiveUpdate prev {
|
in lib.recursiveUpdate prev {
|
||||||
passthru = {
|
passthru = {
|
||||||
|
dync = self.nixos.config.dynamicism;
|
||||||
|
dyno = self.nixos.options.dynamicism;
|
||||||
|
gotosocial = self.nixos.options.dynamicism.for.valueMeta.attrs.gotosocial.configuration;
|
||||||
|
|
||||||
inherit byStdenv;
|
inherit byStdenv;
|
||||||
nixos = evalNixos {
|
nixos = evalNixos {
|
||||||
configuration = ./configuration.nix;
|
configuration = ./configuration.nix;
|
||||||
};
|
};
|
||||||
|
c = self.nixos;
|
||||||
nixos-vm = self.nixos.config.system.build.vm;
|
nixos-vm = self.nixos.config.system.build.vm;
|
||||||
doChange = builtins.seq self.nixos.config.dynamicism doChange;
|
doChange = builtins.seq self.nixos.config.dynamicism doChange;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -11,20 +11,8 @@ let
|
||||||
;
|
;
|
||||||
t = lib.types;
|
t = lib.types;
|
||||||
cfg = config.dynamicism;
|
cfg = config.dynamicism;
|
||||||
|
opts = options.dynamicism;
|
||||||
settingsFormat = pkgs.formats.yaml { };
|
subOpts = lib.mapAttrs (_: metaAttr: metaAttr.configuration.options) options.dynamicism.for.valueMeta.attrs;
|
||||||
|
|
||||||
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;
|
|
||||||
|
|
||||||
finalSettingsFor = { ... }@submod: lib.foldl (acc: optPath: let
|
finalSettingsFor = { ... }@submod: lib.foldl (acc: optPath: let
|
||||||
next =
|
next =
|
||||||
|
|
@ -52,14 +40,31 @@ in
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
config.assertions = lib.foldlAttrs (acc: name: submod: let
|
config.assertions = let
|
||||||
next = lib.optionals submod.enable (assertionsFor name submod);
|
unitsExist = lib.foldl' (acc: submod: let
|
||||||
in acc ++ next) [ ] cfg.for;
|
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 = {
|
config.dynamicism.for = {
|
||||||
gotosocial = {
|
gotosocial = {
|
||||||
source-options = [
|
source-options = [
|
||||||
"services.gotosocial.settings"
|
"services.gotosocial.setting"
|
||||||
];
|
];
|
||||||
systemd-services-updated = [
|
systemd-services-updated = [
|
||||||
"gotosocial.service"
|
"gotosocial.service"
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,7 @@ let
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
options = {
|
options = {
|
||||||
enable = mkEnableOption "Enable dynamicism for '${name}'";
|
enable = mkEnableOption "dynamicism for '${name}'";
|
||||||
|
|
||||||
source-options = mkOption {
|
source-options = mkOption {
|
||||||
type = t.listOf convenientAttrPath;
|
type = t.listOf convenientAttrPath;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue