From e6e5f18aa1329325cfcd615b1adc8ae4feb6013a Mon Sep 17 00:00:00 2001 From: Rory& Date: Sat, 17 Aug 2024 10:47:57 +0200 Subject: Fix synapse paths? --- .../services/matrix/synapse/workers/sync.nix | 92 ++++++++++++---------- 1 file changed, 50 insertions(+), 42 deletions(-) (limited to 'host/Rory-nginx/services/matrix/synapse/workers/sync.nix') diff --git a/host/Rory-nginx/services/matrix/synapse/workers/sync.nix b/host/Rory-nginx/services/matrix/synapse/workers/sync.nix index 645e550..636f521 100644 --- a/host/Rory-nginx/services/matrix/synapse/workers/sync.nix +++ b/host/Rory-nginx/services/matrix/synapse/workers/sync.nix @@ -16,6 +16,9 @@ let media = [ ]; }; in +let + enabledResources = lib.optionals (lib.length workerRoutes.client > 0) [ "client" ] ++ lib.optionals (lib.length workerRoutes.federation > 0) [ "federation" ] ++ lib.optionals (lib.length workerRoutes.media > 0) [ "media" ]; +in { config = lib.mkIf (cfg.syncWorkers > 0) { services.matrix-synapse = { @@ -35,29 +38,30 @@ in name = "${workerName}-${toString index}"; value = { worker_app = "synapse.app.generic_worker"; - worker_listeners = [ - { - type = "http"; - path = "/run/matrix-synapse/${workerName}-${toString index}.sock"; - resources = [ - { - names = [ "replication" ]; - compress = false; - } - ]; - } - { + worker_listeners = + [ + { + type = "http"; + path = "/run/matrix-synapse/${workerName}-${toString index}.sock"; + resources = [ + { + names = [ "replication" ]; + compress = false; + } + ]; + } + ] + ++ lib.map (type: { type = "http"; - path = "/run/matrix-synapse/${workerName}-client-${toString index}.sock"; + path = "/run/matrix-synapse/${workerName}-${type}-${toString index}.sock"; mode = "666"; resources = [ { - names = [ "client" ]; + names = [ type ]; compress = false; } ]; - } - ]; + }) enabledResources; database = ( import ../db.nix { inherit dbGroup; @@ -69,38 +73,42 @@ in ); }; - services.nginx.upstreams."${workerName}" = { - extraConfig = '' - keepalive 32; - ''; - servers = lib.listToAttrs ( - lib.map (index: { - name = "unix:/run/matrix-synapse/${workerName}-client-${toString index}.sock"; + services.nginx = { + upstreams = lib.listToAttrs ( + lib.map (type: { + name = "${workerName}-${type}"; value = { - max_fails = 0; + extraConfig = '' + keepalive 32; + least_conn; + ''; + servers = lib.listToAttrs ( + lib.map (index: { + name = "unix:/run/matrix-synapse/${workerName}-${type}-${toString index}.sock"; + value = { + max_fails = 0; + }; + }) workers + ); }; - }) workers + }) enabledResources ); - }; - services.nginx = { virtualHosts."${cfg.nginxVirtualHostName}".locations = lib.listToAttrs ( 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} - ) + lib.forEach enabledResources ( + type: + lib.map (route: { + name = route; + value = { + proxyPass = "http://${workerName}-${type}"; + extraConfig = '' + proxy_http_version 1.1; + proxy_set_header Connection ""; + ''; + }; + }) workerRoutes.${type} + ) ) ); }; -- cgit 1.4.1