From 634b0403739377fd5d0a162444ce92acf51e9d97 Mon Sep 17 00:00:00 2001 From: Emery Hemingway Date: Fri, 12 May 2017 10:05:41 -0500 Subject: 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 --- nixos/modules/services/mail/mlmmj.nix | 52 ++++++++++++++++++++++++++--------- 1 file changed, 39 insertions(+), 13 deletions(-) (limited to 'nixos/modules/services') diff --git a/nixos/modules/services/mail/mlmmj.nix b/nixos/modules/services/mail/mlmmj.nix index 4a01745eb8b6..b6439b44fb5f 100644 --- a/nixos/modules/services/mail/mlmmj.nix +++ b/nixos/modules/services/mail/mlmmj.nix @@ -4,6 +4,8 @@ with lib; let + concatMapLines = f: l: lib.concatStringsSep "\n" (map f l); + cfg = config.services.mlmmj; stateDir = "/var/lib/mlmmj"; spoolDir = "/var/spool/mlmmj"; @@ -16,13 +18,24 @@ let 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 - ''; + 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 { @@ -63,6 +76,16 @@ in description = "The collection of hosted maillists"; }; + maintInterval = mkOption { + type = types.str; + default = "20min"; + description = '' + Time interval between mlmmj-maintd runs, see + systemd.time + 7 for format information. + ''; + }; + }; }; @@ -93,7 +116,7 @@ in 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; + extraAliases = concatMapLines (alias cfg.listDomain) cfg.mailLists; extraConfig = '' transport_maps = hash:${stateDir}/transports @@ -107,17 +130,15 @@ in 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 + ${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"; - wantedBy = [ "multi-user.target" ]; - serviceConfig = { User = cfg.user; Group = cfg.group; @@ -125,6 +146,11 @@ in }; }; + systemd.timers."mlmmj-maintd" = { + description = "mlmmj maintenance timer"; + timerConfig.OnUnitActiveSec = cfg.maintInterval; + wantedBy = [ "timers.target" ]; + }; }; } -- cgit 1.4.1