cluster/services/locksmith: allow waiting for keys
This commit is contained in:
parent
d7f816ee39
commit
55741bc8f6
1 changed files with 74 additions and 38 deletions
|
@ -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
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue