factor out do_append in prep for delta subcommands
This commit is contained in:
parent
8477c73067
commit
9ae0630db4
8 changed files with 237 additions and 56 deletions
61
dynamic-options.nix
Normal file
61
dynamic-options.nix
Normal file
|
|
@ -0,0 +1,61 @@
|
|||
{ 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;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue