nixpkgs/nixos/modules/services/mail/opensmtpd.nix

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

136 lines
3.4 KiB
Nix
Raw Normal View History

{ config, lib, pkgs, ... }:
2013-07-30 08:20:56 +00:00
with lib;
2013-07-30 08:20:56 +00:00
let
cfg = config.services.opensmtpd;
conf = pkgs.writeText "smtpd.conf" cfg.serverConfiguration;
2013-07-30 08:20:56 +00:00
args = concatStringsSep " " cfg.extraServerArgs;
sendmail = pkgs.runCommand "opensmtpd-sendmail" { preferLocalBuild = true; } ''
mkdir -p $out/bin
ln -s ${cfg.package}/sbin/smtpctl $out/bin/sendmail
'';
2013-07-30 08:20:56 +00:00
in {
###### interface
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.";
};
package = mkOption {
type = types.package;
default = pkgs.opensmtpd;
defaultText = literalExpression "pkgs.opensmtpd";
description = "The OpenSMTPD package to use.";
};
setSendmail = mkOption {
type = types.bool;
default = true;
description = "Whether to set the system sendmail to OpenSMTPD's.";
};
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 {
type = types.lines;
2013-07-30 08:20:56 +00:00
example = ''
listen on lo
accept for any deliver to lmtp localhost:24
'';
2013-07-30 08:20:56 +00:00
description = ''
The contents of the smtpd.conf configuration file. See the
OpenSMTPD documentation for syntax information.
2013-07-30 08:20:56 +00:00
'';
};
procPackages = mkOption {
type = types.listOf types.package;
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
config = mkIf cfg.enable rec {
users.groups = {
2013-07-30 08:20:56 +00:00
smtpd.gid = config.ids.gids.smtpd;
smtpq.gid = config.ids.gids.smtpq;
};
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";
};
};
security.wrappers.smtpctl = {
2021-10-03 09:43:13 +00:00
owner = "root";
group = "smtpq";
setuid = false;
setgid = true;
source = "${cfg.package}/bin/smtpctl";
};
services.mail.sendmailSetuidWrapper = mkIf cfg.setSendmail
(security.wrappers.smtpctl // { program = "sendmail"; });
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 {
2013-07-30 08:20:56 +00:00
wantedBy = [ "multi-user.target" ];
after = [ "network.target" ];
serviceConfig.ExecStart = "${cfg.package}/sbin/smtpd -d -f ${conf} ${args}";
environment.OPENSMTPD_PROC_PATH = "${procEnv}/libexec/opensmtpd";
2013-07-30 08:20:56 +00:00
};
};
}