diff options
author | makefu <github@syntax-fehler.de> | 2016-02-22 14:35:59 +0100 |
---|---|---|
committer | makefu <github@syntax-fehler.de> | 2016-02-22 14:35:59 +0100 |
commit | b25d15573ab10a4b2dd55e46291fbab6adf70162 (patch) | |
tree | 1036547a8003c5767565d53d748d83d3614271b6 /krebs/3modules/secret.nix | |
parent | 5b7039f1f11e7cf2da6f3735cc7d99322a31c7a5 (diff) | |
parent | 8393444dce1888d369955e46dd16983a43762bb9 (diff) |
Merge remote-tracking branch 'cd/master'
Diffstat (limited to 'krebs/3modules/secret.nix')
-rw-r--r-- | krebs/3modules/secret.nix | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/krebs/3modules/secret.nix b/krebs/3modules/secret.nix new file mode 100644 index 000000000..579f375f3 --- /dev/null +++ b/krebs/3modules/secret.nix @@ -0,0 +1,39 @@ +{ config, lib, pkgs, ... }@args: with config.krebs.lib; let + cfg = config.krebs.secret; +in { + options.krebs.secret = { + files = mkOption { + type = with types; attrsOf secret-file; + default = {}; + }; + }; + config = lib.mkIf (cfg.files != {}) { + systemd.services.secret = let + # TODO fail if two files have the same path but differ otherwise + files = unique (map (flip removeAttrs ["_module"]) + (attrValues cfg.files)); + in { + serviceConfig = { + Type = "oneshot"; + RemainAfterExit = "yes"; + SyslogIdentifier = "secret"; + ExecStart = pkgs.writeDash "install-secret-files" '' + exit_code=0 + ${concatMapStringsSep "\n" (file: '' + ${pkgs.coreutils}/bin/install \ + -D \ + --compare \ + --verbose \ + --mode=${shell.escape file.mode} \ + --owner=${shell.escape file.owner.name} \ + --group=${shell.escape file.group-name} \ + ${shell.escape file.source-path} \ + ${shell.escape file.path} \ + || exit_code=1 + '') files} + exit $exit_code + ''; + }; + }; + }; +} |