From 1615be91ef522cfc9aaeb4eb37b8d3519cd08ea7 Mon Sep 17 00:00:00 2001 From: Edward Tjörnhammar Date: Wed, 9 Jul 2014 00:43:26 +0200 Subject: Add mlmmj package and nixos module. --- nixos/modules/misc/ids.nix | 2 + nixos/modules/module-list.nix | 1 + nixos/modules/services/mail/mlmmj.nix | 128 ++++++++++++++++++++++++++++++++++ 3 files changed, 131 insertions(+) create mode 100644 nixos/modules/services/mail/mlmmj.nix (limited to 'nixos/modules') diff --git a/nixos/modules/misc/ids.nix b/nixos/modules/misc/ids.nix index 9f509ba8cb94..b49837efd50e 100644 --- a/nixos/modules/misc/ids.nix +++ b/nixos/modules/misc/ids.nix @@ -142,6 +142,7 @@ gdm = 132; dhcpd = 133; siproxd = 134; + mlmmj = 135; # When adding a uid, make sure it doesn't match an existing gid. And don't use uids above 399! @@ -258,6 +259,7 @@ gdm = 132; tss = 133; siproxd = 134; + mlmmj = 135; # When adding a gid, make sure it doesn't match an existing uid. And don't use gids above 399! diff --git a/nixos/modules/module-list.nix b/nixos/modules/module-list.nix index 1fc2959bd8a0..c25110fc5b14 100644 --- a/nixos/modules/module-list.nix +++ b/nixos/modules/module-list.nix @@ -142,6 +142,7 @@ ./services/mail/dovecot.nix ./services/mail/freepops.nix ./services/mail/mail.nix + ./services/mail/mlmmj.nix ./services/mail/opensmtpd.nix ./services/mail/postfix.nix ./services/mail/spamassassin.nix diff --git a/nixos/modules/services/mail/mlmmj.nix b/nixos/modules/services/mail/mlmmj.nix new file mode 100644 index 000000000000..637974f05cd1 --- /dev/null +++ b/nixos/modules/services/mail/mlmmj.nix @@ -0,0 +1,128 @@ +{ config, lib, pkgs, ... }: + +with lib; + +let + + 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}/mlmmj-receive -L ${listDir domain list}/\""; + subjectPrefix = list: "[${list}]"; + listAddress = domain: list: "${list}@${domain}"; + customHeaders = list: domain: [ "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}/listadress + 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 + ''; +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"; + }; + + }; + + }; + + ###### implementation + + config = mkIf cfg.enable { + + users.extraUsers = singleton { + name = cfg.user; + description = "mlmmj user"; + home = stateDir; + createHome = true; + uid = config.ids.uids.mlmmj; + group = cfg.group; + useDefaultShell = true; + }; + + users.extraGroups = singleton { + name = cfg.group; + gid = config.ids.gids.mlmmj; + }; + + services.postfix = { + enable = true; + recipientDelimiter= "+"; + extraMasterConf = '' + mlmmj unix - n n - - pipe flags=ORhu user=mlmmj argv=${pkgs.mlmmj}/bin/mlmmj-recieve -F -L ${spoolDir}/$nextHop + ''; + + extraAliases = concatMapStrings (alias cfg.listDomain) cfg.mailLists; + + extraConfig = '' + transport = hash:${stateDir}/transports + virtual = hash:${stateDir}/virtuals + ''; + }; + + 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} + ${lib.concatMapStrings (createList cfg.listDomain) cfg.mailLists} + echo ${lib.concatMapStrings (virtual cfg.listDomain) cfg.mailLists} > ${stateDir}/virtuals + echo ${cfg.listDomain} mailman: > ${stateDir}/transports + echo ${lib.concatMapStrings (transport cfg.listDomain) cfg.mailLists} >> ${stateDir}/transports + ''; + + systemd.services."mlmmj-maintd" = { + description = "mlmmj maintenance daemon"; + wantedBy = [ "multi-user.target" ]; + + serviceConfig = { + User = cfg.user; + Group = cfg.group; + ExecStart = "${pkgs.mlmmj}/bin/mlmmj-maintd -F -d ${spoolDir}/${cfg.listDomain}"; + }; + }; + + }; + +} -- cgit 1.4.1