diff options
Diffstat (limited to 'host/Rory-nginx/services/matrix/synapse/workers/event-creator.nix')
-rw-r--r-- | host/Rory-nginx/services/matrix/synapse/workers/event-creator.nix | 111 |
1 files changed, 111 insertions, 0 deletions
diff --git a/host/Rory-nginx/services/matrix/synapse/workers/event-creator.nix b/host/Rory-nginx/services/matrix/synapse/workers/event-creator.nix new file mode 100644 index 0000000..c4b9c7f --- /dev/null +++ b/host/Rory-nginx/services/matrix/synapse/workers/event-creator.nix @@ -0,0 +1,111 @@ +{ config, lib, ... }: + +let + cfg = config.services.matrix-synapse; + dbGroup = "medium"; + workers = lib.range 0 (cfg.eventCreators - 1); + workerName = "event_creator"; + workerRoutes = { + client = + [ + "^/_matrix/client/(api/v1|r0|v3|unstable)/rooms/.*/redact" + "^/_matrix/client/(api/v1|r0|v3|unstable)/rooms/.*/send" + "^/_matrix/client/(api/v1|r0|v3|unstable)/rooms/.*/(join|invite|leave|ban|unban|kick)$" + "^/_matrix/client/(api/v1|r0|v3|unstable)/join/" + "^/_matrix/client/(api/v1|r0|v3|unstable)/knock/" + "^/_matrix/client/(api/v1|r0|v3|unstable)/profile/" + ]; + federation = [ ]; + media = [ ]; + }; +in +{ + config = lib.mkIf (cfg.eventCreators > 0) { + services.matrix-synapse = { + settings = { + instance_map = lib.listToAttrs ( + lib.map (index: { + name = "${workerName}-${toString index}"; + value = { + path = "/run/matrix-synapse/${workerName}-${toString index}.sock"; + }; + }) workers + ); + }; + + workers = lib.listToAttrs ( + lib.map (index: { + 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; + } + ]; + } + { + type = "http"; + path = "/run/matrix-synapse/${workerName}-client-${toString index}.sock"; + mode = "666"; + resources = [ + { + names = [ "client" ]; + compress = false; + } + ]; + } + ]; + database = ( + import ../db.nix { + inherit dbGroup; + workerName = "${workerName}-${toString index}"; + } + ); + }; + }) workers + ); + }; + + services.nginx.upstreams."${workerName}" = { + extraConfig = '' + keepalive 32; + ''; + servers = lib.listToAttrs ( + lib.map (index: { + name = "unix:/run/matrix-synapse/${workerName}-client-${toString index}.sock"; + value = { + max_fails = 0; + }; + }) workers + ); + }; + + 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} + ) + ) + ); + }; + }; +} |