at 15.09-beta 3.7 kB view raw
1{ config, lib, pkgs, ... }: 2 3with lib; 4 5let 6 7 cfg = config.services.mlmmj; 8 stateDir = "/var/lib/mlmmj"; 9 spoolDir = "/var/spool/mlmmj"; 10 listDir = domain: list: "${spoolDir}/${domain}/${list}"; 11 listCtl = domain: list: "${listDir domain list}/control"; 12 transport = domain: list: "${domain}--${list}@local.list.mlmmj mlmmj:${domain}/${list}"; 13 virtual = domain: list: "${list}@${domain} ${domain}--${list}@local.list.mlmmj"; 14 alias = domain: list: "${list}: \"|${pkgs.mlmmj}/bin/mlmmj-receive -L ${listDir domain list}/\""; 15 subjectPrefix = list: "[${list}]"; 16 listAddress = domain: list: "${list}@${domain}"; 17 customHeaders = list: domain: [ "List-Id: ${list}" "Reply-To: ${list}@${domain}" ]; 18 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}/listadress 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 ''; 26in 27 28{ 29 30 ###### interface 31 32 options = { 33 34 services.mlmmj = { 35 36 enable = mkOption { 37 type = types.bool; 38 default = false; 39 description = "Enable mlmmj"; 40 }; 41 42 user = mkOption { 43 type = types.str; 44 default = "mlmmj"; 45 description = "mailinglist local user"; 46 }; 47 48 group = mkOption { 49 type = types.str; 50 default = "mlmmj"; 51 description = "mailinglist local group"; 52 }; 53 54 listDomain = mkOption { 55 type = types.str; 56 default = "localhost"; 57 description = "Set the mailing list domain"; 58 }; 59 60 mailLists = mkOption { 61 type = types.listOf types.str; 62 default = []; 63 description = "The collection of hosted maillists"; 64 }; 65 66 }; 67 68 }; 69 70 ###### implementation 71 72 config = mkIf cfg.enable { 73 74 users.extraUsers = singleton { 75 name = cfg.user; 76 description = "mlmmj user"; 77 home = stateDir; 78 createHome = true; 79 uid = config.ids.uids.mlmmj; 80 group = cfg.group; 81 useDefaultShell = true; 82 }; 83 84 users.extraGroups = singleton { 85 name = cfg.group; 86 gid = config.ids.gids.mlmmj; 87 }; 88 89 services.postfix = { 90 enable = true; 91 recipientDelimiter= "+"; 92 extraMasterConf = '' 93 mlmmj unix - n n - - pipe flags=ORhu user=mlmmj argv=${pkgs.mlmmj}/bin/mlmmj-receive -F -L ${spoolDir}/$nextHop 94 ''; 95 96 extraAliases = concatMapStrings (alias cfg.listDomain) cfg.mailLists; 97 98 extraConfig = '' 99 transport = hash:${stateDir}/transports 100 virtual = hash:${stateDir}/virtuals 101 ''; 102 }; 103 104 environment.systemPackages = [ pkgs.mlmmj ]; 105 106 system.activationScripts.mlmmj = '' 107 ${pkgs.coreutils}/bin/mkdir -p ${stateDir} ${spoolDir}/${cfg.listDomain} 108 ${pkgs.coreutils}/bin/chown -R ${cfg.user}:${cfg.group} ${spoolDir} 109 ${lib.concatMapStrings (createList cfg.listDomain) cfg.mailLists} 110 echo ${lib.concatMapStrings (virtual cfg.listDomain) cfg.mailLists} > ${stateDir}/virtuals 111 echo ${cfg.listDomain} mailman: > ${stateDir}/transports 112 echo ${lib.concatMapStrings (transport cfg.listDomain) cfg.mailLists} >> ${stateDir}/transports 113 ''; 114 115 systemd.services."mlmmj-maintd" = { 116 description = "mlmmj maintenance daemon"; 117 wantedBy = [ "multi-user.target" ]; 118 119 serviceConfig = { 120 User = cfg.user; 121 Group = cfg.group; 122 ExecStart = "${pkgs.mlmmj}/bin/mlmmj-maintd -F -d ${spoolDir}/${cfg.listDomain}"; 123 }; 124 }; 125 126 }; 127 128}