X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=modules%2Fsecrets.nix;h=ecc1ebc56a976023911fb1ac8b88968b6e9e85df;hb=0c67c58418d0b69135109765226e31137bd13c0a;hp=808b15c5bdeb886347a8f9c34f69891495e0999f;hpb=17f6eae9907a122d4472da727ae8b1ac1c40c027;p=perso%2FImmae%2FConfig%2FNix.git diff --git a/modules/secrets.nix b/modules/secrets.nix index 808b15c..ecc1ebc 100644 --- a/modules/secrets.nix +++ b/modules/secrets.nix @@ -11,16 +11,26 @@ default = "/var/secrets"; description = "Location where to put the keys"; }; + # Read-only variables + fullPaths = lib.mkOption { + type = lib.types.attrsOf lib.types.path; + default = builtins.listToAttrs + (map (v: { name = v.dest; value = "${config.secrets.location}/${v.dest}"; }) config.secrets.keys); + readOnly = true; + description = "set of full paths to secrets"; + }; }; + config = let location = config.secrets.location; keys = config.secrets.keys; empty = pkgs.runCommand "empty" { preferLocalBuild = true; } "mkdir -p $out && touch $out/done"; + fpath = v: "secrets/${v.dest}${lib.optionalString (v.isTemplated or true) ".gucci.tpl"}"; dumpKey = v: '' mkdir -p secrets/$(dirname ${v.dest}) - echo -n ${lib.strings.escapeShellArg v.text} > secrets/${v.dest} + echo -n ${lib.strings.escapeShellArg v.text} > ${fpath v} cat >> mods < $TMP/currentSecrets + if [ -f /run/keys/vars.yml ]; then + find $TMP -name "*.gucci.tpl" -exec \ + /bin/sh -c 'f="{}"; ${pkgs.gucci}/bin/gucci -f /run/keys/vars.yml "$f" > "''${f%.gucci.tpl}"; touch --reference "$f" ''${f%.gucci.tpl} ; chmod --reference="$f" ''${f%.gucci.tpl} ; chown --reference="$f" ''${f%.gucci.tpl}' \; + sha512sum /run/keys/secrets.tar /run/keys/vars.yml > $TMP/currentSecrets + else + sha512sum /run/keys/secrets.tar > $TMP/currentSecrets + fi find $TMP -type d -exec chown root:keys {} \; -exec chmod o-rx {} \; - ${pkgs.rsync}/bin/rsync -O -c -av --delete $TMP/ ${location} + ${pkgs.rsync}/bin/rsync --exclude="*.gucci.tpl" -O -c -av --delete $TMP/ ${location} rm -rf $TMP fi fi fi ''; }; - deployment.keys."secrets.tar" = { + + system.extraDependencies = [ secrets ]; + deployment.secrets."secret_vars.yml" = { + source = builtins.toString ; + destination = "/run/keys/vars.yml"; + owner.user = "root"; + owner.group = "root"; + permissions = "0400"; + }; + deployment.secrets."secrets.tar" = { + source = "${secrets}"; + destination = "/run/keys/secrets.tar"; + owner.user = "root"; + owner.group = "root"; permissions = "0400"; - # keyFile below is not evaluated at build time by nixops, so the - # `secrets` path doesn’t necessarily exist when uploading the - # keys, and nixops is unhappy. - user = "root${builtins.substring 10000 1 secrets}"; - group = "root"; - keyFile = "${secrets}"; }; }; }