git.iko.soy/typeable/nixpkgs
on master help sign in
nixos/mlmmj: fix newline problems with multiple lists

- Insert newlines into list configurations - Move list maintence to a timer - Create missing directories at profile activation

commit634b0403739377fd5d0a162444ce92acf51e9d97 authorEmery Hemingway <emery@vfemail.net> dateFri 12 May 2017, 10:05 (10 years ago) parent71f7de9
1 file changed+39−13
nixos/modules/services/mail/mlmmj.nix+39−13
nixos/modules/services/mail/mlmmj.nix+39−13
@@ -4,6 +4,8 @@ with lib;
44
55let
66
7+ concatMapLines = f: l: lib.concatStringsSep "\n" (map f l);
8+
79 cfg = config.services.mlmmj;
810 stateDir = "/var/lib/mlmmj";
911 spoolDir = "/var/spool/mlmmj";
@@ -16,13 +18,24 @@ let
1618 listAddress = domain: list: "${list}@${domain}";
1719 customHeaders = domain: list: [ "List-Id: ${list}" "Reply-To: ${list}@${domain}" ];
1820 footer = domain: list: "To unsubscribe send a mail to ${list}+unsubscribe@${domain}";
19− createList = d: l: ''
20− ${pkgs.coreutils}/bin/mkdir -p ${listCtl d l}
21− echo ${listAddress d l} > ${listCtl d l}/listaddress
22− echo "${lib.concatStringsSep "\n" (customHeaders d l)}" > ${listCtl d l}/customheaders
23− echo ${footer d l} > ${listCtl d l}/footer
24− echo ${subjectPrefix l} > ${listCtl d l}/prefix
25− '';
21+ createList = d: l:
22+ let ctlDir = listCtl d l; in
23+ ''
24+ for DIR in incoming queue queue/discarded archive text subconf unsubconf \
25+ bounce control moderation subscribers.d digesters.d requeue \
26+ nomailsubs.d
27+ do
28+ mkdir -p '${listDir d l}'/"$DIR"
29+ done
30+ ${pkgs.coreutils}/bin/mkdir -p ${ctlDir}
31+ echo ${listAddress d l} > '${ctlDir}/listaddress'
32+ [ ! -e ${ctlDir}/customheaders ] && \
33+ echo "${lib.concatStringsSep "\n" (customHeaders d l)}" > '${ctlDir}/customheaders'
34+ [ ! -e ${ctlDir}/footer ] && \
35+ echo ${footer d l} > '${ctlDir}/footer'
36+ [ ! -e ${ctlDir}/prefix ] && \
37+ echo ${subjectPrefix l} > '${ctlDir}/prefix'
38+ '';
2639in
2740
2841{
@@ -63,6 +76,16 @@ in
6376 description = "The collection of hosted maillists";
6477 };
6578
79+ maintInterval = mkOption {
80+ type = types.str;
81+ default = "20min";
82+ description = ''
83+ Time interval between mlmmj-maintd runs, see
84+ <citerefentry><refentrytitle>systemd.time</refentrytitle>
85+ <manvolnum>7</manvolnum></citerefentry> for format information.
86+ '';
87+ };
88+
6689 };
6790
6891 };
@@ -93,7 +116,7 @@ in
93116 mlmmj unix - n n - - pipe flags=ORhu user=mlmmj argv=${pkgs.mlmmj}/bin/mlmmj-receive -F -L ${spoolDir}/$nexthop
94117 '';
95118
96− extraAliases = concatMapStrings (alias cfg.listDomain) cfg.mailLists;
119+ extraAliases = concatMapLines (alias cfg.listDomain) cfg.mailLists;
97120
98121 extraConfig = ''
99122 transport_maps = hash:${stateDir}/transports
@@ -107,17 +130,15 @@ in
107130 system.activationScripts.mlmmj = ''
108131 ${pkgs.coreutils}/bin/mkdir -p ${stateDir} ${spoolDir}/${cfg.listDomain}
109132 ${pkgs.coreutils}/bin/chown -R ${cfg.user}:${cfg.group} ${spoolDir}
110− ${lib.concatMapStrings (createList cfg.listDomain) cfg.mailLists}
111− echo ${lib.concatMapStrings (virtual cfg.listDomain) cfg.mailLists} > ${stateDir}/virtuals
112− echo ${lib.concatMapStrings (transport cfg.listDomain) cfg.mailLists} > ${stateDir}/transports
133+ ${concatMapLines (createList cfg.listDomain) cfg.mailLists}
134+ echo "${concatMapLines (virtual cfg.listDomain) cfg.mailLists}" > ${stateDir}/virtuals
135+ echo "${concatMapLines (transport cfg.listDomain) cfg.mailLists}" > ${stateDir}/transports
113136 ${pkgs.postfix}/bin/postmap ${stateDir}/virtuals
114137 ${pkgs.postfix}/bin/postmap ${stateDir}/transports
115138 '';
116139
117140 systemd.services."mlmmj-maintd" = {
118141 description = "mlmmj maintenance daemon";
119− wantedBy = [ "multi-user.target" ];
120−
121142 serviceConfig = {
122143 User = cfg.user;
123144 Group = cfg.group;
@@ -125,6 +146,11 @@ in
125146 };
126147 };
127148
149+ systemd.timers."mlmmj-maintd" = {
150+ description = "mlmmj maintenance timer";
151+ timerConfig.OnUnitActiveSec = cfg.maintInterval;
152+ wantedBy = [ "timers.target" ];
153+ };
128154 };
129155
130156}