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