git.iko.soy/typeable/nixpkgs
on master help sign in
Merge pull request #25381 from sargon/nullmailer

nullmailer + service: init at 2.0

commitae12ded6bf9685124b55fdbcdc92eb04de1fa553 authorJörg Thalheim <Mic92@users.noreply.github.com> dateSat 13 May 2017, 07:13 (10 years ago) parent53a86344338f09
4 files changed+271
nixos/modules/module-list.nix+1 nixos/modules/services/mail/nullmailer.nix+217 pkgs/servers/mail/nullmailer/default.nix+51 pkgs/top-level/all-packages.nix+2
nixos/modules/module-list.nix+1
@@ -256,6 +256,7 @@
256256 ./services/mail/spamassassin.nix
257257 ./services/mail/rspamd.nix
258258 ./services/mail/rmilter.nix
259+ ./services/mail/nullmailer.nix
259260 ./services/misc/apache-kafka.nix
260261 ./services/misc/autofs.nix
261262 ./services/misc/autorandr.nix
nixos/modules/services/mail/nullmailer.nixnew file+217
@@ -0,0 +1,217 @@
1+{ config, lib, pkgs, ... }:
2+
3+with lib;
4+
5+{
6+
7+ options = {
8+
9+ services.nullmailer = {
10+ enable = mkOption {
11+ type = types.bool;
12+ default = false;
13+ description = "Whether to enable nullmailer daemon.";
14+ };
15+
16+ user = mkOption {
17+ type = types.string;
18+ default = "nullmailer";
19+ description = ''
20+ User to use to run nullmailer-send.
21+ '';
22+ };
23+
24+ group = mkOption {
25+ type = types.string;
26+ default = "nullmailer";
27+ description = ''
28+ Group to use to run nullmailer-send.
29+ '';
30+ };
31+
32+ setSendmail = mkOption {
33+ type = types.bool;
34+ default = true;
35+ description = "Whether to set the system sendmail to nullmailer's.";
36+ };
37+
38+ config = {
39+ adminaddr = mkOption {
40+ type = types.nullOr types.str;
41+ default = null;
42+ description = ''
43+ If set, all recipients to users at either "localhost" (the literal string)
44+ or the canonical host name (from the me control attribute) are remapped to this address.
45+ This is provided to allow local daemons to be able to send email to
46+ "somebody@localhost" and have it go somewhere sensible instead of being bounced
47+ by your relay host. To send to multiple addresses,
48+ put them all on one line separated by a comma.
49+ '';
50+ };
51+
52+ allmailfrom = mkOption {
53+ type = types.nullOr types.str;
54+ default = null;
55+ description = ''
56+ If set, content will override the envelope sender on all messages.
57+ '';
58+ };
59+
60+ defaultdomain = mkOption {
61+ type = types.nullOr types.str;
62+ default = null;
63+ description = ''
64+ The content of this attribute is appended to any host name that
65+ does not contain a period (except localhost), including defaulthost
66+ and idhost. Defaults to the value of the me attribute, if it exists,
67+ otherwise the literal name defauldomain.
68+ '';
69+ };
70+
71+ defaulthost = mkOption {
72+ type = types.nullOr types.str;
73+ default = null;
74+ description = ''
75+ The content of this attribute is appended to any address that
76+ is missing a host name. Defaults to the value of the me control
77+ attribute, if it exists, otherwise the literal name defaulthost.
78+ '';
79+ };
80+
81+ doublebounceto = mkOption {
82+ type = types.nullOr types.str;
83+ default = null;
84+ description = ''
85+ If the original sender was empty (the original message was a
86+ delivery status or disposition notification), the double bounce
87+ is sent to the address in this attribute.
88+ '';
89+ };
90+
91+ helohost = mkOption {
92+ type = types.nullOr types.str;
93+ default = null;
94+ description = ''
95+ Sets the environment variable $HELOHOST which is used by the
96+ SMTP protocol module to set the parameter given to the HELO command.
97+ Defaults to the value of the me configuration attribute.
98+ '';
99+ };
100+
101+ idhost = mkOption {
102+ type = types.nullOr types.str;
103+ default = null;
104+ description = ''
105+ The content of this attribute is used when building the message-id
106+ string for the message. Defaults to the canonicalized value of defaulthost.
107+ '';
108+ };
109+
110+ maxpause = mkOption {
111+ type = types.nullOr types.str;
112+ default = null;
113+ description = ''
114+ The maximum time to pause between successive queue runs, in seconds.
115+ Defaults to 24 hours (86400).
116+ '';
117+ };
118+
119+ me = mkOption {
120+ type = types.nullOr types.str;
121+ default = null;
122+ description = ''
123+ The fully-qualifiled host name of the computer running nullmailer.
124+ Defaults to the literal name me.
125+ '';
126+ };
127+
128+ pausetime = mkOption {
129+ type = types.nullOr types.str;
130+ default = null;
131+ description = ''
132+ The minimum time to pause between successive queue runs when there
133+ are messages in the queue, in seconds. Defaults to 1 minute (60).
134+ Each time this timeout is reached, the timeout is doubled to a
135+ maximum of maxpause. After new messages are injected, the timeout
136+ is reset. If this is set to 0, nullmailer-send will exit
137+ immediately after going through the queue once (one-shot mode).
138+ '';
139+ };
140+
141+ remotes = mkOption {
142+ type = types.nullOr types.str;
143+ default = null;
144+ description = ''
145+ If set, content will override the envelope sender on all messages.
146+ '';
147+ };
148+
149+ sendtimeout = mkOption {
150+ type = types.nullOr types.str;
151+ default = null;
152+ description = ''
153+ The time to wait for a remote module listed above to complete sending
154+ a message before killing it and trying again, in seconds.
155+ Defaults to 1 hour (3600). If this is set to 0, nullmailer-send
156+ will wait forever for messages to complete sending.
157+ '';
158+ };
159+ };
160+ };
161+ };
162+
163+ config = let
164+ cfg = config.services.nullmailer;
165+ in mkIf cfg.enable {
166+
167+ environment = {
168+ systemPackages = [ pkgs.nullmailer ];
169+ etc = let
170+ getval = attr: builtins.getAttr attr cfg.config;
171+ attrs = builtins.attrNames cfg.config;
172+ attrs' = builtins.filter (attr: ! isNull (getval attr)) attrs;
173+ in foldl' (as: attr: as // { "nullmailer/${attr}".text = getval attr; }) {} attrs';
174+ };
175+
176+ users = {
177+ extraUsers = singleton {
178+ name = cfg.user;
179+ description = "Nullmailer relay-only mta user";
180+ group = cfg.group;
181+ };
182+
183+ extraGroups = singleton {
184+ name = cfg.group;
185+ };
186+ };
187+
188+ systemd.services.nullmailer = {
189+ description = "nullmailer";
190+ wantedBy = [ "multi-user.target" ];
191+ after = [ "network.target" ];
192+
193+ preStart = ''
194+ mkdir -p /var/spool/nullmailer/{queue,tmp}
195+ rm -f var/spool/nullmailer/trigger && mkfifo -m 660 /var/spool/nullmailer/trigger
196+ chown ${cfg.user} /var/spool/nullmailer/*
197+ '';
198+
199+ serviceConfig = {
200+ User = cfg.user;
201+ Group = cfg.group;
202+ PermissionsStartOnly=true;
203+ ExecStart = "${pkgs.nullmailer}/bin/nullmailer-send";
204+ Restart = "always";
205+ };
206+ };
207+
208+ services.mail.sendmailSetuidWrapper = mkIf cfg.setSendmail {
209+ program = "sendmail";
210+ source = "${pkgs.nullmailer}/bin/sendmail";
211+ owner = cfg.user;
212+ group = cfg.group;
213+ setuid = true;
214+ setgid = true;
215+ };
216+ };
217+}
pkgs/servers/mail/nullmailer/default.nixnew file+51
@@ -0,0 +1,51 @@
1+{ stdenv, fetchurl, lib, tls ? true, gnutls ? null }:
2+
3+assert tls -> gnutls != null;
4+
5+stdenv.mkDerivation rec {
6+
7+ version = "2.0";
8+ name = "nullmailer-${version}";
9+
10+ src = fetchurl {
11+ url = "http://untroubled.org/nullmailer/nullmailer-${version}.tar.gz";
12+ sha256 = "112ghdln8q9yljc8kp9mc3843mh0fyb4rig2v4q2dzy1l324q3yp";
13+ };
14+
15+ buildInputs = stdenv.lib.optional tls gnutls;
16+
17+ configureFlags = [
18+ "--sysconfdir=/etc"
19+ "--localstatedir=/var"
20+ ] ++ stdenv.lib.optional tls "--enable-tls";
21+
22+ installFlags = [ "DESTDIR=$(out)" ];
23+
24+ # We have to remove the ''var'' directory, since nix can't handle named pipes
25+ # and we can't use it in the store anyway. Same for ''etc''.
26+ # The second line is need, because the installer of nullmailer will copy its
27+ # own prepared version of ''etc'' and ''var'' and also uses the prefix path (configure phase)
28+ # for hardcoded absolute references to its own binary farm, e.g. sendmail binary is
29+ # calling nullmailer-inject binary. Since we can't configure inside the store of
30+ # the derivation we need both directories in the root, but don't want to put them there
31+ # during install, hence we have to fix mumbling inside the install directory.
32+ # This is kind of a hack, but the only way I know of, yet.
33+ postInstall = ''
34+ rm -rf $out/var/ $out/etc/
35+ mv $out/$out/* $out/
36+ rmdir $out/$out
37+ '';
38+
39+ enableParallelBuilding = true;
40+
41+ meta = {
42+ homepage = "http://untroubled.org/nullmailer/";
43+ description = ''
44+ A sendmail/qmail/etc replacement MTA for hosts which relay to a fixed set of smart relays.
45+ It is designed to be simple to configure, secure, and easily extendable.
46+ '';
47+ license = lib.licenses.gpl2;
48+ platforms = lib.platforms.all;
49+ maintainers = with lib.maintainers ; [ sargon ];
50+ };
51+}
pkgs/top-level/all-packages.nix+2
@@ -12747,6 +12747,8 @@ with pkgs;
1274712747 inherit (callPackages ../data/fonts/noto-fonts {})
1274812748 noto-fonts noto-fonts-cjk noto-fonts-emoji;
1274912749
12750+ nullmailer = callPackage ../servers/mail/nullmailer { };
12751+
1275012752 numix-icon-theme = callPackage ../data/icons/numix-icon-theme { };
1275112753
1275212754 numix-icon-theme-circle = callPackage ../data/icons/numix-icon-theme-circle { };