2009-05-28 03:59:14 +04:00
|
|
|
# Configuration for `ssmtp', a trivial mail transfer agent that can
|
|
|
|
# replace sendmail/postfix on simple systems. It delivers email
|
|
|
|
# directly to an SMTP server defined in its configuration file, wihout
|
|
|
|
# queueing mail locally.
|
|
|
|
|
2014-04-14 18:26:48 +04:00
|
|
|
{ config, lib, pkgs, ... }:
|
2009-05-28 03:59:14 +04:00
|
|
|
|
2014-04-14 18:26:48 +04:00
|
|
|
with lib;
|
2009-05-28 03:59:14 +04:00
|
|
|
|
|
|
|
let
|
|
|
|
|
2013-09-04 15:05:09 +04:00
|
|
|
cfg = config.networking.defaultMailServer;
|
|
|
|
|
|
|
|
in
|
|
|
|
|
|
|
|
{
|
|
|
|
|
2009-05-28 03:59:14 +04:00
|
|
|
options = {
|
|
|
|
|
|
|
|
networking.defaultMailServer = {
|
|
|
|
|
|
|
|
directDelivery = mkOption {
|
2014-11-05 02:42:12 +03:00
|
|
|
type = types.bool;
|
2009-05-28 03:59:14 +04:00
|
|
|
default = false;
|
2013-09-04 15:05:09 +04:00
|
|
|
description = ''
|
2009-05-28 03:59:14 +04:00
|
|
|
Use the trivial Mail Transfer Agent (MTA)
|
|
|
|
<command>ssmtp</command> package to allow programs to send
|
2013-09-04 15:05:09 +04:00
|
|
|
e-mail. If you don't want to run a “real” MTA like
|
2009-05-28 03:59:14 +04:00
|
|
|
<command>sendmail</command> or <command>postfix</command> on
|
|
|
|
your machine, set this option to <literal>true</literal>, and
|
|
|
|
set the option
|
|
|
|
<option>networking.defaultMailServer.hostName</option> to the
|
|
|
|
host name of your preferred mail server.
|
2013-09-04 15:05:09 +04:00
|
|
|
'';
|
2009-05-28 03:59:14 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
hostName = mkOption {
|
2014-11-05 02:42:12 +03:00
|
|
|
type = types.str;
|
2009-05-28 03:59:14 +04:00
|
|
|
example = "mail.example.org";
|
2013-09-04 15:05:09 +04:00
|
|
|
description = ''
|
2009-05-28 03:59:14 +04:00
|
|
|
The host name of the default mail server to use to deliver
|
2017-04-08 18:12:59 +03:00
|
|
|
e-mail. Can also contain a port number (ex: mail.example.org:587),
|
|
|
|
defaults to port 25 if no port is given.
|
2013-09-04 15:05:09 +04:00
|
|
|
'';
|
2009-05-28 03:59:14 +04:00
|
|
|
};
|
|
|
|
|
2014-11-05 02:42:23 +03:00
|
|
|
root = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "";
|
|
|
|
example = "root@example.org";
|
|
|
|
description = ''
|
|
|
|
The e-mail to which mail for users with UID < 1000 is forwarded.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2009-05-28 03:59:14 +04:00
|
|
|
domain = mkOption {
|
2014-11-05 02:42:12 +03:00
|
|
|
type = types.str;
|
2009-05-28 03:59:14 +04:00
|
|
|
default = "";
|
|
|
|
example = "example.org";
|
2013-09-04 15:05:09 +04:00
|
|
|
description = ''
|
2009-05-28 03:59:14 +04:00
|
|
|
The domain from which mail will appear to be sent.
|
2013-09-04 15:05:09 +04:00
|
|
|
'';
|
2009-05-28 03:59:14 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
useTLS = mkOption {
|
2014-11-05 02:42:12 +03:00
|
|
|
type = types.bool;
|
2009-05-28 03:59:14 +04:00
|
|
|
default = false;
|
2013-09-04 15:05:09 +04:00
|
|
|
description = ''
|
2009-05-28 03:59:14 +04:00
|
|
|
Whether TLS should be used to connect to the default mail
|
|
|
|
server.
|
2013-09-04 15:05:09 +04:00
|
|
|
'';
|
2009-05-28 03:59:14 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
useSTARTTLS = mkOption {
|
2014-11-05 02:42:12 +03:00
|
|
|
type = types.bool;
|
2009-05-28 03:59:14 +04:00
|
|
|
default = false;
|
2013-09-04 15:05:09 +04:00
|
|
|
description = ''
|
2009-05-28 03:59:14 +04:00
|
|
|
Whether the STARTTLS should be used to connect to the default
|
|
|
|
mail server. (This is needed for TLS-capable mail servers
|
|
|
|
running on the default SMTP port 25.)
|
2013-09-04 15:05:09 +04:00
|
|
|
'';
|
2009-05-28 03:59:14 +04:00
|
|
|
};
|
|
|
|
|
2013-04-16 19:01:35 +04:00
|
|
|
authUser = mkOption {
|
2014-11-05 02:42:12 +03:00
|
|
|
type = types.str;
|
2013-04-16 19:01:35 +04:00
|
|
|
default = "";
|
|
|
|
example = "foo@example.org";
|
2013-09-04 15:05:09 +04:00
|
|
|
description = ''
|
2013-04-16 19:01:35 +04:00
|
|
|
Username used for SMTP auth. Leave blank to disable.
|
2013-09-04 15:05:09 +04:00
|
|
|
'';
|
2013-04-16 19:01:35 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
authPass = mkOption {
|
2014-11-05 02:42:12 +03:00
|
|
|
type = types.str;
|
2013-04-16 19:01:35 +04:00
|
|
|
default = "";
|
|
|
|
example = "correctHorseBatteryStaple";
|
2013-09-04 15:05:09 +04:00
|
|
|
description = ''
|
2013-07-02 08:03:52 +04:00
|
|
|
Password used for SMTP auth. (STORED PLAIN TEXT, WORLD-READABLE IN NIX STORE)
|
2017-03-25 04:46:51 +03:00
|
|
|
|
|
|
|
It's recommended to use <option>authPassFile</option>
|
|
|
|
which takes precedence over <option>authPass</option>.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
authPassFile = mkOption {
|
|
|
|
type = types.nullOr types.str;
|
|
|
|
default = null;
|
|
|
|
example = "/run/keys/ssmtp-authpass";
|
|
|
|
description = ''
|
2017-04-08 18:12:59 +03:00
|
|
|
Path to a file that contains the password used for SMTP auth. The file
|
|
|
|
should not contain a trailing newline, if the password does not contain one.
|
2017-03-25 04:46:51 +03:00
|
|
|
This file should be readable by the users that need to execute ssmtp.
|
|
|
|
|
|
|
|
<option>authPassFile</option> takes precedence over <option>authPass</option>.
|
|
|
|
|
|
|
|
Warning: when <option>authPass</option> is non-empty <option>authPassFile</option>
|
|
|
|
defaults to a file in the WORLD-READABLE Nix store containing that password.
|
2013-09-04 15:05:09 +04:00
|
|
|
'';
|
2013-04-16 19:37:36 +04:00
|
|
|
};
|
2017-03-25 04:46:51 +03:00
|
|
|
|
2016-07-23 19:00:10 +03:00
|
|
|
setSendmail = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = true;
|
|
|
|
description = "Whether to set the system sendmail to ssmtp's.";
|
|
|
|
};
|
2013-04-16 19:01:35 +04:00
|
|
|
|
2009-05-28 03:59:14 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2013-09-04 15:05:09 +04:00
|
|
|
config = mkIf cfg.directDelivery {
|
2009-05-28 03:59:14 +04:00
|
|
|
|
2017-03-25 04:46:51 +03:00
|
|
|
networking.defaultMailServer.authPassFile = mkIf (cfg.authPass != "")
|
|
|
|
(mkDefault (toString (pkgs.writeTextFile {
|
|
|
|
name = "ssmtp-authpass";
|
|
|
|
text = cfg.authPass;
|
|
|
|
})));
|
|
|
|
|
2013-09-04 15:05:09 +04:00
|
|
|
environment.etc."ssmtp/ssmtp.conf".text =
|
2017-03-25 04:46:51 +03:00
|
|
|
let yesNo = yes : if yes then "YES" else "NO"; in
|
2013-09-04 15:05:09 +04:00
|
|
|
''
|
|
|
|
MailHub=${cfg.hostName}
|
|
|
|
FromLineOverride=YES
|
2017-03-25 04:46:51 +03:00
|
|
|
${optionalString (cfg.root != "") "root=${cfg.root}"}
|
|
|
|
${optionalString (cfg.domain != "") "rewriteDomain=${cfg.domain}"}
|
|
|
|
UseTLS=${yesNo cfg.useTLS}
|
|
|
|
UseSTARTTLS=${yesNo cfg.useSTARTTLS}
|
2013-09-04 15:05:09 +04:00
|
|
|
#Debug=YES
|
2017-03-25 04:46:51 +03:00
|
|
|
${optionalString (cfg.authUser != "") "AuthUser=${cfg.authUser}"}
|
|
|
|
${optionalString (!isNull cfg.authPassFile) "AuthPassFile=${cfg.authPassFile}"}
|
2013-09-04 15:05:09 +04:00
|
|
|
'';
|
|
|
|
|
|
|
|
environment.systemPackages = [pkgs.ssmtp];
|
2017-03-25 04:46:51 +03:00
|
|
|
|
2016-07-23 21:58:58 +03:00
|
|
|
services.mail.sendmailSetuidWrapper = mkIf cfg.setSendmail {
|
2016-07-23 19:00:10 +03:00
|
|
|
program = "sendmail";
|
|
|
|
source = "${pkgs.ssmtp}/bin/sendmail";
|
|
|
|
setuid = false;
|
|
|
|
setgid = false;
|
|
|
|
};
|
2013-09-04 15:05:09 +04:00
|
|
|
|
|
|
|
};
|
2009-05-28 03:59:14 +04:00
|
|
|
|
|
|
|
}
|