2015-02-18 18:55:07 +00:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
let
|
|
|
|
inherit (lib) mkIf mkOption singleton types;
|
2018-09-16 13:19:29 +00:00
|
|
|
inherit (pkgs) coreutils;
|
2015-02-18 18:55:07 +00:00
|
|
|
cfg = config.services.exim;
|
|
|
|
in
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
###### interface
|
|
|
|
|
|
|
|
options = {
|
|
|
|
|
|
|
|
services.exim = {
|
|
|
|
|
|
|
|
enable = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
|
|
|
description = "Whether to enable the Exim mail transfer agent.";
|
|
|
|
};
|
|
|
|
|
|
|
|
config = mkOption {
|
2019-08-08 20:48:27 +00:00
|
|
|
type = types.lines;
|
2015-02-18 18:55:07 +00:00
|
|
|
default = "";
|
|
|
|
description = ''
|
|
|
|
Verbatim Exim configuration. This should not contain exim_user,
|
|
|
|
exim_group, exim_path, or spool_directory.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
user = mkOption {
|
2019-08-08 20:48:27 +00:00
|
|
|
type = types.str;
|
2015-02-18 18:55:07 +00:00
|
|
|
default = "exim";
|
|
|
|
description = ''
|
|
|
|
User to use when no root privileges are required.
|
|
|
|
In particular, this applies when receiving messages and when doing
|
|
|
|
remote deliveries. (Local deliveries run as various non-root users,
|
|
|
|
typically as the owner of a local mailbox.) Specifying this value
|
|
|
|
as root is not supported.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
group = mkOption {
|
2019-08-08 20:48:27 +00:00
|
|
|
type = types.str;
|
2015-02-18 18:55:07 +00:00
|
|
|
default = "exim";
|
|
|
|
description = ''
|
|
|
|
Group to use when no root privileges are required.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
spoolDir = mkOption {
|
2019-08-08 20:48:27 +00:00
|
|
|
type = types.path;
|
2015-02-18 18:55:07 +00:00
|
|
|
default = "/var/spool/exim";
|
|
|
|
description = ''
|
|
|
|
Location of the spool directory of exim.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2018-09-16 13:19:29 +00:00
|
|
|
package = mkOption {
|
|
|
|
type = types.package;
|
|
|
|
default = pkgs.exim;
|
|
|
|
defaultText = "pkgs.exim";
|
|
|
|
description = ''
|
|
|
|
The Exim derivation to use.
|
|
|
|
This can be used to enable features such as LDAP or PAM support.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2015-02-18 18:55:07 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
###### implementation
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
|
|
|
|
|
|
|
environment = {
|
|
|
|
etc."exim.conf".text = ''
|
|
|
|
exim_user = ${cfg.user}
|
|
|
|
exim_group = ${cfg.group}
|
2017-01-29 10:11:01 +00:00
|
|
|
exim_path = /run/wrappers/bin/exim
|
2015-02-18 18:55:07 +00:00
|
|
|
spool_directory = ${cfg.spoolDir}
|
|
|
|
${cfg.config}
|
|
|
|
'';
|
2018-09-16 13:19:29 +00:00
|
|
|
systemPackages = [ cfg.package ];
|
2015-02-18 18:55:07 +00:00
|
|
|
};
|
|
|
|
|
2019-09-14 17:51:29 +00:00
|
|
|
users.users.${cfg.user} = {
|
2015-02-18 18:55:07 +00:00
|
|
|
description = "Exim mail transfer agent user";
|
|
|
|
uid = config.ids.uids.exim;
|
|
|
|
group = cfg.group;
|
|
|
|
};
|
|
|
|
|
2019-09-14 17:51:29 +00:00
|
|
|
users.groups.${cfg.group} = {
|
2015-02-18 18:55:07 +00:00
|
|
|
gid = config.ids.gids.exim;
|
|
|
|
};
|
|
|
|
|
2018-09-16 13:19:29 +00:00
|
|
|
security.wrappers.exim.source = "${cfg.package}/bin/exim";
|
2015-02-18 18:55:07 +00:00
|
|
|
|
|
|
|
systemd.services.exim = {
|
|
|
|
description = "Exim Mail Daemon";
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
2018-06-03 19:22:55 +00:00
|
|
|
restartTriggers = [ config.environment.etc."exim.conf".source ];
|
2015-02-18 18:55:07 +00:00
|
|
|
serviceConfig = {
|
2018-09-16 13:19:29 +00:00
|
|
|
ExecStart = "${cfg.package}/bin/exim -bdf -q30m";
|
2015-02-18 18:55:07 +00:00
|
|
|
ExecReload = "${coreutils}/bin/kill -HUP $MAINPID";
|
|
|
|
};
|
|
|
|
preStart = ''
|
|
|
|
if ! test -d ${cfg.spoolDir}; then
|
|
|
|
${coreutils}/bin/mkdir -p ${cfg.spoolDir}
|
|
|
|
${coreutils}/bin/chown ${cfg.user}:${cfg.group} ${cfg.spoolDir}
|
|
|
|
fi
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|