summary refs log tree commit diff
path: root/host/Rory-nginx/services/matrix/synapse/workers
diff options
context:
space:
mode:
Diffstat (limited to 'host/Rory-nginx/services/matrix/synapse/workers')
-rw-r--r--host/Rory-nginx/services/matrix/synapse/workers/appservice.nix15
-rw-r--r--host/Rory-nginx/services/matrix/synapse/workers/background.nix15
-rw-r--r--host/Rory-nginx/services/matrix/synapse/workers/client-reader.nix26
-rw-r--r--host/Rory-nginx/services/matrix/synapse/workers/federation-inbound.nix32
-rw-r--r--host/Rory-nginx/services/matrix/synapse/workers/federation-reader.nix30
-rw-r--r--host/Rory-nginx/services/matrix/synapse/workers/federation-sender.nix36
-rw-r--r--host/Rory-nginx/services/matrix/synapse/workers/media-repo.nix38
-rw-r--r--host/Rory-nginx/services/matrix/synapse/workers/module.nix16
-rw-r--r--host/Rory-nginx/services/matrix/synapse/workers/pusher.nix19
-rw-r--r--host/Rory-nginx/services/matrix/synapse/workers/stream-writers/__OLD__module.nix87
-rw-r--r--host/Rory-nginx/services/matrix/synapse/workers/stream-writers/event-stream-writer.nix7
-rw-r--r--host/Rory-nginx/services/matrix/synapse/workers/sync.nix26
-rw-r--r--host/Rory-nginx/services/matrix/synapse/workers/user-dir.nix8
13 files changed, 115 insertions, 240 deletions
diff --git a/host/Rory-nginx/services/matrix/synapse/workers/appservice.nix b/host/Rory-nginx/services/matrix/synapse/workers/appservice.nix
index d259edd..e3b07bc 100644
--- a/host/Rory-nginx/services/matrix/synapse/workers/appservice.nix
+++ b/host/Rory-nginx/services/matrix/synapse/workers/appservice.nix
@@ -1,23 +1,20 @@
-{
-  config,
-  pkgs,
-  lib,
-  ...
-}:
+{ config, lib, ... }:
 
 let
   cfg = config.services.matrix-synapse;
+  workerName = "appservice";
+  workerRoutes = [ ];
 in
 {
   services.matrix-synapse = lib.mkIf cfg.enableAppserviceWorker {
     settings = {
       instance_map = {
         appservice = {
-          path = "/run/matrix-synapse/appservice.sock";
+          path = "/run/matrix-synapse/${workerName}.sock";
         };
       };
 
-      notify_appservices_from_worker = "appservice";
+      notify_appservices_from_worker = workerName;
     };
 
     workers = {
@@ -26,7 +23,7 @@ in
         worker_listeners = [
           {
             type = "http";
-            path = "/run/matrix-synapse/appservice.sock";
+            path = "/run/matrix-synapse/${workerName}.sock";
             resources = [
               {
                 names = [ "replication" ];
diff --git a/host/Rory-nginx/services/matrix/synapse/workers/background.nix b/host/Rory-nginx/services/matrix/synapse/workers/background.nix
index 501299a..611f6eb 100644
--- a/host/Rory-nginx/services/matrix/synapse/workers/background.nix
+++ b/host/Rory-nginx/services/matrix/synapse/workers/background.nix
@@ -1,23 +1,20 @@
-{
-  config,
-  pkgs,
-  lib,
-  ...
-}:
+{ config, lib, ... }:
 
 let
   cfg = config.services.matrix-synapse;
+  workerName = "background";
+  workerRoutes = [ ];
 in
 {
   services.matrix-synapse = lib.mkIf cfg.enableBackgroundWorker {
     settings = {
       instance_map = {
         background = {
-          path = "/run/matrix-synapse/background.sock";
+          path = "/run/matrix-synapse/${workerName}.sock";
         };
       };
 
-      run_background_tasks_on = "background";
+      run_background_tasks_on = workerName;
     };
 
     workers = {
@@ -26,7 +23,7 @@ in
         worker_listeners = [
           {
             type = "http";
-            path = "/run/matrix-synapse/background.sock";
+            path = "/run/matrix-synapse/${workerName}.sock";
             resources = [
               {
                 names = [ "replication" ];
diff --git a/host/Rory-nginx/services/matrix/synapse/workers/client-reader.nix b/host/Rory-nginx/services/matrix/synapse/workers/client-reader.nix
index ff7352b..c89b147 100644
--- a/host/Rory-nginx/services/matrix/synapse/workers/client-reader.nix
+++ b/host/Rory-nginx/services/matrix/synapse/workers/client-reader.nix
@@ -1,13 +1,9 @@
-{
-  config,
-  pkgs,
-  lib,
-  ...
-}:
+{ config, lib, ... }:
 
 let
   cfg = config.services.matrix-synapse;
   workers = lib.range 0 (cfg.clientReaders - 1);
+  workerName = "client_reader";
   routes = [
     "~ ^/_matrix/client/(api/v1|r0|v3|unstable)/publicRooms$"
     "~ ^/_matrix/client/(api/v1|r0|v3|unstable)/rooms/.*/joined_members$"
@@ -44,9 +40,9 @@ in
       settings = {
         instance_map = lib.listToAttrs (
           lib.map (index: {
-            name = "client_reader-${toString index}";
+            name = "${workerName}-${toString index}";
             value = {
-              path = "/run/matrix-synapse/client_reader-${toString index}.sock";
+              path = "/run/matrix-synapse/${workerName}-${toString index}.sock";
             };
           }) workers
         );
@@ -54,13 +50,13 @@ in
 
       workers = lib.listToAttrs (
         lib.map (index: {
-          name = "client_reader-${toString index}";
+          name = "${workerName}-${toString index}";
           value = {
             worker_app = "synapse.app.generic_worker";
             worker_listeners = [
               {
                 type = "http";
-                path = "/run/matrix-synapse/client_reader-${toString index}.sock";
+                path = "/run/matrix-synapse/${workerName}-${toString index}.sock";
                 resources = [
                   {
                     names = [ "replication" ];
@@ -70,7 +66,7 @@ in
               }
               {
                 type = "http";
-                path = "/run/matrix-synapse/client_reader-client-${toString index}.sock";
+                path = "/run/matrix-synapse/${workerName}-client-${toString index}.sock";
                 mode = "666";
                 resources = [
                   {
@@ -82,7 +78,7 @@ in
             ];
             database = (
               import ../db.nix {
-                workerName = "client_reader-${toString index}";
+                workerName = "${workerName}-${toString index}";
                 dbGroup = "medium";
               }
             );
@@ -91,13 +87,13 @@ in
       );
     };
 
-    services.nginx.upstreams."client_reader" = {
+    services.nginx.upstreams."${workerName}" = {
       extraConfig = ''
         keepalive 32;
       '';
       servers = lib.listToAttrs (
         lib.map (index: {
-          name = "unix:/run/matrix-synapse/client_reader-client-${toString index}.sock";
+          name = "unix:/run/matrix-synapse/${workerName}-client-${toString index}.sock";
           value = {
             max_fails = 0;
           };
@@ -109,7 +105,7 @@ in
       lib.map (route: {
         name = route;
         value = {
-          proxyPass = "http://client_reader";
+          proxyPass = "http://${workerName}";
         };
       }) routes
     );
diff --git a/host/Rory-nginx/services/matrix/synapse/workers/federation-inbound.nix b/host/Rory-nginx/services/matrix/synapse/workers/federation-inbound.nix
index 9853601..2e3574f 100644
--- a/host/Rory-nginx/services/matrix/synapse/workers/federation-inbound.nix
+++ b/host/Rory-nginx/services/matrix/synapse/workers/federation-inbound.nix
@@ -1,16 +1,10 @@
-{
-  config,
-  pkgs,
-  lib,
-  ...
-}:
+{ config, lib, ... }:
 
 let
   cfg = config.services.matrix-synapse;
   workers = lib.range 0 (cfg.federationReaders - 1);
-  routes = [
-    "~ /_matrix/federation/(v1|v2)/send/"
-  ];
+  workerName = "federation_inbound";
+  workerRoutes = [ "~ /_matrix/federation/(v1|v2)/send/" ];
 in
 {
   config = lib.mkIf (cfg.federationInboundWorkers > 0) {
@@ -18,9 +12,9 @@ in
       settings = {
         instance_map = lib.listToAttrs (
           lib.map (index: {
-            name = "federation_inbound-${toString index}";
+            name = "${workerName}-${toString index}";
             value = {
-              path = "/run/matrix-synapse/federation_inbound-${toString index}.sock";
+              path = "/run/matrix-synapse/${workerName}-${toString index}.sock";
             };
           }) workers
         );
@@ -28,13 +22,13 @@ in
 
       workers = lib.listToAttrs (
         lib.map (index: {
-          name = "federation_inbound-${toString index}";
+          name = "${workerName}-${toString index}";
           value = {
             worker_app = "synapse.app.generic_worker";
             worker_listeners = [
               {
                 type = "http";
-                path = "/run/matrix-synapse/federation_inbound-${toString index}.sock";
+                path = "/run/matrix-synapse/${workerName}-${toString index}.sock";
                 resources = [
                   {
                     names = [ "replication" ];
@@ -44,7 +38,7 @@ in
               }
               {
                 type = "http";
-                path = "/run/matrix-synapse/federation_inbound-federation-${toString index}.sock";
+                path = "/run/matrix-synapse/${workerName}-federation-${toString index}.sock";
                 mode = "666";
                 resources = [
                   {
@@ -56,7 +50,7 @@ in
             ];
             database = (
               import ../db.nix {
-                workerName = "federation_inbound-${toString index}";
+                workerName = "${workerName}-${toString index}";
                 dbGroup = "medium";
               }
             );
@@ -65,14 +59,14 @@ in
       );
     };
 
-    services.nginx.upstreams."federation_inbound" = {
+    services.nginx.upstreams."${workerName}" = {
       extraConfig = ''
         keepalive 32;
         ip_hash;
       '';
       servers = lib.listToAttrs (
         lib.map (index: {
-          name = "unix:/run/matrix-synapse/federation_inbound-federation-${toString index}.sock";
+          name = "unix:/run/matrix-synapse/${workerName}-federation-${toString index}.sock";
           value = {
             max_fails = 0;
           };
@@ -84,9 +78,9 @@ in
       lib.map (route: {
         name = route;
         value = {
-          proxyPass = "http://federation_inbound";
+          proxyPass = "http://${workerName}";
         };
-      }) routes
+      }) workerRoutes
     );
   };
 }
diff --git a/host/Rory-nginx/services/matrix/synapse/workers/federation-reader.nix b/host/Rory-nginx/services/matrix/synapse/workers/federation-reader.nix
index 9aafb28..762f82c 100644
--- a/host/Rory-nginx/services/matrix/synapse/workers/federation-reader.nix
+++ b/host/Rory-nginx/services/matrix/synapse/workers/federation-reader.nix
@@ -1,14 +1,10 @@
-{
-  config,
-  pkgs,
-  lib,
-  ...
-}:
+{ config, lib, ... }:
 
 let
   cfg = config.services.matrix-synapse;
   workers = lib.range 0 (cfg.federationReaders - 1);
-  routes = [
+  workerName = "federation_reader";
+  workerRoutes = [
     "~ ^/_matrix/federation/(v1|v2)/event/"
     "~ ^/_matrix/federation/(v1|v2)/state/"
     "~ ^/_matrix/federation/(v1|v2)/state_ids/"
@@ -38,9 +34,9 @@ in
       settings = {
         instance_map = lib.listToAttrs (
           lib.map (index: {
-            name = "federation_reader-${toString index}";
+            name = "${workerName}-${toString index}";
             value = {
-              path = "/run/matrix-synapse/federation_reader-${toString index}.sock";
+              path = "/run/matrix-synapse/${workerName}-${toString index}.sock";
             };
           }) workers
         );
@@ -48,13 +44,13 @@ in
 
       workers = lib.listToAttrs (
         lib.map (index: {
-          name = "federation_reader-${toString index}";
+          name = "${workerName}-${toString index}";
           value = {
             worker_app = "synapse.app.generic_worker";
             worker_listeners = [
               {
                 type = "http";
-                path = "/run/matrix-synapse/federation_reader-${toString index}.sock";
+                path = "/run/matrix-synapse/${workerName}-${toString index}.sock";
                 resources = [
                   {
                     names = [ "replication" ];
@@ -64,7 +60,7 @@ in
               }
               {
                 type = "http";
-                path = "/run/matrix-synapse/federation_reader-federation-${toString index}.sock";
+                path = "/run/matrix-synapse/${workerName}-federation-${toString index}.sock";
                 mode = "666";
                 resources = [
                   {
@@ -76,7 +72,7 @@ in
             ];
             database = (
               import ../db.nix {
-                workerName = "federation_reader-${toString index}";
+                workerName = "${workerName}-${toString index}";
                 dbGroup = "medium";
               }
             );
@@ -85,14 +81,14 @@ in
       );
     };
 
-    services.nginx.upstreams."federation_reader" = {
+    services.nginx.upstreams."${workerName}" = {
       extraConfig = ''
         keepalive 32;
         hash $request_uri consistent;
       '';
       servers = lib.listToAttrs (
         lib.map (index: {
-          name = "unix:/run/matrix-synapse/federation_reader-federation-${toString index}.sock";
+          name = "unix:/run/matrix-synapse/${workerName}-federation-${toString index}.sock";
           value = {
             max_fails = 0;
           };
@@ -104,9 +100,9 @@ in
       lib.map (route: {
         name = route;
         value = {
-          proxyPass = "http://federation_reader";
+          proxyPass = "http://${workerName}";
         };
-      }) routes
+      }) workerRoutes
     );
   };
 }
diff --git a/host/Rory-nginx/services/matrix/synapse/workers/federation-sender.nix b/host/Rory-nginx/services/matrix/synapse/workers/federation-sender.nix
index 4cb137a..391e046 100644
--- a/host/Rory-nginx/services/matrix/synapse/workers/federation-sender.nix
+++ b/host/Rory-nginx/services/matrix/synapse/workers/federation-sender.nix
@@ -1,46 +1,36 @@
-{
-  config,
-  pkgs,
-  lib,
-  ...
-}:
+{ config, lib, ... }:
 let
   cfg = config.services.matrix-synapse;
   federationSenders = lib.range 0 (cfg.federationSenders - 1);
+  workerName = "federation_sender";
+  workerRoutes = [ ];
 in
 {
   services.matrix-synapse = lib.mkIf (cfg.federationSenders > 0) {
     settings = {
       instance_map = lib.listToAttrs (
         lib.map (index: {
-          name = "federation_sender-${toString index}";
+          name = "${workerName}-${toString index}";
           value = {
-            path = "/run/matrix-synapse/federation_sender-${toString index}.sock";
+            path = "/run/matrix-synapse/${workerName}-${toString index}.sock";
           };
         }) federationSenders
       );
       send_federation = false;
-      federation_sender_instances = lib.map (index: "federation_sender-${toString index}") federationSenders;
-      outbound_federation_restricted_to = lib.map (index: "federation_sender-${toString index}") federationSenders;
-      worker_replication_secret = "federation_sender_secret";
-
-      database = (
-        import ../db.nix {
-          workerName = "federation_sender";
-          dbGroup = "solo";
-        }
-      );
+      federation_sender_instances = lib.map (index: "${workerName}-${toString index}") federationSenders;
+      outbound_federation_restricted_to = lib.map (index: "${workerName}-${toString index}") federationSenders;
+      worker_replication_secret = "${workerName}_secret";
     };
 
     workers = lib.listToAttrs (
       lib.map (index: {
-        name = "federation_sender-${toString index}";
+        name = "${workerName}-${toString index}";
         value = {
           worker_app = "synapse.app.generic_worker";
           worker_listeners = [
             {
               type = "http";
-              path = "/run/matrix-synapse/federation_sender-${toString index}.sock";
+              path = "/run/matrix-synapse/${workerName}-${toString index}.sock";
               resources = [
                 {
                   names = [ "replication" ];
@@ -49,6 +39,12 @@ in
               ];
             }
           ];
+          database = (
+            import ../db.nix {
+              workerName = "${workerName}-${toString index}";
+              dbGroup = "solo";
+            }
+          );
         };
       }) federationSenders
     );
diff --git a/host/Rory-nginx/services/matrix/synapse/workers/media-repo.nix b/host/Rory-nginx/services/matrix/synapse/workers/media-repo.nix
index e4d3b32..b030706 100644
--- a/host/Rory-nginx/services/matrix/synapse/workers/media-repo.nix
+++ b/host/Rory-nginx/services/matrix/synapse/workers/media-repo.nix
@@ -1,13 +1,9 @@
-{
-  config,
-  pkgs,
-  lib,
-  ...
-}:
+{ config, lib, ... }:
 
 let
   cfg = config.services.matrix-synapse;
   workers = lib.range 0 (cfg.mediaRepoWorkers - 1);
+  workerName = "media_repo";
   routes = [
     "~ ^/_matrix/media/"
     "~ ^/_matrix/client/v1/media/"
@@ -25,26 +21,26 @@ in
       settings = {
         instance_map = lib.listToAttrs (
           lib.map (index: {
-            name = "media_repo-${toString index}";
+            name = "${workerName}-${toString index}";
             value = {
-              path = "/run/matrix-synapse/media_repo-${toString index}.sock";
+              path = "/run/matrix-synapse/${workerName}-${toString index}.sock";
             };
           }) workers
         );
 
-        media_instance_running_background_jobs = "media_repo-0";
+        media_instance_running_background_jobs = "${workerName}-0";
         enable_media_repo = false;
       };
 
       workers = lib.listToAttrs (
         lib.map (index: {
-          name = "media_repo-${toString index}";
+          name = "${workerName}-${toString index}";
           value = {
             worker_app = "synapse.app.generic_worker";
             worker_listeners = [
               {
                 type = "http";
-                path = "/run/matrix-synapse/media_repo-${toString index}.sock";
+                path = "/run/matrix-synapse/${workerName}-${toString index}.sock";
                 resources = [
                   {
                     names = [ "replication" ];
@@ -54,7 +50,7 @@ in
               }
               {
                 type = "http";
-                path = "/run/matrix-synapse/media_repo-media-${toString index}.sock";
+                path = "/run/matrix-synapse/${workerName}-media-${toString index}.sock";
                 mode = "666";
                 resources = [
                   {
@@ -66,23 +62,33 @@ in
             ];
             database = (
               import ../db.nix {
-                workerName = "media_repo-${toString index}";
+                workerName = "${workerName}-${toString index}";
                 dbGroup = "solo";
               }
             );
             enable_media_repo = true;
+            max_upload_size = "512M";
+            remote_media_download_burst_count = "512G";
+            remote_media_download_per_second = "512G";
+            rc_federation = {
+              window_size = 1;
+              sleep_limit = 1000;
+              sleep_delay = 1;
+              reject_limit = 1000;
+              concurrent = 100;
+            };
           };
         }) workers
       );
     };
 
-    services.nginx.upstreams."media_repo" = {
+    services.nginx.upstreams."${workerName}" = {
       extraConfig = ''
         keepalive 32;
       '';
       servers = lib.listToAttrs (
         lib.map (index: {
-          name = "unix:/run/matrix-synapse/media_repo-media-${toString index}.sock";
+          name = "unix:/run/matrix-synapse/${workerName}-media-${toString index}.sock";
           value = {
             max_fails = 0;
           };
@@ -94,7 +100,7 @@ in
       lib.map (route: {
         name = route;
         value = {
-          proxyPass = "http://media_repo";
+          proxyPass = "http://${workerName}";
           extraConfig = ''
             client_max_body_size 500M;
           '';
diff --git a/host/Rory-nginx/services/matrix/synapse/workers/module.nix b/host/Rory-nginx/services/matrix/synapse/workers/module.nix
index 1450d52..bb46aed 100644
--- a/host/Rory-nginx/services/matrix/synapse/workers/module.nix
+++ b/host/Rory-nginx/services/matrix/synapse/workers/module.nix
@@ -1,19 +1,8 @@
-{
-  config,
-  pkgs,
-  lib,
-  ...
-}:
+{ config, lib, ... }:
 let
   cfg = config.services.matrix-synapse;
 in
-#eventWriters = lib.range 0 (count - 1);
-#typingWriters = lib.range 0 (count - 1);
-#deviceWriters = lib.range 0 (count - 1);
-#accountDataWriters = lib.range 0 (count - 1);
-#receiptsWriters = lib.range 0 (count - 1);
-#presenceWriters = lib.range 0 (count - 1);
-#pusherWriters = lib.range 0 (count - 1);
+
 {
   imports = [
     ./appservice.nix
@@ -51,6 +40,7 @@ in
         ]
     )
     // {
+      enableWorkers = lib.mkEnableOption "Enable dedicated workers";
       enableStreamWriters = lib.mkEnableOption "Enable stream writers";
       enableAppserviceWorker = lib.mkEnableOption "Enable dedicated appservice worker";
       enableBackgroundWorker = lib.mkEnableOption "Enable dedicated background task worker";
diff --git a/host/Rory-nginx/services/matrix/synapse/workers/pusher.nix b/host/Rory-nginx/services/matrix/synapse/workers/pusher.nix
index 63d903a..3391171 100644
--- a/host/Rory-nginx/services/matrix/synapse/workers/pusher.nix
+++ b/host/Rory-nginx/services/matrix/synapse/workers/pusher.nix
@@ -1,12 +1,9 @@
-{
-  config,
-  pkgs,
-  lib,
-  ...
-}:
+{ config, lib, ... }:
 let
   cfg = config.services.matrix-synapse;
   pushers = lib.range 0 (cfg.pushers - 1);
+  workerName = "pusher";
+  workerRoutes = [ ];
 in
 {
   config = lib.mkIf (cfg.pushers > 0) {
@@ -16,23 +13,23 @@ in
           lib.map (index: {
             name = "pusher-${toString index}";
             value = {
-              path = "/run/matrix-synapse/pusher-${toString index}.sock";
+              path = "/run/matrix-synapse/${workerName}-${toString index}.sock";
             };
           }) pushers
         );
 
-        pusher_instances = lib.map (index: "pusher-${toString index}") pushers;
+        pusher_instances = lib.map (index: "${workerName}-${toString index}") pushers;
       };
 
       workers = lib.listToAttrs (
         lib.map (index: {
-          name = "pusher-${toString index}";
+          name = "${workerName}-${toString index}";
           value = {
             worker_app = "synapse.app.generic_worker";
             worker_listeners = [
               {
                 type = "http";
-                path = "/run/matrix-synapse/pusher-${toString index}.sock";
+                path = "/run/matrix-synapse/${workerName}-${toString index}.sock";
                 resources = [
                   {
                     names = [ "replication" ];
@@ -43,7 +40,7 @@ in
             ];
             database = (
               import ../db.nix {
-                workerName = "pusher-${toString index}";
+                workerName = "${workerName}-${toString index}";
                 dbGroup = "small";
               }
             );
diff --git a/host/Rory-nginx/services/matrix/synapse/workers/stream-writers/__OLD__module.nix b/host/Rory-nginx/services/matrix/synapse/workers/stream-writers/__OLD__module.nix
deleted file mode 100644
index d4a9ff4..0000000
--- a/host/Rory-nginx/services/matrix/synapse/workers/stream-writers/__OLD__module.nix
+++ /dev/null
@@ -1,87 +0,0 @@
-{
-  config,
-  pkgs,
-  lib,
-  ...
-}:
-let
-  cfg = config.services.matrix-synapse;
-in
-#eventWriters = lib.range 0 (count - 1);
-#typingWriters = lib.range 0 (count - 1);
-#deviceWriters = lib.range 0 (count - 1);
-#accountDataWriters = lib.range 0 (count - 1);
-#receiptsWriters = lib.range 0 (count - 1);
-#presenceWriters = lib.range 0 (count - 1);
-#pusherWriters = lib.range 0 (count - 1);
-{
-  options.services.matrix-synapse =
-    lib.listToAttrs (
-      lib.map
-        (option: {
-          name = "${option}StreamWriters";
-          value = lib.mkOption {
-            type = lib.types.int;
-            default = 1;
-            description = "Number of writers for ${option} streams";
-          };
-        })
-        [
-          "event"
-          "typing"
-          "toDevice"
-          "accountData"
-          "receipts"
-          "presence"
-          "pushRule"
-        ]
-    )
-    // {
-      enableStreamWriters = lib.mkEnableOption "Enable stream writers";
-      federationSenders = lib.mkOption {
-        type = lib.types.int;
-        default = 1;
-        description = "Number of federation senders";
-      };
-      pushers = lib.mkOption {
-        type = lib.types.int;
-        default = 1;
-        description = "Number of pushers";
-      };
-    };
-
-  config = lib.mkIf cfg.enableStreamWriters {
-    services.matrix-synapse = {
-      settings = {
-        instance_map = lib.listToAttrs (
-          lib.map (port: {
-            name = "stream-writer-${toString port}";
-            value = {
-              path = "/run/matrix-synapse/stream-writer-${toString port}.sock";
-            };
-          }) federationSenders
-        );
-
-        stream_writers = {
-          events = lib.map (port: "stream-writer-events-${toString port}") federationSenders;
-          typing = lib.map (port: "stream-writer-typing-${toString port}") typingWriters;
-          to_device = lib.map (port: "stream-writer-to_device-${toString port}") deviceWriters;
-          account_data = lib.map (port: "stream-writer-account_data-${toString port}") accountDataWriters;
-          receipts = lib.map (port: "stream-writer-receipts-${toString port}") receiptsWriters;
-          presence = lib.map (port: "stream-writer-presence-${toString port}") presenceWriters;
-          push_rules = lib.map (port: "stream-writer-push_rules-${toString port}") pusherWriters;
-        };
-      };
-
-      workers = lib.listToAttrs (
-        lib.map (port: {
-          name = "stream-writerr-${toString port}";
-          value = {
-            worker_app = "synapse.app.generic_worker";
-            worker_listeners = [ ];
-          };
-        }) federationSenders
-      );
-    };
-  };
-}
diff --git a/host/Rory-nginx/services/matrix/synapse/workers/stream-writers/event-stream-writer.nix b/host/Rory-nginx/services/matrix/synapse/workers/stream-writers/event-stream-writer.nix
index 4dbf4ee..1f5b638 100644
--- a/host/Rory-nginx/services/matrix/synapse/workers/stream-writers/event-stream-writer.nix
+++ b/host/Rory-nginx/services/matrix/synapse/workers/stream-writers/event-stream-writer.nix
@@ -1,9 +1,4 @@
-{
-  config,
-  pkgs,
-  lib,
-  ...
-}:
+{ config, lib, ... }:
 let
   cfg = config.services.matrix-synapse;
   streamWriters = lib.range 0 (cfg.eventStreamWriters - 1);
diff --git a/host/Rory-nginx/services/matrix/synapse/workers/sync.nix b/host/Rory-nginx/services/matrix/synapse/workers/sync.nix
index b9ccad3..579e14b 100644
--- a/host/Rory-nginx/services/matrix/synapse/workers/sync.nix
+++ b/host/Rory-nginx/services/matrix/synapse/workers/sync.nix
@@ -1,13 +1,9 @@
-{
-  config,
-  pkgs,
-  lib,
-  ...
-}:
+{ config, lib, ... }:
 
 let
   cfg = config.services.matrix-synapse;
   workers = lib.range 0 (cfg.syncWorkers - 1);
+  workerName = "sync";
   routes = [
     "~ ^/_matrix/client/(v2_alpha|r0|v3)/sync$"
     "~ ^/_matrix/client/(api/v1|v2_alpha|r0|v3)/events$"
@@ -21,9 +17,9 @@ in
       settings = {
         instance_map = lib.listToAttrs (
           lib.map (index: {
-            name = "sync-${toString index}";
+            name = "${workerName}-${toString index}";
             value = {
-              path = "/run/matrix-synapse/sync-${toString index}.sock";
+              path = "/run/matrix-synapse/${workerName}-${toString index}.sock";
             };
           }) workers
         );
@@ -31,13 +27,13 @@ in
 
       workers = lib.listToAttrs (
         lib.map (index: {
-          name = "sync-${toString index}";
+          name = "${workerName}-${toString index}";
           value = {
             worker_app = "synapse.app.generic_worker";
             worker_listeners = [
               {
                 type = "http";
-                path = "/run/matrix-synapse/sync-${toString index}.sock";
+                path = "/run/matrix-synapse/${workerName}-${toString index}.sock";
                 resources = [
                   {
                     names = [ "replication" ];
@@ -47,7 +43,7 @@ in
               }
               {
                 type = "http";
-                path = "/run/matrix-synapse/sync-client-${toString index}.sock";
+                path = "/run/matrix-synapse/${workerName}-client-${toString index}.sock";
                 mode = "666";
                 resources = [
                   {
@@ -59,7 +55,7 @@ in
             ];
             database = (
               import ../db.nix {
-                workerName = "sync-${toString index}";
+                workerName = "${workerName}-${toString index}";
                 dbGroup = "small";
               }
             );
@@ -68,13 +64,13 @@ in
       );
     };
 
-    services.nginx.upstreams."sync" = {
+    services.nginx.upstreams."${workerName}" = {
       extraConfig = ''
         keepalive 32;
       '';
       servers = lib.listToAttrs (
         lib.map (index: {
-          name = "unix:/run/matrix-synapse/sync-client-${toString index}.sock";
+          name = "unix:/run/matrix-synapse/${workerName}-client-${toString index}.sock";
           value = {
             max_fails = 0;
           };
@@ -86,7 +82,7 @@ in
       lib.map (route: {
         name = route;
         value = {
-          proxyPass = "http://sync";
+          proxyPass = "http://${workerName}";
         };
       }) routes
     );
diff --git a/host/Rory-nginx/services/matrix/synapse/workers/user-dir.nix b/host/Rory-nginx/services/matrix/synapse/workers/user-dir.nix
index 2eabe9d..f8d118e 100644
--- a/host/Rory-nginx/services/matrix/synapse/workers/user-dir.nix
+++ b/host/Rory-nginx/services/matrix/synapse/workers/user-dir.nix
@@ -7,6 +7,8 @@
 
 let
   cfg = config.services.matrix-synapse;
+  workerName = "user_dir";
+  workerRoutes = [ "~ ^/_matrix/client/(api/v1|r0|v3|unstable)/user_directory/search$" ];
 in
 {
   config = lib.mkIf cfg.enableUserDirWorker {
@@ -18,7 +20,7 @@ in
           };
         };
 
-        update_user_directory_from_worker = "user_dir";
+        update_user_directory_from_worker = workerName;
       };
 
       workers = {
@@ -27,7 +29,7 @@ in
           worker_listeners = [
             {
               type = "http";
-              path = "/run/matrix-synapse/user_dir.sock";
+              path = "/run/matrix-synapse/${workerName}.sock";
               resources = [
                 {
                   names = [ "replication" ];
@@ -37,7 +39,7 @@ in
             }
             {
               type = "http";
-              path = "/run/matrix-synapse/user_dir-client.sock";
+              path = "/run/matrix-synapse/${workerName}-client.sock";
               mode = "666";
               resources = [
                 {