1{lib, config, ...}: let2 inherit (lib.options) mkOption;3 inherit (lib.types) unspecified nullOr listOf str bool attrsOf submodule;4 inherit (lib.strings) concatStringsSep;5 inherit (lib.attrsets) mapAttrs;67 sharedSecret = {config, ...}: {8 options = {9 expectedOwners = mkOption {10 type = nullOr (listOf str);11 description = ''12 List of hosts to encrypt secret for. null if managed by user (= via owners field from fleet.nix)1314 Secrets would be decrypted and stored to /run/secrets/$\{name} on owners15 '';16 default = null;17 };18 19 regenerateOnOwnerAdded = mkOption {20 type = bool;21 description = ''22 Is this secret owner-dependent, and needs to be regenerated on ownership set change, or it may be just reencrypted.2324 You want to have this option set to true, when this secret contains some reference to its owners, i.e x509 SANs.25 '';26 };27 regenerateOnOwnerRemoved = mkOption {28 default = config.regenerateOnOwnerAdded;29 type = bool;30 description = ''31 Should this secret be removed on owner removal, or it may be just reencrypted3233 Most probably its value should be equal to regenerateOnOwnerAdded, override only if you know what are you doing.34 Contrary to regenerateOnOwnerAdded, you may want to set this option to false, when host permissions are revoked35 in some other way than by this secret ownership, I.e by firewall/etc.36 '';37 };38 generator = mkOption {39 type = nullOr unspecified;40 description = "Derivation to evaluate for secret generation";41 default = null;42 };43 };44 };45in {46 options = {47 sharedSecrets = mkOption {48 type = attrsOf (submodule sharedSecret);49 default = {};50 description = "Shared secrets";51 };52 };53 config = {54 hosts = mapAttrs (_: secretMap: {55 nixos.secrets = mapAttrs (_: s: removeAttrs s ["createdAt" "expiresAt"]) secretMap;56 }) config.data.hostSecrets;57 nixpkgs.overlays = [58 (final: prev: {59 mkSecretGenerators = {recipients}: rec {60 61 62 63 mkImpureSecretGenerator = {64 script,65 66 67 impureOn ? null,68 }:69 (prev.writeShellScript "impureGenerator.sh" ''70 71 set -eu7273 export GENERATOR_HELPER_IDENTITIES="${concatStringsSep "\n" recipients}";74 export PATH=${final.fleet-generator-helper}/bin:$PATH7576 77 tmp=$(mktemp -d)78 cd $tmp79 8081 created_at=$(date -u +"%Y-%m-%dT%H:%M:%S.%NZ")8283 ${script}8485 if ! test -d $out; then86 echo "impure generator script did not produce expected \$out output"87 exit 188 fi8990 echo -n $created_at > $out/created_at91 echo -n SUCCESS > $out/marker92 '')93 .overrideAttrs (old: {94 passthru = {95 inherit impureOn;96 generatorKind = "impure";97 };98 });99 100 mkSecretGenerator = {script}: mkImpureSecretGenerator {inherit script;};101102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 };131 })132 ];133 };134}