about summary refs log tree commit diff
path: root/nixpkgs/nixos
diff options
context:
space:
mode:
authorAlyssa Ross <hi@alyssa.is>2021-01-06 10:33:45 +0000
committerAlyssa Ross <hi@alyssa.is>2021-01-06 10:46:07 +0000
commit9270b74fb4c6d4a21b86e5492dc43d78d8e05a03 (patch)
tree19ef5a6e680618bd95ad9867d218d14f7b338cdd /nixpkgs/nixos
parent3641350f6bca02b02d7675fc7349f56bc7a16c85 (diff)
downloadnixlib-9270b74fb4c6d4a21b86e5492dc43d78d8e05a03.tar
nixlib-9270b74fb4c6d4a21b86e5492dc43d78d8e05a03.tar.gz
nixlib-9270b74fb4c6d4a21b86e5492dc43d78d8e05a03.tar.bz2
nixlib-9270b74fb4c6d4a21b86e5492dc43d78d8e05a03.tar.lz
nixlib-9270b74fb4c6d4a21b86e5492dc43d78d8e05a03.tar.xz
nixlib-9270b74fb4c6d4a21b86e5492dc43d78d8e05a03.tar.zst
nixlib-9270b74fb4c6d4a21b86e5492dc43d78d8e05a03.zip
nixos/mailman: add services.mailman.serve
Extracted from
b478e0043c53964c99cc9a145c155a673af3c7d8 ("nixos/mailman: refactor"),
to bring myself closer to current upstream.
Diffstat (limited to 'nixpkgs/nixos')
-rw-r--r--nixpkgs/nixos/modules/services/mail/mailman.nix51
1 files changed, 47 insertions, 4 deletions
diff --git a/nixpkgs/nixos/modules/services/mail/mailman.nix b/nixpkgs/nixos/modules/services/mail/mailman.nix
index 26d05db3caa4..5da4171605b1 100644
--- a/nixpkgs/nixos/modules/services/mail/mailman.nix
+++ b/nixpkgs/nixos/modules/services/mail/mailman.nix
@@ -145,6 +145,10 @@ in {
         '';
       };
 
+      serve = {
+        enable = mkEnableOption "Automatic nginx and uwsgi setup for mailman-web";
+      };
+
       hyperkitty = {
         enable = mkEnableOption "the Hyperkitty archiver for Mailman";
 
@@ -228,6 +232,17 @@ in {
           globals().update(json.load(f))
     '';
 
+    services.nginx = mkIf cfg.serve.enable {
+      enable = mkDefault true;
+      virtualHosts."${lib.head cfg.webHosts}" = {
+        serverAliases = cfg.webHosts;
+        locations = {
+          "/".extraConfig = "uwsgi_pass unix:/run/mailman-web.socket;";
+          "/static/".alias = settings.STATIC_ROOT + "/";
+        };
+      };
+    };
+
     environment.systemPackages = [ cfg.package ] ++ (with pkgs; [ mailman-web ]);
 
     services.postfix = {
@@ -237,6 +252,11 @@ in {
       };
     };
 
+    systemd.sockets.mailman-uwsgi = lib.mkIf cfg.serve.enable {
+      wantedBy = ["sockets.target"];
+      before = ["nginx.service"];
+      socketConfig.ListenStream = "/run/mailman-web.socket";
+    };
     systemd.services = {
       mailman = {
         description = "GNU Mailman Master Process";
@@ -257,8 +277,8 @@ in {
 
       mailman-settings = {
         description = "Generate settings files (including secrets) for Mailman";
-        before = [ "mailman.service" "mailman-web-setup.service" "hyperkitty.service" "httpd.service" "uwsgi.service" ];
-        requiredBy = [ "mailman.service" "mailman-web-setup.service" "hyperkitty.service" "httpd.service" "uwsgi.service" ];
+        before = [ "mailman.service" "mailman-web-setup.service" "mailman-uwsgi.service" "hyperkitty.service" ];
+        requiredBy = [ "mailman.service" "mailman-web-setup.service" "mailman-uwsgi.service" "hyperkitty.service" ];
         path = with pkgs; [ jq ];
         script = ''
           mailmanDir=/var/lib/mailman
@@ -303,8 +323,8 @@ in {
 
       mailman-web-setup = {
         description = "Prepare mailman-web files and database";
-        before = [ "httpd.service" "uwsgi.service" ];
-        requiredBy = [ "httpd.service" "uwsgi.service" ];
+        before = [ "uwsgi.service" "mailman-uwsgi.service" ];
+        requiredBy = [ "mailman-uwsgi.service" ];
         restartTriggers = [ config.environment.etc."mailman3/settings.py".source ];
         script = ''
           if [ -d ${escapeShellArg settings.STATIC_ROOT} ]
@@ -327,6 +347,29 @@ in {
         };
       };
 
+      mailman-uwsgi = mkIf cfg.serve.enable (let
+        uwsgiConfig.uwsgi = {
+          type = "normal";
+          plugins = ["python3"];
+          home = pythonEnv;
+          module = "mailman_web.wsgi";
+        };
+        uwsgiConfigFile = pkgs.writeText "uwsgi-mailman.json" (builtins.toJSON uwsgiConfig);
+      in {
+        wantedBy = ["multi-user.target"];
+        requires = ["mailman-uwsgi.socket" "mailman-web-setup.service"];
+        restartTriggers = [ config.environment.etc."mailman3/settings.py".source ];
+        serviceConfig = {
+          # Since the mailman-web settings.py obstinately creates a logs
+          # dir in the cwd, change to the (writable) runtime directory before
+          # starting uwsgi.
+          ExecStart = "${pkgs.coreutils}/bin/env -C $RUNTIME_DIRECTORY ${pkgs.uwsgi.override { plugins = ["python3"]; }}/bin/uwsgi --json ${uwsgiConfigFile}";
+          User = cfg.webUser;
+          Group = "mailman";
+          RuntimeDirectory = "mailman-uwsgi";
+        };
+      });
+
       mailman-daily = {
         description = "Trigger daily Mailman events";
         startAt = "daily";