|
26 | 26 |
|
27 | 27 | home.activation.sopsFallbackSecrets = lib.hm.dag.entryAfter [ "writeBoundary" ] '' |
28 | 28 | if [ -f "${cfg.age.keyFile}" ]; then |
29 | | - ${lib.concatStringsSep "\n" (lib.mapAttrsToList (name: secret: '' |
30 | | - if [ -n "${secret.path or ""}" ] && [ ! -e "${secret.path}" ]; then |
31 | | - mkdir -p "$(dirname "${secret.path}")" |
| 29 | + ${lib.concatStringsSep "\n" (lib.mapAttrsToList (name: secret: let |
| 30 | + secretPath = if (secret.path != null && secret.path != "") |
| 31 | + then secret.path |
| 32 | + else "${cfg.defaultSecretsMountPoint}/${name}"; |
| 33 | + in '' |
| 34 | + if [ ! -e "${secretPath}" ]; then |
| 35 | + mkdir -p "$(dirname "${secretPath}")" |
32 | 36 | SOPS_AGE_KEY_FILE="${cfg.age.keyFile}" $DRY_RUN_CMD ${pkgs.sops}/bin/sops --decrypt \ |
33 | 37 | --extract '["${lib.replaceStrings ["/"] ["\"][\""] name}"]' \ |
34 | | - ${secret.sopsFile} > "${secret.path}" 2>/dev/null || true |
35 | | - chmod ${secret.mode or "0600"} "${secret.path}" |
| 38 | + ${secret.sopsFile} > "${secretPath}" 2>/dev/null || true |
| 39 | + chmod ${secret.mode or "0600"} "${secretPath}" |
36 | 40 | fi |
37 | | - '') (lib.filterAttrs (_: s: s.path != null && s.path != "") cfg.secrets))} |
| 41 | + '') cfg.secrets)} |
| 42 | +
|
| 43 | + ${lib.concatStringsSep "\n" (lib.mapAttrsToList (tName: template: '' |
| 44 | + mkdir -p "$(dirname "${template.path}")" |
| 45 | + TMP_FILE=$(mktemp) |
| 46 | + cp "${template.file}" "$TMP_FILE" |
| 47 | + ${lib.concatStringsSep "\n" (lib.mapAttrsToList (sName: secret: let |
| 48 | + secretPath = if (secret.path != null && secret.path != "") |
| 49 | + then secret.path |
| 50 | + else "${cfg.defaultSecretsMountPoint}/${sName}"; |
| 51 | + placeholder = cfg.placeholder."${sName}"; |
| 52 | + in '' |
| 53 | + if [ -f "${secretPath}" ]; then |
| 54 | + SECRET_VAL=$(cat "${secretPath}") |
| 55 | + ${pkgs.python3}/bin/python3 -c " |
| 56 | +import sys |
| 57 | +content = open(sys.argv[1]).read() |
| 58 | +placeholder = sys.argv[2] |
| 59 | +val = sys.argv[3] |
| 60 | +new_content = content.replace(placeholder, val) |
| 61 | +open(sys.argv[1], 'w').write(new_content) |
| 62 | +" "$TMP_FILE" "${placeholder}" "$SECRET_VAL" |
| 63 | + fi |
| 64 | + '') cfg.secrets)} |
| 65 | + $DRY_RUN_CMD cp "$TMP_FILE" "${template.path}" |
| 66 | + $DRY_RUN_CMD chmod ${template.mode or "0600"} "${template.path}" |
| 67 | + rm -f "$TMP_FILE" |
| 68 | + '') cfg.templates)} |
38 | 69 | fi |
39 | 70 | ''; |
40 | 71 | } |
0 commit comments