62 lines
1.6 KiB
Nix
62 lines
1.6 KiB
Nix
|
|
{ pkgs, lib, config, ... }:
|
||
|
|
let
|
||
|
|
inherit (lib.modules)
|
||
|
|
mkIf
|
||
|
|
;
|
||
|
|
inherit (lib.options)
|
||
|
|
mkOption
|
||
|
|
mkEnableOption
|
||
|
|
literalExpression
|
||
|
|
showOption
|
||
|
|
;
|
||
|
|
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;
|
||
|
|
in
|
||
|
|
{
|
||
|
|
options.dynamicism.for = mkOption {
|
||
|
|
type = t.attrsOf (t.submoduleWith {
|
||
|
|
modules = [ ./dynamic-submodule.nix ];
|
||
|
|
shorthandOnlyDefinesConfig = false;
|
||
|
|
});
|
||
|
|
default = { };
|
||
|
|
};
|
||
|
|
|
||
|
|
options.dynamicism.finalSettings = mkOption {
|
||
|
|
type = t.attrsOf t.raw;
|
||
|
|
internal = true;
|
||
|
|
readOnly = true;
|
||
|
|
};
|
||
|
|
|
||
|
|
config.assertions = lib.foldlAttrs (acc: name: submod: let
|
||
|
|
next = lib.optionals submod.enable (assertionsFor name submod);
|
||
|
|
in acc ++ next) [ ] cfg.for;
|
||
|
|
|
||
|
|
config.dynamicism.for = {
|
||
|
|
gotosocial = {
|
||
|
|
source-parameters = [ "services" "gotosocial" "settings" ];
|
||
|
|
systemd-services-updated = [ "gotosocial.service" ];
|
||
|
|
};
|
||
|
|
};
|
||
|
|
|
||
|
|
# FIXME: this should be a fold.
|
||
|
|
config.dynamicism.finalSettings = lib.mapAttrs (name: submod: let
|
||
|
|
#optValue = lib.getAttrFromPath submod.
|
||
|
|
# FIXME: this should be a fold.
|
||
|
|
optValue = lib.getAttrFromPath submod.source-parameters config;
|
||
|
|
in optValue) cfg.for;
|
||
|
|
}
|