2021-12-23 19:09:06 +00:00
|
|
|
{ config, pkgs, ... }: let {
|
2021-12-23 00:10:22 +00:00
|
|
|
lib = import ../../lib;
|
|
|
|
|
|
|
|
body.options.krebs.systemd.services = lib.mkOption {
|
|
|
|
default = {};
|
2021-12-23 19:09:06 +00:00
|
|
|
type = lib.types.attrsOf (lib.types.submodule {
|
|
|
|
options = {
|
2021-12-29 15:52:23 +00:00
|
|
|
restartIfCredentialsChange = lib.mkOption {
|
|
|
|
# Enabling this by default only makes sense here as the user already
|
|
|
|
# bothered to write down krebs.systemd.services.* = {}. If this
|
|
|
|
# functionality gets upstreamed to systemd.services, restarting
|
|
|
|
# should be disabled by default.
|
|
|
|
default = true;
|
2021-12-23 19:16:34 +00:00
|
|
|
description = ''
|
2021-12-29 15:52:23 +00:00
|
|
|
Whether to restart the service whenever any of its credentials
|
|
|
|
change. Only credentials with an absolute path in LoadCredential=
|
|
|
|
are supported.
|
2021-12-23 19:16:34 +00:00
|
|
|
'';
|
2021-12-29 15:52:23 +00:00
|
|
|
type = lib.types.bool;
|
2021-12-23 19:16:34 +00:00
|
|
|
};
|
2021-12-23 19:09:06 +00:00
|
|
|
};
|
|
|
|
});
|
2021-12-23 00:10:22 +00:00
|
|
|
};
|
|
|
|
|
2021-12-23 22:42:59 +00:00
|
|
|
body.config = {
|
|
|
|
systemd.paths = lib.mapAttrs' (serviceName: _:
|
|
|
|
lib.nameValuePair "trigger-${lib.systemd.encodeName serviceName}" {
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
pathConfig.PathChanged =
|
|
|
|
lib.filter
|
|
|
|
lib.types.absolute-pathname.check
|
|
|
|
(map
|
|
|
|
(lib.compose [ lib.maybeHead (lib.match "[^:]*:(.*)") ])
|
2021-12-23 23:49:30 +00:00
|
|
|
(lib.toList
|
|
|
|
config.systemd.services.${serviceName}.serviceConfig.LoadCredential));
|
2021-12-23 22:42:59 +00:00
|
|
|
}
|
|
|
|
) config.krebs.systemd.services;
|
|
|
|
|
|
|
|
systemd.services = lib.mapAttrs' (serviceName: cfg:
|
|
|
|
lib.nameValuePair "trigger-${lib.systemd.encodeName serviceName}" {
|
|
|
|
serviceConfig = {
|
|
|
|
Type = "oneshot";
|
2021-12-29 15:52:23 +00:00
|
|
|
ExecStart = "${pkgs.systemd}/bin/systemctl restart ${lib.shell.escape serviceName}";
|
2021-12-23 22:42:59 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
) config.krebs.systemd.services;
|
|
|
|
};
|
2021-12-23 00:10:22 +00:00
|
|
|
}
|