1 { config, lib, pkgs, ... }:
7 cfg = config.services.opensmtpd;
8 conf = pkgs.writeText "smtpd.conf" cfg.serverConfiguration;
9 args = concatStringsSep " " cfg.extraServerArgs;
11 sendmail = pkgs.runCommand "opensmtpd-sendmail" { preferLocalBuild = true; } ''
13 ln -s ${cfg.package}/sbin/smtpctl $out/bin/sendmail
21 (mkRenamedOptionModule [ "services" "opensmtpd" "addSendmailToSystemPath" ] [ "services" "opensmtpd" "setSendmail" ])
26 services.opensmtpd = {
31 description = lib.mdDoc "Whether to enable the OpenSMTPD server.";
36 default = pkgs.opensmtpd;
37 defaultText = literalExpression "pkgs.opensmtpd";
38 description = lib.mdDoc "The OpenSMTPD package to use.";
41 setSendmail = mkOption {
44 description = lib.mdDoc "Whether to set the system sendmail to OpenSMTPD's.";
47 extraServerArgs = mkOption {
48 type = types.listOf types.str;
50 example = [ "-v" "-P mta" ];
51 description = lib.mdDoc ''
52 Extra command line arguments provided when the smtpd process
57 serverConfiguration = mkOption {
61 accept for any deliver to lmtp localhost:24
63 description = lib.mdDoc ''
64 The contents of the smtpd.conf configuration file. See the
65 OpenSMTPD documentation for syntax information.
69 procPackages = mkOption {
70 type = types.listOf types.package;
72 description = lib.mdDoc ''
73 Packages to search for filters, tables, queues, and schedulers.
75 Add OpenSMTPD-extras here if you want to use the filters, etc. from
86 config = mkIf cfg.enable rec {
88 smtpd.gid = config.ids.gids.smtpd;
89 smtpq.gid = config.ids.gids.smtpq;
94 description = "OpenSMTPD process user";
95 uid = config.ids.uids.smtpd;
99 description = "OpenSMTPD queue user";
100 uid = config.ids.uids.smtpq;
105 security.wrappers.smtpctl = {
110 source = "${cfg.package}/bin/smtpctl";
113 services.mail.sendmailSetuidWrapper = mkIf cfg.setSendmail
114 (security.wrappers.smtpctl // { program = "sendmail"; });
116 systemd.tmpfiles.rules = [
117 "d /var/spool/smtpd 711 root - - -"
118 "d /var/spool/smtpd/offline 770 root smtpq - -"
119 "d /var/spool/smtpd/purge 700 smtpq root - -"
122 systemd.services.opensmtpd = let
123 procEnv = pkgs.buildEnv {
124 name = "opensmtpd-procs";
125 paths = [ cfg.package ] ++ cfg.procPackages;
126 pathsToLink = [ "/libexec/opensmtpd" ];
129 wantedBy = [ "multi-user.target" ];
130 after = [ "network.target" ];
131 serviceConfig.ExecStart = "${cfg.package}/sbin/smtpd -d -f ${conf} ${args}";
132 environment.OPENSMTPD_PROC_PATH = "${procEnv}/libexec/opensmtpd";