2014-04-14 14:26:48 +00:00
|
|
|
{ config, lib, pkgs, ... }:
|
2013-07-30 08:20:56 +00:00
|
|
|
|
2014-04-14 14:26:48 +00:00
|
|
|
with lib;
|
2013-07-30 08:20:56 +00:00
|
|
|
|
|
|
|
let
|
|
|
|
|
|
|
|
cfg = config.services.opensmtpd;
|
2016-10-24 15:53:50 +00:00
|
|
|
conf = pkgs.writeText "smtpd.conf" cfg.serverConfiguration;
|
2013-07-30 08:20:56 +00:00
|
|
|
args = concatStringsSep " " cfg.extraServerArgs;
|
|
|
|
|
2018-11-08 10:59:03 +00:00
|
|
|
sendmail = pkgs.runCommand "opensmtpd-sendmail" { preferLocalBuild = true; } ''
|
2016-02-05 15:33:57 +00:00
|
|
|
mkdir -p $out/bin
|
2018-06-18 07:46:47 +00:00
|
|
|
ln -s ${cfg.package}/sbin/smtpctl $out/bin/sendmail
|
2016-02-05 15:33:57 +00:00
|
|
|
'';
|
|
|
|
|
2013-07-30 08:20:56 +00:00
|
|
|
in {
|
|
|
|
|
|
|
|
###### interface
|
|
|
|
|
2020-06-10 13:08:36 +00:00
|
|
|
imports = [
|
|
|
|
(mkRenamedOptionModule [ "services" "opensmtpd" "addSendmailToSystemPath" ] [ "services" "opensmtpd" "setSendmail" ])
|
|
|
|
];
|
|
|
|
|
2013-07-30 08:20:56 +00:00
|
|
|
options = {
|
|
|
|
|
|
|
|
services.opensmtpd = {
|
|
|
|
|
|
|
|
enable = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
|
|
|
description = "Whether to enable the OpenSMTPD server.";
|
|
|
|
};
|
|
|
|
|
2018-06-18 07:46:47 +00:00
|
|
|
package = mkOption {
|
|
|
|
type = types.package;
|
|
|
|
default = pkgs.opensmtpd;
|
|
|
|
defaultText = "pkgs.opensmtpd";
|
|
|
|
description = "The OpenSMTPD package to use.";
|
|
|
|
};
|
|
|
|
|
2020-06-10 13:08:36 +00:00
|
|
|
setSendmail = mkOption {
|
2016-02-05 15:33:57 +00:00
|
|
|
type = types.bool;
|
|
|
|
default = true;
|
2020-06-10 13:08:36 +00:00
|
|
|
description = "Whether to set the system sendmail to OpenSMTPD's.";
|
2016-02-05 15:33:57 +00:00
|
|
|
};
|
|
|
|
|
2013-07-30 08:20:56 +00:00
|
|
|
extraServerArgs = mkOption {
|
2015-06-15 16:18:46 +00:00
|
|
|
type = types.listOf types.str;
|
2013-07-30 08:20:56 +00:00
|
|
|
default = [];
|
|
|
|
example = [ "-v" "-P mta" ];
|
|
|
|
description = ''
|
|
|
|
Extra command line arguments provided when the smtpd process
|
|
|
|
is started.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
serverConfiguration = mkOption {
|
2016-10-24 15:53:20 +00:00
|
|
|
type = types.lines;
|
2013-07-30 08:20:56 +00:00
|
|
|
example = ''
|
|
|
|
listen on lo
|
|
|
|
accept for any deliver to lmtp localhost:24
|
2016-10-24 15:53:20 +00:00
|
|
|
'';
|
2013-07-30 08:20:56 +00:00
|
|
|
description = ''
|
|
|
|
The contents of the smtpd.conf configuration file. See the
|
2016-10-24 15:56:30 +00:00
|
|
|
OpenSMTPD documentation for syntax information.
|
2013-07-30 08:20:56 +00:00
|
|
|
'';
|
|
|
|
};
|
2015-11-14 20:32:51 +00:00
|
|
|
|
|
|
|
procPackages = mkOption {
|
2016-10-24 15:54:10 +00:00
|
|
|
type = types.listOf types.package;
|
2015-11-14 20:32:51 +00:00
|
|
|
default = [];
|
|
|
|
description = ''
|
|
|
|
Packages to search for filters, tables, queues, and schedulers.
|
|
|
|
|
|
|
|
Add OpenSMTPD-extras here if you want to use the filters, etc. from
|
|
|
|
that package.
|
|
|
|
'';
|
|
|
|
};
|
2013-07-30 08:20:56 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
###### implementation
|
|
|
|
|
2020-06-10 13:08:36 +00:00
|
|
|
config = mkIf cfg.enable rec {
|
2018-06-29 23:58:35 +00:00
|
|
|
users.groups = {
|
2013-07-30 08:20:56 +00:00
|
|
|
smtpd.gid = config.ids.gids.smtpd;
|
|
|
|
smtpq.gid = config.ids.gids.smtpq;
|
|
|
|
};
|
|
|
|
|
2018-06-29 23:58:35 +00:00
|
|
|
users.users = {
|
2013-07-30 08:20:56 +00:00
|
|
|
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-10 13:08:36 +00:00
|
|
|
security.wrappers.smtpctl = {
|
|
|
|
group = "smtpq";
|
|
|
|
setgid = true;
|
|
|
|
source = "${cfg.package}/bin/smtpctl";
|
|
|
|
};
|
|
|
|
|
|
|
|
services.mail.sendmailSetuidWrapper = mkIf cfg.setSendmail security.wrappers.smtpctl;
|
|
|
|
|
2019-10-31 22:24: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 - -"
|
|
|
|
];
|
|
|
|
|
2015-11-14 20:32:51 +00:00
|
|
|
systemd.services.opensmtpd = let
|
|
|
|
procEnv = pkgs.buildEnv {
|
|
|
|
name = "opensmtpd-procs";
|
2018-06-18 07:46:47 +00:00
|
|
|
paths = [ cfg.package ] ++ cfg.procPackages;
|
2015-11-14 20:32:51 +00:00
|
|
|
pathsToLink = [ "/libexec/opensmtpd" ];
|
|
|
|
};
|
|
|
|
in {
|
2013-07-30 08:20:56 +00:00
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
after = [ "network.target" ];
|
2018-06-18 07:46:47 +00:00
|
|
|
serviceConfig.ExecStart = "${cfg.package}/sbin/smtpd -d -f ${conf} ${args}";
|
2015-11-14 20:32:51 +00:00
|
|
|
environment.OPENSMTPD_PROC_PATH = "${procEnv}/libexec/opensmtpd";
|
2013-07-30 08:20:56 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|