1 { config, lib, pkgs, ... }:
7 concatMapLines = f: l: lib.concatStringsSep "\n" (map f l);
9 cfg = config.services.mlmmj;
10 stateDir = "/var/lib/mlmmj";
11 spoolDir = "/var/spool/mlmmj";
12 listDir = domain: list: "${spoolDir}/${domain}/${list}";
13 listCtl = domain: list: "${listDir domain list}/control";
14 transport = domain: list: "${domain}--${list}@local.list.mlmmj mlmmj:${domain}/${list}";
15 virtual = domain: list: "${list}@${domain} ${domain}--${list}@local.list.mlmmj";
16 alias = domain: list: "${list}: \"|${pkgs.mlmmj}/bin/mlmmj-receive -L ${listDir domain list}/\"";
17 subjectPrefix = list: "[${list}]";
18 listAddress = domain: list: "${list}@${domain}";
19 customHeaders = domain: list: [
21 "Reply-To: ${list}@${domain}"
22 "List-Post: <mailto:${list}@${domain}>"
23 "List-Help: <mailto:${list}+help@${domain}>"
24 "List-Subscribe: <mailto:${list}+subscribe@${domain}>"
25 "List-Unsubscribe: <mailto:${list}+unsubscribe@${domain}>"
27 footer = domain: list: "To unsubscribe send a mail to ${list}+unsubscribe@${domain}";
29 let ctlDir = listCtl d l; in
31 for DIR in incoming queue queue/discarded archive text subconf unsubconf \
32 bounce control moderation subscribers.d digesters.d requeue \
35 mkdir -p '${listDir d l}'/"$DIR"
37 ${pkgs.coreutils}/bin/mkdir -p ${ctlDir}
38 echo ${listAddress d l} > '${ctlDir}/listaddress'
39 [ ! -e ${ctlDir}/customheaders ] && \
40 echo "${lib.concatStringsSep "\n" (customHeaders d l)}" > '${ctlDir}/customheaders'
41 [ ! -e ${ctlDir}/footer ] && \
42 echo ${footer d l} > '${ctlDir}/footer'
43 [ ! -e ${ctlDir}/prefix ] && \
44 echo ${subjectPrefix l} > '${ctlDir}/prefix'
59 description = lib.mdDoc "Enable mlmmj";
65 description = lib.mdDoc "mailinglist local user";
71 description = lib.mdDoc "mailinglist local group";
74 listDomain = mkOption {
76 default = "localhost";
77 description = lib.mdDoc "Set the mailing list domain";
80 mailLists = mkOption {
81 type = types.listOf types.str;
83 description = lib.mdDoc "The collection of hosted maillists";
86 maintInterval = mkOption {
89 description = lib.mdDoc ''
90 Time interval between mlmmj-maintd runs, see
91 {manpage}`systemd.time(7)` for format information.
101 config = mkIf cfg.enable {
103 users.users.${cfg.user} = {
104 description = "mlmmj user";
107 uid = config.ids.uids.mlmmj;
109 useDefaultShell = true;
112 users.groups.${cfg.group} = {
113 gid = config.ids.gids.mlmmj;
118 recipientDelimiter= "+";
119 masterConfig.mlmmj = {
129 "argv=${pkgs.mlmmj}/bin/mlmmj-receive"
132 "${spoolDir}/$nexthop"
136 extraAliases = concatMapLines (alias cfg.listDomain) cfg.mailLists;
138 extraConfig = "propagate_unmatched_extensions = virtual";
140 virtual = concatMapLines (virtual cfg.listDomain) cfg.mailLists;
141 transport = concatMapLines (transport cfg.listDomain) cfg.mailLists;
144 environment.systemPackages = [ pkgs.mlmmj ];
146 system.activationScripts.mlmmj = ''
147 ${pkgs.coreutils}/bin/mkdir -p ${stateDir} ${spoolDir}/${cfg.listDomain}
148 ${pkgs.coreutils}/bin/chown -R ${cfg.user}:${cfg.group} ${spoolDir}
149 ${concatMapLines (createList cfg.listDomain) cfg.mailLists}
150 ${pkgs.postfix}/bin/postmap /etc/postfix/virtual
151 ${pkgs.postfix}/bin/postmap /etc/postfix/transport
154 systemd.services.mlmmj-maintd = {
155 description = "mlmmj maintenance daemon";
159 ExecStart = "${pkgs.mlmmj}/bin/mlmmj-maintd -F -d ${spoolDir}/${cfg.listDomain}";
163 systemd.timers.mlmmj-maintd = {
164 description = "mlmmj maintenance timer";
165 timerConfig.OnUnitActiveSec = cfg.maintInterval;
166 wantedBy = [ "timers.target" ];