|
111 | 111 | wantedBy = [ "multi-user.target" ]; |
112 | 112 | requires = [ "network-online.target" ]; |
113 | 113 |
|
114 | | - serviceConfig = { |
| 114 | + serviceConfig = (lib.optionalAttrs (cfg.email.passwordFile != null) { |
| 115 | + LoadCredential = "emailPassword:${cfg.email.passwordFile}"; |
| 116 | + }) // { |
115 | 117 | ExecStart = "${cfg.package}/bin/AttestationServer"; |
116 | 118 | ExecStartPre = let |
117 | 119 | inherit (cfg.email) username passwordFile host port local; |
|
120 | 122 | # truncate the trailing newline (\n = char(10)) anyway. |
121 | 123 | values = lib.concatStringsSep ", " [ |
122 | 124 | "('emailUsername', '${username}')" |
123 | | - "('emailPassword', TRIM(readfile('%S/attestation/emailPassword'), char(10)))" |
| 125 | + "('emailPassword', TRIM(readfile('$CREDENTIALS_DIRECTORY/emailPassword'), char(10)))" |
124 | 126 | "('emailHost', '${host}')" |
125 | 127 | "('emailPort', '${toString port}')" |
126 | 128 | "('emailLocal', '${if local then "1" else "0"}')" |
|
129 | 131 | # Note the leading + on the first command. The passwordFile could be |
130 | 132 | # anywhere in the file system, so it has to be copied as root and |
131 | 133 | # permissions fixed to be accessible by the service. |
132 | | - "+${pkgs.coreutils}/bin/install -m 0640 -g keys ${passwordFile} %S/attestation/emailPassword" |
133 | 134 | ''${pkgs.sqlite}/bin/sqlite3 %S/attestation/attestation.db "CREATE TABLE IF NOT EXISTS Configuration (key TEXT PRIMARY KEY NOT NULL, value NOT NULL)"'' |
134 | 135 | ''${pkgs.sqlite}/bin/sqlite3 %S/attestation/attestation.db "INSERT OR REPLACE INTO Configuration VALUES ${values}"'' |
135 | | - "${pkgs.coreutils}/bin/rm -f %S/attestation/emailPassword" |
136 | 136 | ]; |
137 | | - SupplementaryGroups = [ "keys" ]; |
138 | 137 |
|
139 | 138 | # When sending TERM, e.g. for restart, AttestationServer fails with |
140 | 139 | # this exit code. |
|
0 commit comments