2023-06-10 10:50:53 +00:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
with import ../../lib/pure.nix { inherit lib; }; let
|
2016-02-21 04:27:37 +00:00
|
|
|
cfg = config.krebs.secret;
|
|
|
|
in {
|
|
|
|
options.krebs.secret = {
|
2020-10-14 10:18:59 +00:00
|
|
|
directory = mkOption {
|
|
|
|
default = toString <secrets>;
|
|
|
|
type = types.absolute-pathname;
|
|
|
|
};
|
2016-02-21 04:27:37 +00:00
|
|
|
files = mkOption {
|
2023-06-10 10:50:53 +00:00
|
|
|
type = with pkgs.stockholm.lib.types; attrsOf secret-file;
|
2016-02-21 04:27:37 +00:00
|
|
|
default = {};
|
2023-09-11 13:31:13 +00:00
|
|
|
apply = mapAttrs (name: secret-file:
|
|
|
|
if types.absolute-pathname.check secret-file.source-path then
|
|
|
|
secret-file
|
|
|
|
else
|
|
|
|
secret-file // {
|
|
|
|
source-path = "${config.krebs.secret.directory}/secret-file.source-path";
|
|
|
|
}
|
|
|
|
);
|
2016-02-21 04:27:37 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
config = lib.mkIf (cfg.files != {}) {
|
2020-08-04 20:22:43 +00:00
|
|
|
systemd.paths =
|
|
|
|
mapAttrs'
|
|
|
|
(name: file: nameValuePair "secret-trigger-${systemd.encodeName name}" {
|
|
|
|
wantedBy = ["multi-user.target"];
|
|
|
|
pathConfig.PathChanged = file.source-path;
|
|
|
|
})
|
|
|
|
cfg.files;
|
|
|
|
systemd.services =
|
|
|
|
mapAttrs'
|
|
|
|
(name: file: nameValuePair "secret-trigger-${systemd.encodeName name}" {
|
|
|
|
serviceConfig = {
|
|
|
|
Type = "oneshot";
|
2020-08-11 18:56:01 +00:00
|
|
|
ExecStart = "${pkgs.systemd}/bin/systemctl restart ${shell.escape file.service}";
|
2020-08-04 20:22:43 +00:00
|
|
|
};
|
|
|
|
})
|
|
|
|
cfg.files
|
|
|
|
//
|
|
|
|
mapAttrs'
|
|
|
|
(name: file: nameValuePair "secret-${systemd.encodeName name}" {
|
|
|
|
wantedBy = ["multi-user.target"];
|
|
|
|
serviceConfig = {
|
|
|
|
Type = "oneshot";
|
|
|
|
RemainAfterExit = "yes";
|
|
|
|
ExecStart = toString [
|
|
|
|
"${pkgs.coreutils}/bin/install"
|
|
|
|
"-D"
|
|
|
|
"--compare"
|
|
|
|
"--verbose"
|
|
|
|
"--mode=${file.mode}"
|
|
|
|
"--owner=${file.owner.name}"
|
|
|
|
"--group=${file.group-name}"
|
|
|
|
file.source-path
|
|
|
|
file.path
|
|
|
|
];
|
|
|
|
};
|
|
|
|
})
|
|
|
|
cfg.files;
|
2016-02-21 04:27:37 +00:00
|
|
|
};
|
|
|
|
}
|