From: Ismaël Bouya Date: Wed, 24 Apr 2019 23:35:25 +0000 (+0200) Subject: Start building a secrets.tar to reduce upload time for nixops X-Git-Tag: nur_publish~116 X-Git-Url: https://git.immae.eu/?a=commitdiff_plain;h=44742a43dac86a79274486a9b73a349c5d4ec631;hp=78e25e2ac542eceb33aa0d292397d5236dbb9df8;p=perso%2FImmae%2FConfig%2FNix.git Start building a secrets.tar to reduce upload time for nixops --- diff --git a/nixops/eldiron.nix b/nixops/eldiron.nix index 5e0227d..a85b9de 100644 --- a/nixops/eldiron.nix +++ b/nixops/eldiron.nix @@ -43,6 +43,7 @@ ./modules/irc ./modules/buildbot ./modules/dns + ./modules/secrets ]; services.myGitolite.enable = true; services.myDatabases.enable = true; diff --git a/nixops/modules/secrets/default.nix b/nixops/modules/secrets/default.nix new file mode 100644 index 0000000..7096e48 --- /dev/null +++ b/nixops/modules/secrets/default.nix @@ -0,0 +1,68 @@ +{ lib, pkgs, config, myconfig, mylibs, ... }: +{ + options.mySecrets = { + keys = lib.mkOption { + type = lib.types.listOf lib.types.unspecified; + default = {}; + description = "Keys to upload to server"; + }; + }; + config = let + oldkeys = lib.attrsets.filterAttrs (n: v: n != "secrets.tar") config.deployment.keys; + keys = config.mySecrets.keys; + empty = pkgs.runCommand "empty" { preferLocalBuild = true; } "mkdir -p $out && touch $out/done"; + dumpOldKey = k: v: let + dest = if v.destDir == "/run/keys" + then k + else (builtins.replaceStrings ["/run/keys/"] [""] v.destDir) + "/" + k; + in '' + mkdir -p secrets/$(dirname ${dest}) + echo -n ${lib.strings.escapeShellArg v.text} > secrets/${dest} + cat >> mods < secrets/${v.dest} + cat >> mods < /var/secrets/currentSecrets + find /var/secrets -type d -exec chown root:keys {} \; -exec chmod o-rx {} \; + fi + fi + ''; + }; + deployment.keys."secrets.tar" = { + 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}"; + }; + }; +}