1 { config, lib, pkgs, ... }:
4 cfg = config.services.opensmtpd;
5 conf = pkgs.writeText "smtpd.conf" cfg.serverConfiguration;
6 args = lib.concatStringsSep " " cfg.extraServerArgs;
8 sendmail = pkgs.runCommand "opensmtpd-sendmail" { preferLocalBuild = true; } ''
10 ln -s ${cfg.package}/sbin/smtpctl $out/bin/sendmail
18 (lib.mkRenamedOptionModule [ "services" "opensmtpd" "addSendmailToSystemPath" ] [ "services" "opensmtpd" "setSendmail" ])
23 services.opensmtpd = {
25 enable = lib.mkOption {
26 type = lib.types.bool;
28 description = "Whether to enable the OpenSMTPD server.";
31 package = lib.mkPackageOption pkgs "opensmtpd" { };
33 setSendmail = lib.mkOption {
34 type = lib.types.bool;
36 description = "Whether to set the system sendmail to OpenSMTPD's.";
39 extraServerArgs = lib.mkOption {
40 type = lib.types.listOf lib.types.str;
42 example = [ "-v" "-P mta" ];
44 Extra command line arguments provided when the smtpd process
49 serverConfiguration = lib.mkOption {
50 type = lib.types.lines;
53 accept for any deliver to lmtp localhost:24
56 The contents of the smtpd.conf configuration file. See the
57 OpenSMTPD documentation for syntax information.
61 procPackages = lib.mkOption {
62 type = lib.types.listOf lib.types.package;
65 Packages to search for filters, tables, queues, and schedulers.
67 Add OpenSMTPD-extras here if you want to use the filters, etc. from
78 config = lib.mkIf cfg.enable rec {
80 smtpd.gid = config.ids.gids.smtpd;
81 smtpq.gid = config.ids.gids.smtpq;
86 description = "OpenSMTPD process user";
87 uid = config.ids.uids.smtpd;
91 description = "OpenSMTPD queue user";
92 uid = config.ids.uids.smtpq;
97 security.wrappers.smtpctl = {
102 source = "${cfg.package}/bin/smtpctl";
105 services.mail.sendmailSetuidWrapper = lib.mkIf cfg.setSendmail
106 (security.wrappers.smtpctl // { program = "sendmail"; });
108 systemd.tmpfiles.rules = [
109 "d /var/spool/smtpd 711 root - - -"
110 "d /var/spool/smtpd/offline 770 root smtpq - -"
111 "d /var/spool/smtpd/purge 700 smtpq root - -"
114 systemd.services.opensmtpd = let
115 procEnv = pkgs.buildEnv {
116 name = "opensmtpd-procs";
117 paths = [ cfg.package ] ++ cfg.procPackages;
118 pathsToLink = [ "/libexec/opensmtpd" ];
121 wantedBy = [ "multi-user.target" ];
122 after = [ "network.target" ];
123 serviceConfig.ExecStart = "${cfg.package}/sbin/smtpd -d -f ${conf} ${args}";
124 environment.OPENSMTPD_PROC_PATH = "${procEnv}/libexec/opensmtpd";