diff options
author | Linus Heckemann <git@sphalerite.org> | 2020-05-22 16:52:10 +0200 |
---|---|---|
committer | Linus Heckemann <git@sphalerite.org> | 2020-06-18 17:23:33 +0200 |
commit | 3dbbc786f51eb3f74fc75b1d179b3c447e315ecc (patch) | |
tree | 2a9bf57434315ba9298af0c645eadfbce3d4187d /nixos | |
parent | 1b8af3e1ae75df048fbdfb3acf6842f13de3e38f (diff) |
nixos/mailman: RFC42-ise
Diffstat (limited to 'nixos')
-rw-r--r-- | nixos/modules/services/mail/mailman.nix | 67 |
1 files changed, 37 insertions, 30 deletions
diff --git a/nixos/modules/services/mail/mailman.nix b/nixos/modules/services/mail/mailman.nix index 7f9a7cc072ee7..a604f32b33716 100644 --- a/nixos/modules/services/mail/mailman.nix +++ b/nixos/modules/services/mail/mailman.nix @@ -13,7 +13,7 @@ let # This deliberately doesn't use recursiveUpdate so users can # override the defaults. - settings = { + webSettings = { DEFAULT_FROM_EMAIL = cfg.siteOwner; SERVER_EMAIL = cfg.siteOwner; ALLOWED_HOSTS = [ "localhost" "127.0.0.1" ] ++ cfg.webHosts; @@ -31,7 +31,7 @@ let }; } // cfg.webSettings; - settingsJSON = pkgs.writeText "settings.json" (builtins.toJSON settings); + webSettingsJSON = pkgs.writeText "settings.json" (builtins.toJSON webSettings); # TODO: Should this be RFC42-ised so that users can set additional options without modifying the module? mtaConfig = pkgs.writeText "mailman-postfix.cfg" '' @@ -40,31 +40,7 @@ let transport_file_type: hash ''; - mailmanCfg = '' - [mailman] - site_owner: ${cfg.siteOwner} - layout: fhs - - [paths.fhs] - bin_dir: ${pkgs.python3Packages.mailman}/bin - var_dir: /var/lib/mailman - queue_dir: $var_dir/queue - template_dir: $var_dir/templates - log_dir: /var/log/mailman - lock_dir: $var_dir/lock - etc_dir: /etc - ext_dir: $etc_dir/mailman.d - pid_file: /run/mailman/master.pid - - [mta] - configuration: ${mtaConfig} - '' + optionalString cfg.hyperkitty.enable '' - - [archiver.hyperkitty] - class: mailman_hyperkitty.Archiver - enable: yes - configuration: /var/lib/mailman/mailman-hyperkitty.cfg - ''; + mailmanCfg = lib.generators.toINI {} cfg.settings; mailmanHyperkittyCfg = pkgs.writeText "mailman-hyperkitty.cfg" '' [general] @@ -160,6 +136,12 @@ in { default = []; }; + settings = mkOption { + description = "Settings for mailman.cfg"; + type = types.attrsOf (types.attrsOf types.str); + default = {}; + }; + hyperkitty = { enable = mkEnableOption "the Hyperkitty archiver for Mailman"; @@ -180,6 +162,31 @@ in { config = mkIf cfg.enable { + services.mailman.settings = { + mailman.site_owner = lib.mkDefault cfg.siteOwner; + mailman.layout = "fhs"; + + "paths.fhs" = { + bin_dir = "${pkgs.python3Packages.mailman}/bin"; + var_dir = "/var/lib/mailman"; + queue_dir = "$var_dir/queue"; + template_dir = "$var_dir/templates"; + log_dir = "/var/log/mailman"; + lock_dir = "$var_dir/lock"; + etc_dir = "/etc"; + ext_dir = "$etc_dir/mailman.d"; + pid_file = "/run/mailman/master.pid"; + }; + + mta.configuration = lib.mkDefault "${mtaConfig}"; + + "archiver.hyperkitty" = lib.mkIf cfg.hyperkitty.enable { + class = "mailman_hyperkitty.Archiver"; + enable = "yes"; + configuration = "/var/lib/mailman/mailman-hyperkitty.cfg"; + }; + }; + assertions = let inherit (config.services) postfix; @@ -230,7 +237,7 @@ in { import json - with open('${settingsJSON}') as f: + with open('${webSettingsJSON}') as f: globals().update(json.load(f)) with open('/var/lib/mailman-web/settings_local.json') as f: @@ -243,7 +250,7 @@ in { serverAliases = cfg.webHosts; locations = { "/".extraConfig = "uwsgi_pass unix:/run/mailman-web.socket;"; - "/static/".alias = settings.STATIC_ROOT + "/"; + "/static/".alias = webSettings.STATIC_ROOT + "/"; }; }; }; @@ -334,7 +341,7 @@ in { requiredBy = [ "mailman-uwsgi.service" ]; restartTriggers = [ config.environment.etc."mailman3/settings.py".source ]; script = '' - [[ -e "${settings.STATIC_ROOT}" ]] && find "${settings.STATIC_ROOT}/" -mindepth 1 -delete + [[ -e "${webSettings.STATIC_ROOT}" ]] && find "${webSettings.STATIC_ROOT}/" -mindepth 1 -delete ${pythonEnv}/bin/mailman-web migrate ${pythonEnv}/bin/mailman-web collectstatic ${pythonEnv}/bin/mailman-web compress |