From b305a16775934682e736345c5e885010de236cd3 Mon Sep 17 00:00:00 2001 From: Rory& Date: Fri, 16 Aug 2024 14:22:56 +0200 Subject: Unify single workers --- .../services/matrix/synapse/workers/auth.nix | 26 +++++++------ .../services/matrix/synapse/workers/module.nix | 2 +- .../matrix/synapse/workers/single/appservice.nix | 35 ++++++++++++------ .../matrix/synapse/workers/single/background.nix | 33 ++++++++++++----- .../matrix/synapse/workers/single/user-dir.nix | 43 ++++++++++++++-------- 5 files changed, 91 insertions(+), 48 deletions(-) diff --git a/host/Rory-nginx/services/matrix/synapse/workers/auth.nix b/host/Rory-nginx/services/matrix/synapse/workers/auth.nix index e8d14b5..2313a4d 100644 --- a/host/Rory-nginx/services/matrix/synapse/workers/auth.nix +++ b/host/Rory-nginx/services/matrix/synapse/workers/auth.nix @@ -7,18 +7,20 @@ let hasFederationResource = false; workers = lib.range 0 (cfg.authWorkers - 1); workerName = "auth"; - workerRoutes = [ - "~ ^/_matrix/client/(api/v1|r0|v3|unstable)/login$" - "~ ^/_matrix/client/(api/v1|r0|v3|unstable)/account/3pid$" - "~ ^/_matrix/client/(api/v1|r0|v3|unstable)/account/whoami$" - "~ ^/_matrix/client/versions$" - "~ ^/_matrix/client/(api/v1|r0|v3|unstable)/voip/turnServer$" - "~ ^/_matrix/client/(r0|v3|unstable)/register$" - "~ ^/_matrix/client/(r0|v3|unstable)/register/available$" - "~ ^/_matrix/client/(r0|v3|unstable)/auth/.*/fallback/web$" - "~ ^/_matrix/client/(r0|v3|unstable)/password_policy$" - "~ ^/_matrix/client/(r0|v3|unstable)/capabilities$" - ]; + workerRoutes = { + client = [ + "~ ^/_matrix/client/(api/v1|r0|v3|unstable)/login$" + "~ ^/_matrix/client/(api/v1|r0|v3|unstable)/account/3pid$" + "~ ^/_matrix/client/(api/v1|r0|v3|unstable)/account/whoami$" + "~ ^/_matrix/client/versions$" + "~ ^/_matrix/client/(api/v1|r0|v3|unstable)/voip/turnServer$" + "~ ^/_matrix/client/(r0|v3|unstable)/register$" + "~ ^/_matrix/client/(r0|v3|unstable)/register/available$" + "~ ^/_matrix/client/(r0|v3|unstable)/auth/.*/fallback/web$" + "~ ^/_matrix/client/(r0|v3|unstable)/password_policy$" + "~ ^/_matrix/client/(r0|v3|unstable)/capabilities$" + ]; + }; in { config = lib.mkIf (cfg.authWorkers > 0) { diff --git a/host/Rory-nginx/services/matrix/synapse/workers/module.nix b/host/Rory-nginx/services/matrix/synapse/workers/module.nix index ca6aaec..6615809 100644 --- a/host/Rory-nginx/services/matrix/synapse/workers/module.nix +++ b/host/Rory-nginx/services/matrix/synapse/workers/module.nix @@ -23,7 +23,7 @@ in ./pusher.nix ./sync.nix - ./stream-writers/event-stream-writer.nix + #./stream-writers/event-stream-writer.nix ]; options.services.matrix-synapse = { enableWorkers = lib.mkEnableOption "Enable dedicated workers"; diff --git a/host/Rory-nginx/services/matrix/synapse/workers/single/appservice.nix b/host/Rory-nginx/services/matrix/synapse/workers/single/appservice.nix index ace3bf6..a19b076 100644 --- a/host/Rory-nginx/services/matrix/synapse/workers/single/appservice.nix +++ b/host/Rory-nginx/services/matrix/synapse/workers/single/appservice.nix @@ -3,10 +3,12 @@ let cfg = config.services.matrix-synapse; dbGroup = "small"; - hasClientResource = false; - hasFederationResource = false; workerName = "appservice"; - workerRoutes = [ ]; + workerRoutes = { + client = [ ]; + federation = [ ]; + media = [ ]; + }; in { config = lib.mkIf cfg.enableAppserviceWorker { @@ -37,7 +39,7 @@ in ]; } ] - ++ lib.optional hasClientResource { + ++ lib.optional (lib.length workerRoutes.client > 0) { type = "http"; path = "/run/matrix-synapse/${workerName}-client.sock"; mode = "666"; @@ -48,7 +50,7 @@ in } ]; } - ++ lib.optional hasFederationResource { + ++ lib.optional (lib.length workerRoutes.federation > 0) { type = "http"; path = "/run/matrix-synapse/${workerName}-federation.sock"; mode = "666"; @@ -67,12 +69,23 @@ in services.nginx = { virtualHosts."${cfg.nginxVirtualHostName}".locations = lib.listToAttrs ( - lib.map (route: { - name = route; - value = { - proxyPass = "http://${workerName}"; - }; - }) workerRoutes + lib.flatten ( + lib.forEach + [ + "client" + "federation" + "media" + ] + ( + type: + lib.map (route: { + name = route; + value = { + proxyPass = "http://unix:/run/matrix-synapse/${workerName}-${type}.sock"; + }; + }) workerRoutes.${type} + ) + ) ); }; }; diff --git a/host/Rory-nginx/services/matrix/synapse/workers/single/background.nix b/host/Rory-nginx/services/matrix/synapse/workers/single/background.nix index acc423d..bfa1793 100644 --- a/host/Rory-nginx/services/matrix/synapse/workers/single/background.nix +++ b/host/Rory-nginx/services/matrix/synapse/workers/single/background.nix @@ -6,7 +6,11 @@ let hasClientResource = false; hasFederationResource = false; workerName = "background"; - workerRoutes = [ ]; + workerRoutes = { + client = [ ]; + federation = [ ]; + media = [ ]; + }; in { config = lib.mkIf cfg.enableBackgroundWorker { @@ -37,7 +41,7 @@ in ]; } ] - ++ lib.optional hasClientResource { + ++ lib.optional (lib.length workerRoutes.client > 0) { type = "http"; path = "/run/matrix-synapse/${workerName}-client.sock"; mode = "666"; @@ -48,7 +52,7 @@ in } ]; } - ++ lib.optional hasFederationResource { + ++ lib.optional (lib.length workerRoutes.federation > 0) { type = "http"; path = "/run/matrix-synapse/${workerName}-federation.sock"; mode = "666"; @@ -67,12 +71,23 @@ in services.nginx = { virtualHosts."${cfg.nginxVirtualHostName}".locations = lib.listToAttrs ( - lib.map (route: { - name = route; - value = { - proxyPass = "http://${workerName}"; - }; - }) workerRoutes + lib.flatten ( + lib.forEach + [ + "client" + "federation" + "media" + ] + ( + type: + lib.map (route: { + name = route; + value = { + proxyPass = "http://unix:/run/matrix-synapse/${workerName}-${type}.sock"; + }; + }) workerRoutes.${type} + ) + ) ); }; }; diff --git a/host/Rory-nginx/services/matrix/synapse/workers/single/user-dir.nix b/host/Rory-nginx/services/matrix/synapse/workers/single/user-dir.nix index 0253438..4fd3fb3 100644 --- a/host/Rory-nginx/services/matrix/synapse/workers/single/user-dir.nix +++ b/host/Rory-nginx/services/matrix/synapse/workers/single/user-dir.nix @@ -3,14 +3,16 @@ let cfg = config.services.matrix-synapse; dbGroup = "solo"; - hasClientResource = true; - hasFederationResource = false; workerName = "user_dir"; - workerRoutes = [ - "~ ^/_matrix/client/(api/v1|r0|v3|unstable)/user_directory/search$" - "~ ^/_matrix/client/v3/profile/.*/(displayname|avatar_url)$" - "~ ^/_matrix/client/v3/profile/.*$" - ]; + workerRoutes = { + client = [ + "~ ^/_matrix/client/(api/v1|r0|v3|unstable)/user_directory/search$" + "~ ^/_matrix/client/v3/profile/.*/(displayname|avatar_url)$" + "~ ^/_matrix/client/v3/profile/.*$" + ]; + federation = [ ]; + media = [ ]; + }; in { config = lib.mkIf cfg.enableUserDirWorker { @@ -41,7 +43,7 @@ in ]; } ] - ++ lib.optional hasClientResource { + ++ lib.optional (lib.length workerRoutes.client > 0) { type = "http"; path = "/run/matrix-synapse/${workerName}-client.sock"; mode = "666"; @@ -52,7 +54,7 @@ in } ]; } - ++ lib.optional hasFederationResource { + ++ lib.optional (lib.length workerRoutes.federation > 0) { type = "http"; path = "/run/matrix-synapse/${workerName}-federation.sock"; mode = "666"; @@ -71,12 +73,23 @@ in services.nginx = { virtualHosts."${cfg.nginxVirtualHostName}".locations = lib.listToAttrs ( - lib.map (route: { - name = route; - value = { - proxyPass = "http://${workerName}"; - }; - }) workerRoutes + lib.flatten ( + lib.forEach + [ + "client" + "federation" + "media" + ] + ( + type: + lib.map (route: { + name = route; + value = { + proxyPass = "http://unix:/run/matrix-synapse/${workerName}-${type}.sock"; + }; + }) workerRoutes.${type} + ) + ) ); }; }; -- cgit 1.4.1