2020-04-24 23:36:52 +00:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
|
|
|
|
cfg = config.services.opensmtpd;
|
|
|
|
conf = pkgs.writeText "smtpd.conf" cfg.serverConfiguration;
|
|
|
|
args = concatStringsSep " " cfg.extraServerArgs;
|
|
|
|
|
|
|
|
sendmail = pkgs.runCommand "opensmtpd-sendmail" { preferLocalBuild = true; } ''
|
|
|
|
mkdir -p $out/bin
|
|
|
|
ln -s ${cfg.package}/sbin/smtpctl $out/bin/sendmail
|
|
|
|
'';
|
|
|
|
|
|
|
|
in {
|
|
|
|
|
|
|
|
###### interface
|
|
|
|
|
2020-06-18 07:06:33 +00:00
|
|
|
imports = [
|
|
|
|
(mkRenamedOptionModule [ "services" "opensmtpd" "addSendmailToSystemPath" ] [ "services" "opensmtpd" "setSendmail" ])
|
|
|
|
];
|
|
|
|
|
2020-04-24 23:36:52 +00:00
|
|
|
options = {
|
|
|
|
|
|
|
|
services.opensmtpd = {
|
|
|
|
|
|
|
|
enable = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "Whether to enable the OpenSMTPD server.";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
package = mkOption {
|
|
|
|
type = types.package;
|
|
|
|
default = pkgs.opensmtpd;
|
2021-10-06 13:57:05 +00:00
|
|
|
defaultText = literalExpression "pkgs.opensmtpd";
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "The OpenSMTPD package to use.";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
2020-06-18 07:06:33 +00:00
|
|
|
setSendmail = mkOption {
|
2020-04-24 23:36:52 +00:00
|
|
|
type = types.bool;
|
|
|
|
default = true;
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "Whether to set the system sendmail to OpenSMTPD's.";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
extraServerArgs = mkOption {
|
|
|
|
type = types.listOf types.str;
|
|
|
|
default = [];
|
|
|
|
example = [ "-v" "-P mta" ];
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc ''
|
2020-04-24 23:36:52 +00:00
|
|
|
Extra command line arguments provided when the smtpd process
|
|
|
|
is started.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
serverConfiguration = mkOption {
|
|
|
|
type = types.lines;
|
|
|
|
example = ''
|
|
|
|
listen on lo
|
|
|
|
accept for any deliver to lmtp localhost:24
|
|
|
|
'';
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc ''
|
2020-04-24 23:36:52 +00:00
|
|
|
The contents of the smtpd.conf configuration file. See the
|
|
|
|
OpenSMTPD documentation for syntax information.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
procPackages = mkOption {
|
|
|
|
type = types.listOf types.package;
|
|
|
|
default = [];
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc ''
|
2020-04-24 23:36:52 +00:00
|
|
|
Packages to search for filters, tables, queues, and schedulers.
|
|
|
|
|
|
|
|
Add OpenSMTPD-extras here if you want to use the filters, etc. from
|
|
|
|
that package.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
###### implementation
|
|
|
|
|
2020-06-18 07:06:33 +00:00
|
|
|
config = mkIf cfg.enable rec {
|
2020-04-24 23:36:52 +00:00
|
|
|
users.groups = {
|
|
|
|
smtpd.gid = config.ids.gids.smtpd;
|
|
|
|
smtpq.gid = config.ids.gids.smtpq;
|
|
|
|
};
|
|
|
|
|
|
|
|
users.users = {
|
|
|
|
smtpd = {
|
|
|
|
description = "OpenSMTPD process user";
|
|
|
|
uid = config.ids.uids.smtpd;
|
|
|
|
group = "smtpd";
|
|
|
|
};
|
|
|
|
smtpq = {
|
|
|
|
description = "OpenSMTPD queue user";
|
|
|
|
uid = config.ids.uids.smtpq;
|
|
|
|
group = "smtpq";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2020-06-18 07:06:33 +00:00
|
|
|
security.wrappers.smtpctl = {
|
2021-10-06 13:57:05 +00:00
|
|
|
owner = "root";
|
2020-06-18 07:06:33 +00:00
|
|
|
group = "smtpq";
|
2021-09-22 15:38:15 +00:00
|
|
|
setuid = false;
|
2020-06-18 07:06:33 +00:00
|
|
|
setgid = true;
|
|
|
|
source = "${cfg.package}/bin/smtpctl";
|
|
|
|
};
|
|
|
|
|
2021-09-22 15:38:15 +00:00
|
|
|
services.mail.sendmailSetuidWrapper = mkIf cfg.setSendmail
|
2021-09-23 15:35:13 +00:00
|
|
|
(security.wrappers.smtpctl // { program = "sendmail"; });
|
2020-06-18 07:06:33 +00:00
|
|
|
|
2020-04-24 23:36:52 +00:00
|
|
|
systemd.tmpfiles.rules = [
|
|
|
|
"d /var/spool/smtpd 711 root - - -"
|
|
|
|
"d /var/spool/smtpd/offline 770 root smtpq - -"
|
|
|
|
"d /var/spool/smtpd/purge 700 smtpq root - -"
|
|
|
|
];
|
|
|
|
|
|
|
|
systemd.services.opensmtpd = let
|
|
|
|
procEnv = pkgs.buildEnv {
|
|
|
|
name = "opensmtpd-procs";
|
|
|
|
paths = [ cfg.package ] ++ cfg.procPackages;
|
|
|
|
pathsToLink = [ "/libexec/opensmtpd" ];
|
|
|
|
};
|
|
|
|
in {
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
after = [ "network.target" ];
|
|
|
|
serviceConfig.ExecStart = "${cfg.package}/sbin/smtpd -d -f ${conf} ${args}";
|
|
|
|
environment.OPENSMTPD_PROC_PATH = "${procEnv}/libexec/opensmtpd";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|