From 3ca7d7b2915d48854856d2a2c1024b268decaa4a Mon Sep 17 00:00:00 2001 From: Rickard Nilsson Date: Tue, 30 Jul 2013 10:20:56 +0200 Subject: [PATCH] Add OpenSMTPD service option --- modules/misc/ids.nix | 4 ++ modules/module-list.nix | 1 + modules/services/mail/opensmtpd.nix | 83 +++++++++++++++++++++++++++++ 3 files changed, 88 insertions(+) create mode 100644 modules/services/mail/opensmtpd.nix diff --git a/modules/misc/ids.nix b/modules/misc/ids.nix index 7272c3e7d5d..915da73d307 100644 --- a/modules/misc/ids.nix +++ b/modules/misc/ids.nix @@ -76,6 +76,8 @@ in nslcd = 58; nginx = 60; chrony = 61; + smtpd = 63; + smtpq = 64; # When adding a uid, make sure it doesn't match an existing gid. @@ -135,6 +137,8 @@ in scanner = 59; nginx = 60; systemd-journal = 62; + smtpd = 63; + smtpq = 64; # When adding a gid, make sure it doesn't match an existing uid. diff --git a/modules/module-list.nix b/modules/module-list.nix index ebe66d1fa6e..13501ba4910 100644 --- a/modules/module-list.nix +++ b/modules/module-list.nix @@ -104,6 +104,7 @@ ./services/mail/dovecot.nix ./services/mail/freepops.nix ./services/mail/mail.nix + ./services/mail/opensmtpd.nix ./services/mail/postfix.nix ./services/mail/spamassassin.nix ./services/misc/autofs.nix diff --git a/modules/services/mail/opensmtpd.nix b/modules/services/mail/opensmtpd.nix new file mode 100644 index 00000000000..2732fd60200 --- /dev/null +++ b/modules/services/mail/opensmtpd.nix @@ -0,0 +1,83 @@ +{ pkgs, config, ... }: + +with pkgs; +with pkgs.lib; + +let + + cfg = config.services.opensmtpd; + conf = writeText "smtpd.conf" cfg.serverConfiguration; + args = concatStringsSep " " cfg.extraServerArgs; + +in { + + ###### interface + + options = { + + services.opensmtpd = { + + enable = mkOption { + type = types.bool; + default = false; + description = "Whether to enable the OpenSMTPD server."; + }; + + extraServerArgs = mkOption { + type = types.listOf types.string; + default = []; + example = [ "-v" "-P mta" ]; + description = '' + Extra command line arguments provided when the smtpd process + is started. + ''; + }; + + serverConfiguration = mkOption { + type = types.string; + default = ""; + example = '' + listen on lo + accept for any deliver to lmtp localhost:24 + ''; + description = '' + The contents of the smtpd.conf configuration file. See the + OpenSMTPD documentation for syntax information. If this option + is left empty, the OpenSMTPD server will not start. + ''; + }; + }; + + }; + + + ###### implementation + + config = mkIf config.services.opensmtpd.enable { + users.extraGroups = { + smtpd.gid = config.ids.gids.smtpd; + smtpq.gid = config.ids.gids.smtpq; + }; + + users.extraUsers = { + smtpd = { + description = "OpenSMTPD process user"; + uid = config.ids.uids.smtpd; + group = "smtpd"; + }; + smtpq = { + description = "OpenSMTPD queue user"; + uid = config.ids.uids.smtpq; + group = "smtpq"; + }; + }; + + systemd.services.opensmtpd = { + wantedBy = [ "multi-user.target" ]; + wants = [ "network.target" ]; + after = [ "network.target" ]; + preStart = "mkdir -p /var/spool"; + serviceConfig.ExecStart = "${opensmtpd}/sbin/smtpd -d -f ${conf} ${args}"; + }; + }; +}