2009-05-27 23:59:14 +00: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 14:26:48 +00:00
|
|
|
{ config, lib, pkgs, ... }:
|
2009-05-27 23:59:14 +00:00
|
|
|
|
2014-04-14 14:26:48 +00:00
|
|
|
with lib;
|
2009-05-27 23:59:14 +00:00
|
|
|
|
|
|
|
let
|
|
|
|
|
2013-09-04 11:05:09 +00:00
|
|
|
cfg = config.networking.defaultMailServer;
|
|
|
|
|
|
|
|
in
|
|
|
|
|
|
|
|
{
|
|
|
|
|
2009-05-27 23:59:14 +00:00
|
|
|
options = {
|
|
|
|
|
|
|
|
networking.defaultMailServer = {
|
|
|
|
|
|
|
|
directDelivery = mkOption {
|
2014-11-04 23:42:12 +00:00
|
|
|
type = types.bool;
|
2009-05-27 23:59:14 +00:00
|
|
|
default = false;
|
|
|
|
example = true;
|
2013-09-04 11:05:09 +00:00
|
|
|
description = ''
|
2009-05-27 23:59:14 +00:00
|
|
|
Use the trivial Mail Transfer Agent (MTA)
|
|
|
|
<command>ssmtp</command> package to allow programs to send
|
2013-09-04 11:05:09 +00:00
|
|
|
e-mail. If you don't want to run a “real” MTA like
|
2009-05-27 23:59:14 +00: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 11:05:09 +00:00
|
|
|
'';
|
2009-05-27 23:59:14 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
hostName = mkOption {
|
2014-11-04 23:42:12 +00:00
|
|
|
type = types.str;
|
2009-05-27 23:59:14 +00:00
|
|
|
example = "mail.example.org";
|
2013-09-04 11:05:09 +00:00
|
|
|
description = ''
|
2009-05-27 23:59:14 +00:00
|
|
|
The host name of the default mail server to use to deliver
|
|
|
|
e-mail.
|
2013-09-04 11:05:09 +00:00
|
|
|
'';
|
2009-05-27 23:59:14 +00:00
|
|
|
};
|
|
|
|
|
2014-11-04 23:42:23 +00: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-27 23:59:14 +00:00
|
|
|
domain = mkOption {
|
2014-11-04 23:42:12 +00:00
|
|
|
type = types.str;
|
2009-05-27 23:59:14 +00:00
|
|
|
default = "";
|
|
|
|
example = "example.org";
|
2013-09-04 11:05:09 +00:00
|
|
|
description = ''
|
2009-05-27 23:59:14 +00:00
|
|
|
The domain from which mail will appear to be sent.
|
2013-09-04 11:05:09 +00:00
|
|
|
'';
|
2009-05-27 23:59:14 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
useTLS = mkOption {
|
2014-11-04 23:42:12 +00:00
|
|
|
type = types.bool;
|
2009-05-27 23:59:14 +00:00
|
|
|
default = false;
|
|
|
|
example = true;
|
2013-09-04 11:05:09 +00:00
|
|
|
description = ''
|
2009-05-27 23:59:14 +00:00
|
|
|
Whether TLS should be used to connect to the default mail
|
|
|
|
server.
|
2013-09-04 11:05:09 +00:00
|
|
|
'';
|
2009-05-27 23:59:14 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
useSTARTTLS = mkOption {
|
2014-11-04 23:42:12 +00:00
|
|
|
type = types.bool;
|
2009-05-27 23:59:14 +00:00
|
|
|
default = false;
|
|
|
|
example = true;
|
2013-09-04 11:05:09 +00:00
|
|
|
description = ''
|
2009-05-27 23:59:14 +00: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 11:05:09 +00:00
|
|
|
'';
|
2009-05-27 23:59:14 +00:00
|
|
|
};
|
|
|
|
|
2013-04-16 15:01:35 +00:00
|
|
|
authUser = mkOption {
|
2014-11-04 23:42:12 +00:00
|
|
|
type = types.str;
|
2013-04-16 15:01:35 +00:00
|
|
|
default = "";
|
|
|
|
example = "foo@example.org";
|
2013-09-04 11:05:09 +00:00
|
|
|
description = ''
|
2013-04-16 15:01:35 +00:00
|
|
|
Username used for SMTP auth. Leave blank to disable.
|
2013-09-04 11:05:09 +00:00
|
|
|
'';
|
2013-04-16 15:01:35 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
authPass = mkOption {
|
2014-11-04 23:42:12 +00:00
|
|
|
type = types.str;
|
2013-04-16 15:01:35 +00:00
|
|
|
default = "";
|
|
|
|
example = "correctHorseBatteryStaple";
|
2013-09-04 11:05:09 +00:00
|
|
|
description = ''
|
2013-07-02 04:03:52 +00:00
|
|
|
Password used for SMTP auth. (STORED PLAIN TEXT, WORLD-READABLE IN NIX STORE)
|
2013-09-04 11:05:09 +00:00
|
|
|
'';
|
2013-04-16 15:37:36 +00:00
|
|
|
};
|
2013-04-16 15:01:35 +00:00
|
|
|
|
2009-05-27 23:59:14 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2013-09-04 11:05:09 +00:00
|
|
|
config = mkIf cfg.directDelivery {
|
2009-05-27 23:59:14 +00:00
|
|
|
|
2013-09-04 11:05:09 +00:00
|
|
|
environment.etc."ssmtp/ssmtp.conf".text =
|
|
|
|
''
|
|
|
|
MailHub=${cfg.hostName}
|
|
|
|
FromLineOverride=YES
|
2014-11-04 23:42:23 +00:00
|
|
|
${if cfg.root != "" then "root=${cfg.root}" else ""}
|
2013-09-04 11:05:09 +00:00
|
|
|
${if cfg.domain != "" then "rewriteDomain=${cfg.domain}" else ""}
|
|
|
|
UseTLS=${if cfg.useTLS then "YES" else "NO"}
|
|
|
|
UseSTARTTLS=${if cfg.useSTARTTLS then "YES" else "NO"}
|
|
|
|
#Debug=YES
|
|
|
|
${if cfg.authUser != "" then "AuthUser=${cfg.authUser}" else ""}
|
|
|
|
${if cfg.authPass != "" then "AuthPass=${cfg.authPass}" else ""}
|
|
|
|
'';
|
|
|
|
|
|
|
|
environment.systemPackages = [pkgs.ssmtp];
|
|
|
|
|
|
|
|
};
|
2009-05-27 23:59:14 +00:00
|
|
|
|
|
|
|
}
|