2020-04-24 23:36:52 +00:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
let
|
2021-10-06 13:57:05 +00:00
|
|
|
inherit (lib) literalExpression mkIf mkOption singleton types;
|
2020-04-24 23:36:52 +00:00
|
|
|
inherit (pkgs) coreutils;
|
|
|
|
cfg = config.services.exim;
|
|
|
|
in
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
###### interface
|
|
|
|
|
|
|
|
options = {
|
|
|
|
|
|
|
|
services.exim = {
|
|
|
|
|
|
|
|
enable = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "Whether to enable the Exim mail transfer agent.";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
config = mkOption {
|
|
|
|
type = types.lines;
|
|
|
|
default = "";
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc ''
|
2020-04-24 23:36:52 +00:00
|
|
|
Verbatim Exim configuration. This should not contain exim_user,
|
|
|
|
exim_group, exim_path, or spool_directory.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
user = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "exim";
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc ''
|
2020-04-24 23:36:52 +00:00
|
|
|
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 {
|
|
|
|
type = types.str;
|
|
|
|
default = "exim";
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc ''
|
2020-04-24 23:36:52 +00:00
|
|
|
Group to use when no root privileges are required.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
spoolDir = mkOption {
|
|
|
|
type = types.path;
|
|
|
|
default = "/var/spool/exim";
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc ''
|
2020-04-24 23:36:52 +00:00
|
|
|
Location of the spool directory of exim.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
package = mkOption {
|
|
|
|
type = types.package;
|
|
|
|
default = pkgs.exim;
|
2021-10-06 13:57:05 +00:00
|
|
|
defaultText = literalExpression "pkgs.exim";
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc ''
|
2020-04-24 23:36:52 +00:00
|
|
|
The Exim derivation to use.
|
|
|
|
This can be used to enable features such as LDAP or PAM support.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2021-04-26 19:14:03 +00:00
|
|
|
queueRunnerInterval = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "5m";
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc ''
|
2021-04-26 19:14:03 +00:00
|
|
|
How often to spawn a new queue runner.
|
|
|
|
'';
|
|
|
|
};
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
###### implementation
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
|
|
|
|
|
|
|
environment = {
|
|
|
|
etc."exim.conf".text = ''
|
|
|
|
exim_user = ${cfg.user}
|
|
|
|
exim_group = ${cfg.group}
|
|
|
|
exim_path = /run/wrappers/bin/exim
|
|
|
|
spool_directory = ${cfg.spoolDir}
|
|
|
|
${cfg.config}
|
|
|
|
'';
|
|
|
|
systemPackages = [ cfg.package ];
|
|
|
|
};
|
|
|
|
|
|
|
|
users.users.${cfg.user} = {
|
|
|
|
description = "Exim mail transfer agent user";
|
|
|
|
uid = config.ids.uids.exim;
|
|
|
|
group = cfg.group;
|
|
|
|
};
|
|
|
|
|
|
|
|
users.groups.${cfg.group} = {
|
|
|
|
gid = config.ids.gids.exim;
|
|
|
|
};
|
|
|
|
|
2021-09-22 15:38:15 +00:00
|
|
|
security.wrappers.exim =
|
|
|
|
{ setuid = true;
|
|
|
|
owner = "root";
|
|
|
|
group = "root";
|
|
|
|
source = "${cfg.package}/bin/exim";
|
|
|
|
};
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
systemd.services.exim = {
|
|
|
|
description = "Exim Mail Daemon";
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
restartTriggers = [ config.environment.etc."exim.conf".source ];
|
|
|
|
serviceConfig = {
|
2022-12-28 21:21:41 +00:00
|
|
|
ExecStart = "+${cfg.package}/bin/exim -bdf -q${cfg.queueRunnerInterval}";
|
|
|
|
ExecReload = "+${coreutils}/bin/kill -HUP $MAINPID";
|
|
|
|
User = cfg.user;
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
preStart = ''
|
|
|
|
if ! test -d ${cfg.spoolDir}; then
|
|
|
|
${coreutils}/bin/mkdir -p ${cfg.spoolDir}
|
|
|
|
${coreutils}/bin/chown ${cfg.user}:${cfg.group} ${cfg.spoolDir}
|
|
|
|
fi
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|