2014-07-08 22:43:26 +00:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
|
2017-05-12 15:05:41 +00:00
|
|
|
concatMapLines = f: l: lib.concatStringsSep "\n" (map f l);
|
|
|
|
|
2014-07-08 22:43:26 +00:00
|
|
|
cfg = config.services.mlmmj;
|
|
|
|
stateDir = "/var/lib/mlmmj";
|
|
|
|
spoolDir = "/var/spool/mlmmj";
|
|
|
|
listDir = domain: list: "${spoolDir}/${domain}/${list}";
|
|
|
|
listCtl = domain: list: "${listDir domain list}/control";
|
|
|
|
transport = domain: list: "${domain}--${list}@local.list.mlmmj mlmmj:${domain}/${list}";
|
|
|
|
virtual = domain: list: "${list}@${domain} ${domain}--${list}@local.list.mlmmj";
|
2015-08-25 13:27:58 +00:00
|
|
|
alias = domain: list: "${list}: \"|${pkgs.mlmmj}/bin/mlmmj-receive -L ${listDir domain list}/\"";
|
2014-07-08 22:43:26 +00:00
|
|
|
subjectPrefix = list: "[${list}]";
|
|
|
|
listAddress = domain: list: "${list}@${domain}";
|
2019-05-28 14:47:16 +00:00
|
|
|
customHeaders = domain: list: [
|
|
|
|
"List-Id: ${list}"
|
|
|
|
"Reply-To: ${list}@${domain}"
|
|
|
|
"List-Post: <mailto:${list}@${domain}>"
|
|
|
|
"List-Help: <mailto:${list}+help@${domain}>"
|
|
|
|
"List-Subscribe: <mailto:${list}+subscribe@${domain}>"
|
|
|
|
"List-Unsubscribe: <mailto:${list}+unsubscribe@${domain}>"
|
|
|
|
];
|
2014-07-08 22:43:26 +00:00
|
|
|
footer = domain: list: "To unsubscribe send a mail to ${list}+unsubscribe@${domain}";
|
2017-05-12 15:05:41 +00:00
|
|
|
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'
|
|
|
|
'';
|
2014-07-08 22:43:26 +00:00
|
|
|
in
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
###### interface
|
|
|
|
|
|
|
|
options = {
|
|
|
|
|
|
|
|
services.mlmmj = {
|
|
|
|
|
|
|
|
enable = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
2022-07-28 21:19:15 +00:00
|
|
|
description = lib.mdDoc "Enable mlmmj";
|
2014-07-08 22:43:26 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
user = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "mlmmj";
|
2022-07-28 21:19:15 +00:00
|
|
|
description = lib.mdDoc "mailinglist local user";
|
2014-07-08 22:43:26 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
group = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "mlmmj";
|
2022-07-28 21:19:15 +00:00
|
|
|
description = lib.mdDoc "mailinglist local group";
|
2014-07-08 22:43:26 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
listDomain = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "localhost";
|
2022-07-28 21:19:15 +00:00
|
|
|
description = lib.mdDoc "Set the mailing list domain";
|
2014-07-08 22:43:26 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
mailLists = mkOption {
|
|
|
|
type = types.listOf types.str;
|
|
|
|
default = [];
|
2022-07-28 21:19:15 +00:00
|
|
|
description = lib.mdDoc "The collection of hosted maillists";
|
2014-07-08 22:43:26 +00:00
|
|
|
};
|
|
|
|
|
2017-05-12 15:05:41 +00:00
|
|
|
maintInterval = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "20min";
|
2022-08-05 17:39:00 +00:00
|
|
|
description = lib.mdDoc ''
|
2017-05-12 15:05:41 +00:00
|
|
|
Time interval between mlmmj-maintd runs, see
|
2022-08-05 17:39:00 +00:00
|
|
|
{manpage}`systemd.time(7)` for format information.
|
2017-05-12 15:05:41 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2014-07-08 22:43:26 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
###### implementation
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
|
|
|
|
2019-09-14 17:51:29 +00:00
|
|
|
users.users.${cfg.user} = {
|
2014-07-08 22:43:26 +00:00
|
|
|
description = "mlmmj user";
|
|
|
|
home = stateDir;
|
|
|
|
createHome = true;
|
|
|
|
uid = config.ids.uids.mlmmj;
|
|
|
|
group = cfg.group;
|
|
|
|
useDefaultShell = true;
|
|
|
|
};
|
|
|
|
|
2019-09-14 17:51:29 +00:00
|
|
|
users.groups.${cfg.group} = {
|
2014-07-08 22:43:26 +00:00
|
|
|
gid = config.ids.gids.mlmmj;
|
|
|
|
};
|
|
|
|
|
|
|
|
services.postfix = {
|
|
|
|
enable = true;
|
2015-06-26 12:03:21 +00:00
|
|
|
recipientDelimiter= "+";
|
2019-05-28 14:39:17 +00:00
|
|
|
masterConfig.mlmmj = {
|
|
|
|
type = "unix";
|
|
|
|
private = true;
|
|
|
|
privileged = true;
|
|
|
|
chroot = false;
|
|
|
|
wakeup = 0;
|
|
|
|
command = "pipe";
|
|
|
|
args = [
|
|
|
|
"flags=ORhu"
|
|
|
|
"user=mlmmj"
|
|
|
|
"argv=${pkgs.mlmmj}/bin/mlmmj-receive"
|
|
|
|
"-F"
|
|
|
|
"-L"
|
|
|
|
"${spoolDir}/$nexthop"
|
|
|
|
];
|
|
|
|
};
|
2014-07-08 22:43:26 +00:00
|
|
|
|
2017-05-12 15:05:41 +00:00
|
|
|
extraAliases = concatMapLines (alias cfg.listDomain) cfg.mailLists;
|
2014-07-08 22:43:26 +00:00
|
|
|
|
2019-05-28 14:39:17 +00:00
|
|
|
extraConfig = "propagate_unmatched_extensions = virtual";
|
|
|
|
|
|
|
|
virtual = concatMapLines (virtual cfg.listDomain) cfg.mailLists;
|
|
|
|
transport = concatMapLines (transport cfg.listDomain) cfg.mailLists;
|
2014-07-08 22:43:26 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
environment.systemPackages = [ pkgs.mlmmj ];
|
|
|
|
|
|
|
|
system.activationScripts.mlmmj = ''
|
|
|
|
${pkgs.coreutils}/bin/mkdir -p ${stateDir} ${spoolDir}/${cfg.listDomain}
|
|
|
|
${pkgs.coreutils}/bin/chown -R ${cfg.user}:${cfg.group} ${spoolDir}
|
2017-05-12 15:05:41 +00:00
|
|
|
${concatMapLines (createList cfg.listDomain) cfg.mailLists}
|
2019-05-28 14:39:17 +00:00
|
|
|
${pkgs.postfix}/bin/postmap /etc/postfix/virtual
|
|
|
|
${pkgs.postfix}/bin/postmap /etc/postfix/transport
|
2015-09-16 07:31:38 +00:00
|
|
|
'';
|
2014-07-08 22:43:26 +00:00
|
|
|
|
2019-08-13 21:52:01 +00:00
|
|
|
systemd.services.mlmmj-maintd = {
|
2014-07-08 22:43:26 +00:00
|
|
|
description = "mlmmj maintenance daemon";
|
|
|
|
serviceConfig = {
|
|
|
|
User = cfg.user;
|
|
|
|
Group = cfg.group;
|
|
|
|
ExecStart = "${pkgs.mlmmj}/bin/mlmmj-maintd -F -d ${spoolDir}/${cfg.listDomain}";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2019-08-13 21:52:01 +00:00
|
|
|
systemd.timers.mlmmj-maintd = {
|
2017-05-12 15:05:41 +00:00
|
|
|
description = "mlmmj maintenance timer";
|
|
|
|
timerConfig.OnUnitActiveSec = cfg.maintInterval;
|
|
|
|
wantedBy = [ "timers.target" ];
|
|
|
|
};
|
2014-07-08 22:43:26 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|