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

Changed files
+39 -13
nixos
modules
services
mail
+39 -13
nixos/modules/services/mail/mlmmj.nix
···
let
cfg = config.services.mlmmj;
stateDir = "/var/lib/mlmmj";
spoolDir = "/var/spool/mlmmj";
···
listAddress = domain: list: "${list}@${domain}";
customHeaders = domain: list: [ "List-Id: ${list}" "Reply-To: ${list}@${domain}" ];
footer = domain: list: "To unsubscribe send a mail to ${list}+unsubscribe@${domain}";
-
createList = d: l: ''
-
${pkgs.coreutils}/bin/mkdir -p ${listCtl d l}
-
echo ${listAddress d l} > ${listCtl d l}/listaddress
-
echo "${lib.concatStringsSep "\n" (customHeaders d l)}" > ${listCtl d l}/customheaders
-
echo ${footer d l} > ${listCtl d l}/footer
-
echo ${subjectPrefix l} > ${listCtl d l}/prefix
-
'';
in
{
···
description = "The collection of hosted maillists";
};
};
};
···
mlmmj unix - n n - - pipe flags=ORhu user=mlmmj argv=${pkgs.mlmmj}/bin/mlmmj-receive -F -L ${spoolDir}/$nexthop
'';
-
extraAliases = concatMapStrings (alias cfg.listDomain) cfg.mailLists;
extraConfig = ''
transport_maps = hash:${stateDir}/transports
···
system.activationScripts.mlmmj = ''
${pkgs.coreutils}/bin/mkdir -p ${stateDir} ${spoolDir}/${cfg.listDomain}
${pkgs.coreutils}/bin/chown -R ${cfg.user}:${cfg.group} ${spoolDir}
-
${lib.concatMapStrings (createList cfg.listDomain) cfg.mailLists}
-
echo ${lib.concatMapStrings (virtual cfg.listDomain) cfg.mailLists} > ${stateDir}/virtuals
-
echo ${lib.concatMapStrings (transport cfg.listDomain) cfg.mailLists} > ${stateDir}/transports
${pkgs.postfix}/bin/postmap ${stateDir}/virtuals
${pkgs.postfix}/bin/postmap ${stateDir}/transports
'';
systemd.services."mlmmj-maintd" = {
description = "mlmmj maintenance daemon";
-
wantedBy = [ "multi-user.target" ];
-
serviceConfig = {
User = cfg.user;
Group = cfg.group;
···
};
};
};
}
···
let
+
concatMapLines = f: l: lib.concatStringsSep "\n" (map f l);
+
cfg = config.services.mlmmj;
stateDir = "/var/lib/mlmmj";
spoolDir = "/var/spool/mlmmj";
···
listAddress = domain: list: "${list}@${domain}";
customHeaders = domain: list: [ "List-Id: ${list}" "Reply-To: ${list}@${domain}" ];
footer = domain: list: "To unsubscribe send a mail to ${list}+unsubscribe@${domain}";
+
createList = d: l:
+
let ctlDir = listCtl d l; in
+
''
+
for DIR in incoming queue queue/discarded archive text subconf unsubconf \
+
bounce control moderation subscribers.d digesters.d requeue \
+
nomailsubs.d
+
do
+
mkdir -p '${listDir d l}'/"$DIR"
+
done
+
${pkgs.coreutils}/bin/mkdir -p ${ctlDir}
+
echo ${listAddress d l} > '${ctlDir}/listaddress'
+
[ ! -e ${ctlDir}/customheaders ] && \
+
echo "${lib.concatStringsSep "\n" (customHeaders d l)}" > '${ctlDir}/customheaders'
+
[ ! -e ${ctlDir}/footer ] && \
+
echo ${footer d l} > '${ctlDir}/footer'
+
[ ! -e ${ctlDir}/prefix ] && \
+
echo ${subjectPrefix l} > '${ctlDir}/prefix'
+
'';
in
{
···
description = "The collection of hosted maillists";
};
+
maintInterval = mkOption {
+
type = types.str;
+
default = "20min";
+
description = ''
+
Time interval between mlmmj-maintd runs, see
+
<citerefentry><refentrytitle>systemd.time</refentrytitle>
+
<manvolnum>7</manvolnum></citerefentry> for format information.
+
'';
+
};
+
};
};
···
mlmmj unix - n n - - pipe flags=ORhu user=mlmmj argv=${pkgs.mlmmj}/bin/mlmmj-receive -F -L ${spoolDir}/$nexthop
'';
+
extraAliases = concatMapLines (alias cfg.listDomain) cfg.mailLists;
extraConfig = ''
transport_maps = hash:${stateDir}/transports
···
system.activationScripts.mlmmj = ''
${pkgs.coreutils}/bin/mkdir -p ${stateDir} ${spoolDir}/${cfg.listDomain}
${pkgs.coreutils}/bin/chown -R ${cfg.user}:${cfg.group} ${spoolDir}
+
${concatMapLines (createList cfg.listDomain) cfg.mailLists}
+
echo "${concatMapLines (virtual cfg.listDomain) cfg.mailLists}" > ${stateDir}/virtuals
+
echo "${concatMapLines (transport cfg.listDomain) cfg.mailLists}" > ${stateDir}/transports
${pkgs.postfix}/bin/postmap ${stateDir}/virtuals
${pkgs.postfix}/bin/postmap ${stateDir}/transports
'';
systemd.services."mlmmj-maintd" = {
description = "mlmmj maintenance daemon";
serviceConfig = {
User = cfg.user;
Group = cfg.group;
···
};
};
+
systemd.timers."mlmmj-maintd" = {
+
description = "mlmmj maintenance timer";
+
timerConfig.OnUnitActiveSec = cfg.maintInterval;
+
wantedBy = [ "timers.target" ];
+
};
};
}