@@ -21,9 +21,11 @@ in
2121 (mkRenamedOptionModule [ "networking" "defaultMailServer" "useTLS" ] [ "services" "ssmtp" "useTLS" ])
2222 (mkRenamedOptionModule [ "networking" "defaultMailServer" "useSTARTTLS" ] [ "services" "ssmtp" "useSTARTTLS" ])
2323 (mkRenamedOptionModule [ "networking" "defaultMailServer" "authUser" ] [ "services" "ssmtp" "authUser" ])
24− (mkRenamedOptionModule [ "networking" "defaultMailServer" "authPass" ] [ "services" "ssmtp" "authPass" ])
2524 (mkRenamedOptionModule [ "networking" "defaultMailServer" "authPassFile" ] [ "services" "ssmtp" "authPassFile" ])
2625 (mkRenamedOptionModule [ "networking" "defaultMailServer" "setSendmail" ] [ "services" "ssmtp" "setSendmail" ])
26+
27+ (mkRemovedOptionModule [ "networking" "defaultMailServer" "authPass" ] "authPass has been removed since it leaks the clear-text password into the world-readable store. Use authPassFile instead and make sure it's not a store path")
28+ (mkRemovedOptionModule [ "services" "ssmtp" "authPass" ] "authPass has been removed since it leaks the clear-text password into the world-readable store. Use authPassFile instead and make sure it's not a store path")
2729 ];
2830
2931 options = {
@@ -45,6 +47,21 @@ in
4547 '';
4648 };
4749
50+ settings = mkOption {
51+ type = with types; attrsOf (oneOf [ bool str ]);
52+ default = {};
53+ description = ''
54+ <citerefentry><refentrytitle>ssmtp</refentrytitle><manvolnum>5</manvolnum></citerefentry> configuration. Refer
55+ to <link xlink:href="https://linux.die.net/man/5/ssmtp.conf"/> for details on supported values.
56+ '';
57+ example = literalExample ''
58+ {
59+ Debug = true;
60+ FromLineOverride = false;
61+ }
62+ '';
63+ };
64+
4865 hostName = mkOption {
4966 type = types.str;
5067 example = "mail.example.org";
@@ -101,18 +118,6 @@ in
101118 '';
102119 };
103120
104− authPass = mkOption {
105− type = types.str;
106− default = "";
107− example = "correctHorseBatteryStaple";
108− description = ''
109− Password used for SMTP auth. (STORED PLAIN TEXT, WORLD-READABLE IN NIX STORE)
110−
111− It's recommended to use <option>authPassFile</option>
112− which takes precedence over <option>authPass</option>.
113− '';
114− };
115−
116121 authPassFile = mkOption {
117122 type = types.nullOr types.str;
118123 default = null;
@@ -121,11 +126,6 @@ in
121126 Path to a file that contains the password used for SMTP auth. The file
122127 should not contain a trailing newline, if the password does not contain one.
123128 This file should be readable by the users that need to execute ssmtp.
124−
125− <option>authPassFile</option> takes precedence over <option>authPass</option>.
126−
127− Warning: when <option>authPass</option> is non-empty <option>authPassFile</option>
128− defaults to a file in the WORLD-READABLE Nix store containing that password.
129129 '';
130130 };
131131
@@ -142,25 +142,28 @@ in
142142
143143 config = mkIf cfg.enable {
144144
145− services.ssmtp.authPassFile = mkIf (cfg.authPass != "")
146− (mkDefault (toString (pkgs.writeTextFile {
147− name = "ssmtp-authpass";
148− text = cfg.authPass;
149− })));
150−
151− environment.etc."ssmtp/ssmtp.conf".text =
152− let yesNo = yes : if yes then "YES" else "NO"; in
153− ''
154− MailHub=${cfg.hostName}
155− FromLineOverride=YES
156− ${optionalString (cfg.root != "") "root=${cfg.root}"}
157− ${optionalString (cfg.domain != "") "rewriteDomain=${cfg.domain}"}
158− UseTLS=${yesNo cfg.useTLS}
159− UseSTARTTLS=${yesNo cfg.useSTARTTLS}
160− #Debug=YES
161− ${optionalString (cfg.authUser != "") "AuthUser=${cfg.authUser}"}
162− ${optionalString (cfg.authPassFile != null) "AuthPassFile=${cfg.authPassFile}"}
163− '';
145+ services.ssmtp.settings = mkMerge [
146+ ({
147+ MailHub = cfg.hostName;
148+ FromLineOverride = mkDefault true;
149+ UseTLS = cfg.useTLS;
150+ UseSTARTTLS = cfg.useSTARTTLS;
151+ })
152+ (mkIf (cfg.root != "") { root = cfg.root; })
153+ (mkIf (cfg.domain != "") { rewriteDomain = cfg.domain; })
154+ (mkIf (cfg.authUser != "") { AuthUser = cfg.authUser; })
155+ (mkIf (cfg.authPassFile != null) { AuthPassFile = cfg.authPassFile; })
156+ ];
157+
158+ environment.etc."ssmtp/ssmtp.conf".source =
159+ let
160+ toStr = value:
161+ if value == true then "YES"
162+ else if value == false then "NO"
163+ else builtins.toString value
164+ ;
165+ in
166+ pkgs.writeText "ssmtp.conf" (concatStringsSep "\n" (mapAttrsToList (key: value: "${key}=${toStr value}") cfg.settings));
164167
165168 environment.systemPackages = [pkgs.ssmtp];
166169