cluster/services/locksmith: allow waiting for keys

This commit is contained in:
Max Headroom 2024-07-10 23:01:49 +02:00
parent d7f816ee39
commit 55741bc8f6

View file

@ -9,6 +9,40 @@ let
kvValue = "recipient/${config.networking.hostName}"; kvValue = "recipient/${config.networking.hostName}";
in in
{
options.services.locksmith.waitForSecrets = lib.mkOption {
type = with lib.types; attrsOf (listOf str);
};
config = lib.mkMerge [
{
systemd.services = lib.mapAttrs' (name: secrets: {
name = "locksmith-wait-secrets-${name}";
value = {
description = "Wait for secrets: ${name}";
after = [ "locksmith.service" ];
before = [ "${name}.service" ];
requiredBy = [ "${name}.service" ];
serviceConfig = {
Type = "oneshot";
IPAddressDeny = [ "any" ];
};
path = [
pkgs.inotify-tools
];
script = ''
for key in ${lib.escapeShellArgs secrets}; do
if ! test -e "$key"; then
echo "Waiting for secret: $key"
inotifywait -qq -e create,moved_to --include "$key" /run/locksmith
fi
echo "Heard secret: $key"
done
echo "All secrets known."
'';
};
}) config.services.locksmith.waitForSecrets;
}
{ {
systemd.tmpfiles.settings.locksmith = { systemd.tmpfiles.settings.locksmith = {
"/run/locksmith".d = { "/run/locksmith".d = {
@ -51,3 +85,5 @@ in
''; '';
}; };
} }
];
}