summary refs log tree commit diff
path: root/modules/software-templates/synapse-workers/stream-writers
diff options
context:
space:
mode:
authorRory& <root@rory.gay>2025-02-17 09:16:57 +0100
committerRory& <root@rory.gay>2025-02-17 09:16:57 +0100
commit96e147cc8f39530fb2defb2319964e0c61d28f3c (patch)
tree4d9f6bd3befb3d15f52f39989d169d2236517b89 /modules/software-templates/synapse-workers/stream-writers
parentSome server replacement work (diff)
downloadRory-Open-Architecture-96e147cc8f39530fb2defb2319964e0c61d28f3c.tar.xz
Synapse work
Diffstat (limited to 'modules/software-templates/synapse-workers/stream-writers')
-rw-r--r--modules/software-templates/synapse-workers/stream-writers/account_data-stream-writer.nix129
-rw-r--r--modules/software-templates/synapse-workers/stream-writers/event-stream-writer.nix110
-rw-r--r--modules/software-templates/synapse-workers/stream-writers/presence-stream-writer.nix111
-rw-r--r--modules/software-templates/synapse-workers/stream-writers/push_rule-stream-writer.nix111
-rw-r--r--modules/software-templates/synapse-workers/stream-writers/receipt-stream-writer.nix111
-rw-r--r--modules/software-templates/synapse-workers/stream-writers/to_device-stream-writer.nix111
-rw-r--r--modules/software-templates/synapse-workers/stream-writers/typing-stream-writer.nix111
7 files changed, 794 insertions, 0 deletions
diff --git a/modules/software-templates/synapse-workers/stream-writers/account_data-stream-writer.nix b/modules/software-templates/synapse-workers/stream-writers/account_data-stream-writer.nix
new file mode 100644

index 0000000..5e540b3 --- /dev/null +++ b/modules/software-templates/synapse-workers/stream-writers/account_data-stream-writer.nix
@@ -0,0 +1,129 @@ +{ config, lib, ... }: + +let + cfg = config.services.matrix-synapse; + workerLib = import ../lib.nix; + dbGroup = "medium"; +# streamWriterType = "account_data"; + workers = lib.range 0 (cfg.accountDataStreamWriters - 1); + workerName = "account_data_stream_writer"; + tasks = [ "stream_account_data" ]; + workerRoutes = workerLib.workerRoutes.accountData; +in +let + enabledResources = lib.attrNames workerRoutes; + streamTypes = [] + ++ lib.optional (lib.elem "stream_account_data" tasks) "account_data" + ++ lib.optional (lib.elem "stream_presence" tasks) "presence" + ++ lib.optional (lib.elem "stream_push_rules" tasks) "push_rules" + ++ lib.optional (lib.elem "stream_to_device" tasks) "to_device" + ++ lib.optional (lib.elem "stream_typing" tasks) "typing" + ++ lib.optional (lib.elem "stream_receipts" tasks) "receipts" + ++ lib.optional (lib.elem "stream_events" tasks) "events"; +in +{ + config = lib.mkIf (cfg.accountDataStreamWriters > 0) { + monitoring.synapse.workerNames = lib.map (index: "${workerName}-${toString index}") workers; + 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 + ); + + #stream_writers.${streamWriterType} = lib.map (index: "${workerName}-${toString index}") workers; +# stream_writers = lib.listToA + # map `streams` to `workers` + stream_writers = lib.listToAttrs ( + lib.map (stream: { + name = stream; + value = lib.map (index: "${workerName}-${toString index}") workers; + }) streamTypes + ); + }; + + 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; + } + ]; + } + ] + ++ lib.map (type: { + type = "http"; + path = "/run/matrix-synapse/${workerName}-${type}-${toString index}.sock"; + mode = "666"; + resources = [ + { + names = [ type ]; + compress = false; + } + ]; + }) enabledResources; + database = ( + import ../../db.nix { + inherit dbGroup; + workerName = "${workerName}-${toString index}"; + } + ); + }; + }) workers + ); + }; + + services.nginx = { + upstreams = lib.listToAttrs ( + lib.map (type: { + name = "${workerName}-${type}"; + value = { + 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 + ); + }; + }) enabledResources + ); + + virtualHosts."${cfg.nginxVirtualHostName}".locations = lib.listToAttrs ( + lib.flatten ( + 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} + ) + ) + ); + }; + }; +} diff --git a/modules/software-templates/synapse-workers/stream-writers/event-stream-writer.nix b/modules/software-templates/synapse-workers/stream-writers/event-stream-writer.nix new file mode 100644
index 0000000..7160902 --- /dev/null +++ b/modules/software-templates/synapse-workers/stream-writers/event-stream-writer.nix
@@ -0,0 +1,110 @@ +{ config, lib, ... }: + +let + cfg = config.services.matrix-synapse; + dbGroup = "medium"; + streamWriterType = "events"; + workers = lib.range 0 (cfg.eventStreamWriters - 1); + workerName = "event_stream_writer"; + tasks = [ ]; + workerRoutes = {}; + enabledResources = []; +in +{ + config = lib.mkIf (cfg.eventStreamWriters > 0) { + monitoring.synapse.workerNames = lib.map (index: "${workerName}-${toString index}") workers; + 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 + ); + + stream_writers.${streamWriterType} = lib.map (index: "${workerName}-${toString index}") 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; + } + ]; + } + ] + ++ lib.map (type: { + type = "http"; + path = "/run/matrix-synapse/${workerName}-${type}-${toString index}.sock"; + mode = "666"; + resources = [ + { + names = [ type ]; + compress = false; + } + ]; + }) enabledResources; + database = ( + import ../../db.nix { + inherit dbGroup; + workerName = "${workerName}-${toString index}"; + } + ); + }; + }) workers + ); + }; + + services.nginx = { + upstreams = lib.listToAttrs ( + lib.map (type: { + name = "${workerName}-${type}"; + value = { + 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 + ); + }; + }) enabledResources + ); + + virtualHosts."${cfg.nginxVirtualHostName}".locations = lib.listToAttrs ( + lib.flatten ( + 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} + ) + ) + ); + }; + }; +} diff --git a/modules/software-templates/synapse-workers/stream-writers/presence-stream-writer.nix b/modules/software-templates/synapse-workers/stream-writers/presence-stream-writer.nix new file mode 100644
index 0000000..7121e30 --- /dev/null +++ b/modules/software-templates/synapse-workers/stream-writers/presence-stream-writer.nix
@@ -0,0 +1,111 @@ +{ config, lib, ... }: + +let + cfg = config.services.matrix-synapse; + workerLib = import ../lib.nix; + dbGroup = "medium"; + streamWriterType = "presence"; + workers = lib.range 0 (cfg.presenceStreamWriters - 1); + workerName = "presence_stream_writer"; + tasks = [ ]; + workerRoutes = workerLib.workerRoutes.presence; + enabledResources = lib.attrNames workerRoutes; +in +{ + config = lib.mkIf (cfg.presenceStreamWriters > 0) { + monitoring.synapse.workerNames = lib.map (index: "${workerName}-${toString index}") workers; + 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 + ); + + stream_writers.${streamWriterType} = lib.map (index: "${workerName}-${toString index}") 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; + } + ]; + } + ] + ++ lib.map (type: { + type = "http"; + path = "/run/matrix-synapse/${workerName}-${type}-${toString index}.sock"; + mode = "666"; + resources = [ + { + names = [ type ]; + compress = false; + } + ]; + }) enabledResources; + database = ( + import ../../db.nix { + inherit dbGroup; + workerName = "${workerName}-${toString index}"; + } + ); + }; + }) workers + ); + }; + + services.nginx = { + upstreams = lib.listToAttrs ( + lib.map (type: { + name = "${workerName}-${type}"; + value = { + 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 + ); + }; + }) enabledResources + ); + + virtualHosts."${cfg.nginxVirtualHostName}".locations = lib.listToAttrs ( + lib.flatten ( + 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} + ) + ) + ); + }; + }; +} diff --git a/modules/software-templates/synapse-workers/stream-writers/push_rule-stream-writer.nix b/modules/software-templates/synapse-workers/stream-writers/push_rule-stream-writer.nix new file mode 100644
index 0000000..420c3b5 --- /dev/null +++ b/modules/software-templates/synapse-workers/stream-writers/push_rule-stream-writer.nix
@@ -0,0 +1,111 @@ +{ config, lib, ... }: + +let + cfg = config.services.matrix-synapse; + workerLib = import ../lib.nix; + dbGroup = "medium"; + streamWriterType = "push_rules"; + workers = lib.range 0 (cfg.pushRuleStreamWriters - 1); + workerName = "push_rule_stream_writer"; + tasks = [ ]; + workerRoutes = workerLib.workerRoutes.pushRules; + enabledResources = lib.attrNames workerRoutes; +in +{ + config = lib.mkIf (cfg.pushRuleStreamWriters > 0) { + monitoring.synapse.workerNames = lib.map (index: "${workerName}-${toString index}") workers; + 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 + ); + + stream_writers.${streamWriterType} = lib.map (index: "${workerName}-${toString index}") 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; + } + ]; + } + ] + ++ lib.map (type: { + type = "http"; + path = "/run/matrix-synapse/${workerName}-${type}-${toString index}.sock"; + mode = "666"; + resources = [ + { + names = [ type ]; + compress = false; + } + ]; + }) enabledResources; + database = ( + import ../../db.nix { + inherit dbGroup; + workerName = "${workerName}-${toString index}"; + } + ); + }; + }) workers + ); + }; + + services.nginx = { + upstreams = lib.listToAttrs ( + lib.map (type: { + name = "${workerName}-${type}"; + value = { + 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 + ); + }; + }) enabledResources + ); + + virtualHosts."${cfg.nginxVirtualHostName}".locations = lib.listToAttrs ( + lib.flatten ( + 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} + ) + ) + ); + }; + }; +} diff --git a/modules/software-templates/synapse-workers/stream-writers/receipt-stream-writer.nix b/modules/software-templates/synapse-workers/stream-writers/receipt-stream-writer.nix new file mode 100644
index 0000000..53df3f6 --- /dev/null +++ b/modules/software-templates/synapse-workers/stream-writers/receipt-stream-writer.nix
@@ -0,0 +1,111 @@ +{ config, lib, ... }: + +let + cfg = config.services.matrix-synapse; + workerLib = import ../lib.nix; + dbGroup = "medium"; + streamWriterType = "receipts"; + workers = lib.range 0 (cfg.receiptStreamWriters - 1); + workerName = "receipts_stream_writer"; + tasks = [ ]; + workerRoutes = workerLib.workerRoutes.receipts; + enabledResources = lib.attrNames workerRoutes; +in +{ + config = lib.mkIf (cfg.receiptStreamWriters > 0) { + monitoring.synapse.workerNames = lib.map (index: "${workerName}-${toString index}") workers; + 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 + ); + + stream_writers.${streamWriterType} = lib.map (index: "${workerName}-${toString index}") 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; + } + ]; + } + ] + ++ lib.map (type: { + type = "http"; + path = "/run/matrix-synapse/${workerName}-${type}-${toString index}.sock"; + mode = "666"; + resources = [ + { + names = [ type ]; + compress = false; + } + ]; + }) enabledResources; + database = ( + import ../../db.nix { + inherit dbGroup; + workerName = "${workerName}-${toString index}"; + } + ); + }; + }) workers + ); + }; + + services.nginx = { + upstreams = lib.listToAttrs ( + lib.map (type: { + name = "${workerName}-${type}"; + value = { + 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 + ); + }; + }) enabledResources + ); + + virtualHosts."${cfg.nginxVirtualHostName}".locations = lib.listToAttrs ( + lib.flatten ( + 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} + ) + ) + ); + }; + }; +} diff --git a/modules/software-templates/synapse-workers/stream-writers/to_device-stream-writer.nix b/modules/software-templates/synapse-workers/stream-writers/to_device-stream-writer.nix new file mode 100644
index 0000000..8e1e613 --- /dev/null +++ b/modules/software-templates/synapse-workers/stream-writers/to_device-stream-writer.nix
@@ -0,0 +1,111 @@ +{ config, lib, ... }: + +let + cfg = config.services.matrix-synapse; + workerLib = import ../lib.nix; + dbGroup = "medium"; + streamWriterType = "to_device"; + workers = lib.range 0 (cfg.toDeviceStreamWriters - 1); + workerName = "to_device_stream_writer"; + tasks = [ ]; + workerRoutes = workerLib.workerRoutes.toDevice; + enabledResources = lib.attrNames workerRoutes; +in +{ + config = lib.mkIf (cfg.toDeviceStreamWriters > 0) { + monitoring.synapse.workerNames = lib.map (index: "${workerName}-${toString index}") workers; + 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 + ); + + stream_writers.${streamWriterType} = lib.map (index: "${workerName}-${toString index}") 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; + } + ]; + } + ] + ++ lib.map (type: { + type = "http"; + path = "/run/matrix-synapse/${workerName}-${type}-${toString index}.sock"; + mode = "666"; + resources = [ + { + names = [ type ]; + compress = false; + } + ]; + }) enabledResources; + database = ( + import ../../db.nix { + inherit dbGroup; + workerName = "${workerName}-${toString index}"; + } + ); + }; + }) workers + ); + }; + + services.nginx = { + upstreams = lib.listToAttrs ( + lib.map (type: { + name = "${workerName}-${type}"; + value = { + 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 + ); + }; + }) enabledResources + ); + + virtualHosts."${cfg.nginxVirtualHostName}".locations = lib.listToAttrs ( + lib.flatten ( + 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} + ) + ) + ); + }; + }; +} diff --git a/modules/software-templates/synapse-workers/stream-writers/typing-stream-writer.nix b/modules/software-templates/synapse-workers/stream-writers/typing-stream-writer.nix new file mode 100644
index 0000000..9f57a3b --- /dev/null +++ b/modules/software-templates/synapse-workers/stream-writers/typing-stream-writer.nix
@@ -0,0 +1,111 @@ +{ config, lib, ... }: + +let + cfg = config.services.matrix-synapse; + workerLib = import ../lib.nix; + dbGroup = "medium"; + streamWriterType = "typing"; + workers = lib.range 0 (cfg.typingStreamWriters - 1); + workerName = "typing_stream_writer"; + tasks = [ ]; + workerRoutes = workerLib.workerRoutes.typing; + enabledResources = lib.attrNames workerRoutes; +in +{ + config = lib.mkIf (cfg.typingStreamWriters > 0) { + monitoring.synapse.workerNames = lib.map (index: "${workerName}-${toString index}") workers; + 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 + ); + + stream_writers.${streamWriterType} = lib.map (index: "${workerName}-${toString index}") 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; + } + ]; + } + ] + ++ lib.map (type: { + type = "http"; + path = "/run/matrix-synapse/${workerName}-${type}-${toString index}.sock"; + mode = "666"; + resources = [ + { + names = [ type ]; + compress = false; + } + ]; + }) enabledResources; + database = ( + import ../../db.nix { + inherit dbGroup; + workerName = "${workerName}-${toString index}"; + } + ); + }; + }) workers + ); + }; + + services.nginx = { + upstreams = lib.listToAttrs ( + lib.map (type: { + name = "${workerName}-${type}"; + value = { + 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 + ); + }; + }) enabledResources + ); + + virtualHosts."${cfg.nginxVirtualHostName}".locations = lib.listToAttrs ( + lib.flatten ( + 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} + ) + ) + ); + }; + }; +}