1# Configuration for `ssmtp', a trivial mail transfer agent that can 2# replace sendmail/postfix on simple systems. It delivers email 3# directly to an SMTP server defined in its configuration file, wihout 4# queueing mail locally. 5 6{ config, lib, pkgs, ... }: 7 8with lib; 9 10let 11 12 cfg = config.networking.defaultMailServer; 13 14in 15 16{ 17 18 options = { 19 20 networking.defaultMailServer = { 21 22 directDelivery = mkOption { 23 type = types.bool; 24 default = false; 25 example = true; 26 description = '' 27 Use the trivial Mail Transfer Agent (MTA) 28 <command>ssmtp</command> package to allow programs to send 29 e-mail. If you don't want to run a real MTA like 30 <command>sendmail</command> or <command>postfix</command> on 31 your machine, set this option to <literal>true</literal>, and 32 set the option 33 <option>networking.defaultMailServer.hostName</option> to the 34 host name of your preferred mail server. 35 ''; 36 }; 37 38 hostName = mkOption { 39 type = types.str; 40 example = "mail.example.org"; 41 description = '' 42 The host name of the default mail server to use to deliver 43 e-mail. 44 ''; 45 }; 46 47 root = mkOption { 48 type = types.str; 49 default = ""; 50 example = "root@example.org"; 51 description = '' 52 The e-mail to which mail for users with UID &lt; 1000 is forwarded. 53 ''; 54 }; 55 56 domain = mkOption { 57 type = types.str; 58 default = ""; 59 example = "example.org"; 60 description = '' 61 The domain from which mail will appear to be sent. 62 ''; 63 }; 64 65 useTLS = mkOption { 66 type = types.bool; 67 default = false; 68 example = true; 69 description = '' 70 Whether TLS should be used to connect to the default mail 71 server. 72 ''; 73 }; 74 75 useSTARTTLS = mkOption { 76 type = types.bool; 77 default = false; 78 example = true; 79 description = '' 80 Whether the STARTTLS should be used to connect to the default 81 mail server. (This is needed for TLS-capable mail servers 82 running on the default SMTP port 25.) 83 ''; 84 }; 85 86 authUser = mkOption { 87 type = types.str; 88 default = ""; 89 example = "foo@example.org"; 90 description = '' 91 Username used for SMTP auth. Leave blank to disable. 92 ''; 93 }; 94 95 authPass = mkOption { 96 type = types.str; 97 default = ""; 98 example = "correctHorseBatteryStaple"; 99 description = '' 100 Password used for SMTP auth. (STORED PLAIN TEXT, WORLD-READABLE IN NIX STORE) 101 ''; 102 }; 103 104 }; 105 106 }; 107 108 109 config = mkIf cfg.directDelivery { 110 111 environment.etc."ssmtp/ssmtp.conf".text = 112 '' 113 MailHub=${cfg.hostName} 114 FromLineOverride=YES 115 ${if cfg.root != "" then "root=${cfg.root}" else ""} 116 ${if cfg.domain != "" then "rewriteDomain=${cfg.domain}" else ""} 117 UseTLS=${if cfg.useTLS then "YES" else "NO"} 118 UseSTARTTLS=${if cfg.useSTARTTLS then "YES" else "NO"} 119 #Debug=YES 120 ${if cfg.authUser != "" then "AuthUser=${cfg.authUser}" else ""} 121 ${if cfg.authPass != "" then "AuthPass=${cfg.authPass}" else ""} 122 ''; 123 124 environment.systemPackages = [pkgs.ssmtp]; 125 126 }; 127 128}