PoC part 2

This commit is contained in:
Qyriad 2026-02-03 22:31:32 +01:00
parent 0580ad02bd
commit 15ed56d8ad
3 changed files with 117 additions and 40 deletions

View file

@ -1,5 +1,6 @@
{
name,
pkgs,
lib,
config,
...
@ -13,10 +14,26 @@ let
mkEnableOption
literalExpression
;
inherit (lib.types)
mkOptionType
;
t = lib.types;
/** Either a list of strings, or a dotted string that will be split. */
convenientAttrPath = t.coercedTo t.str (lib.splitString ".") (t.listOf t.str);
executablePathInStore = mkOptionType {
name = "exepath";
description = "executable path in the Nix store";
descriptionClass = "noun";
merge = lib.mergeEqualOption;
functor = lib.defaultFunctor "exepath";
check = x: if lib.isDerivation x then (
x.meta.mainProgram or null != null
) else (
lib.pathInStore.check x
);
};
in
{
options = {
@ -36,12 +53,46 @@ in
A list of systemd unit names (including the suffix, e.g. `.service`) that need to be updated.
'';
example = literalExpression ''
"gotosocial.service"
[ "gotosocial.service" ]
'';
default = lib.attrNames config.unitDropins;
};
configFile = mkOption {
type = t.pathInStore;
internal = true;
};
unitDropins = mkOption {
type = t.attrsOf t.pathInStore;
internal = true;
};
activate = mkOption {
type = executablePathInStore;
internal = true;
};
};
config = mkIf config.enable {
activate = pkgs.writeShellApplication {
name = "dynamicism-for-${name}-activate";
runtimeInputs = [ pkgs.systemd ];
text = let
doEdits = config.unitDropins
|> lib.mapAttrsToList (service: dropin: ''
cat "${dropin}" | systemctl edit "${service}" --runtime --stdin
'');
doReloads = config.unitDropins
|> lib.mapAttrsToList (service: _: ''
systemctl reload-or-restart "${service}"
'');
in [
doEdits
doReloads
] |> lib.concatLists
|> lib.concatStringsSep "\n";
};
};
}