1{2 lib,3 config,4 ...5}: let6 inherit (lib.options) mkOption;7 inherit (lib.types) unspecified nullOr listOf str bool attrsOf submodule;8 inherit (lib.strings) concatStringsSep;9 inherit (lib.attrsets) mapAttrs;1011 sharedSecret = {config, ...}: {12 options = {13 expectedOwners = mkOption {14 type = nullOr (listOf str);15 description = ''16 List of hosts to encrypt secret for. null if managed by user (= via owners field from fleet.nix)1718 Secrets would be decrypted and stored to /run/secrets/$\{name} on owners19 '';20 default = null;21 };22 23 regenerateOnOwnerAdded = mkOption {24 type = bool;25 description = ''26 Is this secret owner-dependent, and needs to be regenerated on ownership set change, or it may be just reencrypted.2728 You want to have this option set to true, when this secret contains some reference to its owners, i.e x509 SANs.29 '';30 };31 regenerateOnOwnerRemoved = mkOption {32 default = config.regenerateOnOwnerAdded;33 type = bool;34 description = ''35 Should this secret be removed on owner removal, or it may be just reencrypted3637 Most probably its value should be equal to regenerateOnOwnerAdded, override only if you know what are you doing.38 Contrary to regenerateOnOwnerAdded, you may want to set this option to false, when host permissions are revoked39 in some other way than by this secret ownership, I.e by firewall/etc.40 '';41 };42 generator = mkOption {43 type = nullOr unspecified;44 description = "Derivation to evaluate for secret generation";45 default = null;46 };47 };48 };49in {50 options = {51 sharedSecrets = mkOption {52 type = attrsOf (submodule sharedSecret);53 default = {};54 description = "Shared secrets";55 };56 };57 config = {58 hosts =59 mapAttrs (_: secretMap: {60 nixos.secrets = mapAttrs (_: s: removeAttrs s ["createdAt" "expiresAt"]) secretMap;61 })62 config.data.hostSecrets;63 nixpkgs.overlays = [64 (final: prev: {65 mkSecretGenerators = {recipients}: rec {66 67 68 69 mkImpureSecretGenerator = {70 script,71 72 73 impureOn ? null,74 }:75 (prev.writeShellScript "impureGenerator.sh" ''76 77 set -eu7879 export GENERATOR_HELPER_IDENTITIES="${concatStringsSep "\n" recipients}";80 export PATH=${final.fleet-generator-helper}/bin:$PATH8182 83 tmp=$(mktemp -d)84 cd $tmp85 8687 created_at=$(date -u +"%Y-%m-%dT%H:%M:%S.%NZ")8889 ${script}9091 if ! test -d $out; then92 echo "impure generator script did not produce expected \$out output"93 exit 194 fi9596 echo -n $created_at > $out/created_at97 echo -n SUCCESS > $out/marker98 '')99 .overrideAttrs (old: {100 passthru = {101 inherit impureOn;102 generatorKind = "impure";103 };104 });105 106 mkSecretGenerator = {script}: mkImpureSecretGenerator {inherit script;};107108 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 135 136 };137 })138 ];139 };140}