1
0
Fork 1
mirror of https://github.com/NixOS/nixpkgs.git synced 2024-12-24 10:56:56 +00:00
nixpkgs/nixos/modules/services/mail/mlmmj.nix

155 lines
4.6 KiB
Nix
Raw Normal View History

2014-07-08 23:43:26 +01:00
{ config, lib, pkgs, ... }:
with lib;
let
concatMapLines = f: l: lib.concatStringsSep "\n" (map f l);
2014-07-08 23:43:26 +01: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";
alias = domain: list: "${list}: \"|${pkgs.mlmmj}/bin/mlmmj-receive -L ${listDir domain list}/\"";
2014-07-08 23:43:26 +01:00
subjectPrefix = list: "[${list}]";
listAddress = domain: list: "${list}@${domain}";
customHeaders = domain: list: [ "List-Id: ${list}" "Reply-To: ${list}@${domain}" ];
2014-07-08 23:43:26 +01:00
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'
'';
2014-07-08 23:43:26 +01:00
in
{
###### interface
options = {
services.mlmmj = {
enable = mkOption {
type = types.bool;
default = false;
description = "Enable mlmmj";
};
user = mkOption {
type = types.str;
default = "mlmmj";
description = "mailinglist local user";
};
group = mkOption {
type = types.str;
default = "mlmmj";
description = "mailinglist local group";
};
listDomain = mkOption {
type = types.str;
default = "localhost";
description = "Set the mailing list domain";
};
mailLists = mkOption {
type = types.listOf types.str;
default = [];
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.
'';
};
2014-07-08 23:43:26 +01:00
};
};
###### implementation
config = mkIf cfg.enable {
users.users.${cfg.user} = {
2014-07-08 23:43:26 +01:00
description = "mlmmj user";
home = stateDir;
createHome = true;
uid = config.ids.uids.mlmmj;
group = cfg.group;
useDefaultShell = true;
};
users.groups.${cfg.group} = {
2014-07-08 23:43:26 +01:00
gid = config.ids.gids.mlmmj;
};
services.postfix = {
enable = true;
recipientDelimiter= "+";
2014-07-08 23:43:26 +01:00
extraMasterConf = ''
mlmmj unix - n n - - pipe flags=ORhu user=mlmmj argv=${pkgs.mlmmj}/bin/mlmmj-receive -F -L ${spoolDir}/$nexthop
2014-07-08 23:43:26 +01:00
'';
extraAliases = concatMapLines (alias cfg.listDomain) cfg.mailLists;
2014-07-08 23:43:26 +01:00
extraConfig = ''
transport_maps = hash:${stateDir}/transports
virtual_alias_maps = hash:${stateDir}/virtuals
propagate_unmatched_extensions = virtual
2014-07-08 23:43:26 +01: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}
${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
'';
2014-07-08 23:43:26 +01:00
2019-08-13 22:52:01 +01:00
systemd.services.mlmmj-maintd = {
2014-07-08 23:43:26 +01: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 22:52:01 +01:00
systemd.timers.mlmmj-maintd = {
description = "mlmmj maintenance timer";
timerConfig.OnUnitActiveSec = cfg.maintInterval;
wantedBy = [ "timers.target" ];
};
2014-07-08 23:43:26 +01:00
};
}