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
|
2020-10-22 16:34:21 +00:00
|
|
|
# directly to an SMTP server defined in its configuration file, without
|
2009-05-27 23:59:14 +00:00
|
|
|
# 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
|
2019-11-24 15:38:52 +00:00
|
|
|
cfg = config.services.ssmtp;
|
2013-09-04 11:05:09 +00:00
|
|
|
|
|
|
|
in
|
|
|
|
{
|
|
|
|
|
2019-12-10 01:51:19 +00:00
|
|
|
imports = [
|
2020-03-22 14:27:24 +00:00
|
|
|
(mkRenamedOptionModule [ "networking" "defaultMailServer" "directDelivery" ] [ "services" "ssmtp" "enable" ])
|
|
|
|
(mkRenamedOptionModule [ "networking" "defaultMailServer" "hostName" ] [ "services" "ssmtp" "hostName" ])
|
|
|
|
(mkRenamedOptionModule [ "networking" "defaultMailServer" "domain" ] [ "services" "ssmtp" "domain" ])
|
|
|
|
(mkRenamedOptionModule [ "networking" "defaultMailServer" "root" ] [ "services" "ssmtp" "root" ])
|
|
|
|
(mkRenamedOptionModule [ "networking" "defaultMailServer" "useTLS" ] [ "services" "ssmtp" "useTLS" ])
|
|
|
|
(mkRenamedOptionModule [ "networking" "defaultMailServer" "useSTARTTLS" ] [ "services" "ssmtp" "useSTARTTLS" ])
|
|
|
|
(mkRenamedOptionModule [ "networking" "defaultMailServer" "authUser" ] [ "services" "ssmtp" "authUser" ])
|
|
|
|
(mkRenamedOptionModule [ "networking" "defaultMailServer" "authPassFile" ] [ "services" "ssmtp" "authPassFile" ])
|
|
|
|
(mkRenamedOptionModule [ "networking" "defaultMailServer" "setSendmail" ] [ "services" "ssmtp" "setSendmail" ])
|
2020-06-06 15:02:23 +00:00
|
|
|
|
|
|
|
(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")
|
|
|
|
(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")
|
2019-12-10 01:51:19 +00:00
|
|
|
];
|
|
|
|
|
2009-05-27 23:59:14 +00:00
|
|
|
options = {
|
|
|
|
|
2019-11-24 15:38:52 +00:00
|
|
|
services.ssmtp = {
|
2009-05-27 23:59:14 +00:00
|
|
|
|
2019-11-24 15:38:52 +00:00
|
|
|
enable = mkOption {
|
2014-11-04 23:42:12 +00:00
|
|
|
type = types.bool;
|
2009-05-27 23:59:14 +00:00
|
|
|
default = false;
|
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
|
2019-11-24 15:38:52 +00:00
|
|
|
<option>services.ssmtp.hostName</option> to the
|
2009-05-27 23:59:14 +00:00
|
|
|
host name of your preferred mail server.
|
2013-09-04 11:05:09 +00:00
|
|
|
'';
|
2009-05-27 23:59:14 +00:00
|
|
|
};
|
|
|
|
|
2020-06-06 14:58:44 +00:00
|
|
|
settings = mkOption {
|
|
|
|
type = with types; attrsOf (oneOf [ bool str ]);
|
|
|
|
default = {};
|
|
|
|
description = ''
|
|
|
|
<citerefentry><refentrytitle>ssmtp</refentrytitle><manvolnum>5</manvolnum></citerefentry> configuration. Refer
|
|
|
|
to <link xlink:href="https://linux.die.net/man/5/ssmtp.conf"/> for details on supported values.
|
|
|
|
'';
|
|
|
|
example = literalExample ''
|
|
|
|
{
|
|
|
|
Debug = true;
|
|
|
|
FromLineOverride = false;
|
|
|
|
}
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
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
|
2017-04-08 15:12:59 +00: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 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;
|
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;
|
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
|
|
|
};
|
|
|
|
|
2017-03-25 01:46:51 +00:00
|
|
|
authPassFile = mkOption {
|
|
|
|
type = types.nullOr types.str;
|
|
|
|
default = null;
|
|
|
|
example = "/run/keys/ssmtp-authpass";
|
|
|
|
description = ''
|
2017-04-08 15:12:59 +00: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 01:46:51 +00:00
|
|
|
This file should be readable by the users that need to execute ssmtp.
|
2013-09-04 11:05:09 +00:00
|
|
|
'';
|
2013-04-16 15:37:36 +00:00
|
|
|
};
|
2017-03-25 01:46:51 +00:00
|
|
|
|
2016-07-23 16:00:10 +00:00
|
|
|
setSendmail = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = true;
|
|
|
|
description = "Whether to set the system sendmail to ssmtp's.";
|
|
|
|
};
|
2013-04-16 15:01:35 +00:00
|
|
|
|
2009-05-27 23:59:14 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2019-11-24 15:38:52 +00:00
|
|
|
config = mkIf cfg.enable {
|
2009-05-27 23:59:14 +00:00
|
|
|
|
2020-11-09 03:35:12 +00:00
|
|
|
assertions = [
|
|
|
|
{
|
|
|
|
assertion = cfg.useSTARTTLS -> cfg.useTLS;
|
|
|
|
message = "services.ssmtp.useSTARTTLS has no effect without services.ssmtp.useTLS";
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
2020-06-06 14:58:44 +00:00
|
|
|
services.ssmtp.settings = mkMerge [
|
|
|
|
({
|
|
|
|
MailHub = cfg.hostName;
|
|
|
|
FromLineOverride = mkDefault true;
|
|
|
|
UseTLS = cfg.useTLS;
|
|
|
|
UseSTARTTLS = cfg.useSTARTTLS;
|
|
|
|
})
|
|
|
|
(mkIf (cfg.root != "") { root = cfg.root; })
|
|
|
|
(mkIf (cfg.domain != "") { rewriteDomain = cfg.domain; })
|
|
|
|
(mkIf (cfg.authUser != "") { AuthUser = cfg.authUser; })
|
|
|
|
(mkIf (cfg.authPassFile != null) { AuthPassFile = cfg.authPassFile; })
|
|
|
|
];
|
|
|
|
|
|
|
|
environment.etc."ssmtp/ssmtp.conf".source =
|
|
|
|
let
|
|
|
|
toStr = value:
|
|
|
|
if value == true then "YES"
|
|
|
|
else if value == false then "NO"
|
|
|
|
else builtins.toString value
|
|
|
|
;
|
|
|
|
in
|
|
|
|
pkgs.writeText "ssmtp.conf" (concatStringsSep "\n" (mapAttrsToList (key: value: "${key}=${toStr value}") cfg.settings));
|
2013-09-04 11:05:09 +00:00
|
|
|
|
|
|
|
environment.systemPackages = [pkgs.ssmtp];
|
2017-03-25 01:46:51 +00:00
|
|
|
|
2016-07-23 18:58:58 +00:00
|
|
|
services.mail.sendmailSetuidWrapper = mkIf cfg.setSendmail {
|
2016-07-23 16:00:10 +00:00
|
|
|
program = "sendmail";
|
|
|
|
source = "${pkgs.ssmtp}/bin/sendmail";
|
|
|
|
setuid = false;
|
|
|
|
setgid = false;
|
|
|
|
};
|
2013-09-04 11:05:09 +00:00
|
|
|
|
|
|
|
};
|
2009-05-27 23:59:14 +00:00
|
|
|
|
|
|
|
}
|