{ 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 keys = config.mySecrets.keys; empty = pkgs.runCommand "empty" { preferLocalBuild = true; } "mkdir -p $out && touch $out/done"; dumpKey = v: '' mkdir -p secrets/$(dirname ${v.dest}) echo -n ${lib.strings.escapeShellArg v.text} > 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}"; }; }; }