diff options
4 files changed, 87 insertions, 29 deletions
diff --git a/host/Rory-nginx/services/matrix/synapse/synapse-main.nix b/host/Rory-nginx/services/matrix/synapse/synapse-main.nix index acd842f..82e9eef 100755 --- a/host/Rory-nginx/services/matrix/synapse/synapse-main.nix +++ b/host/Rory-nginx/services/matrix/synapse/synapse-main.nix @@ -14,11 +14,13 @@ enable = true; withJemalloc = true; + nginxVirtualHostName = "matrix.rory.gay"; federationSenders = 32; pushers = 2; enableStreamWriters = false; enableAppserviceWorker = true; enableBackgroundWorker = true; + enableUserDirWorker = true; #eventStreamWriters = 8; # https://matrix-org.github.io/synapse/latest/usage/configuration/config_documentation.html diff --git a/host/Rory-nginx/services/matrix/synapse/workers/module.nix b/host/Rory-nginx/services/matrix/synapse/workers/module.nix index b9c490e..ad3e2a0 100644 --- a/host/Rory-nginx/services/matrix/synapse/workers/module.nix +++ b/host/Rory-nginx/services/matrix/synapse/workers/module.nix @@ -46,6 +46,7 @@ in enableStreamWriters = lib.mkEnableOption "Enable stream writers"; enableAppserviceWorker = lib.mkEnableOption "Enable dedicated appservice worker"; enableBackgroundWorker = lib.mkEnableOption "Enable dedicated background task worker"; + enableUserDirWorker = lib.mkEnableOption "Enable dedicated user directory worker"; federationSenders = lib.mkOption { type = lib.types.int; @@ -57,36 +58,19 @@ in default = 0; description = "Number of pushers"; }; + + nginxVirtualHostName = lib.mkOption { + type = lib.types.str; + description = "The virtual host name for the nginx server"; + }; }; - config = lib.mkIf cfg.enableStreamWriters { - #services.matrix-synapse = { - # settings = { - # instance_map = lib.listToAttrs (lib.map (index: { - # name = "stream-writer-${toString index}"; - # value = { - # path = "/run/matrix-synapse/stream-writer-${toString index}.sock"; - # }; - # }) federationSenders); - # - # stream_writers = { - # events = lib.map (index: "stream-writer-events-${toString index}") federationSenders; - # typing = lib.map (index: "stream-writer-typing-${toString index}") typingWriters; - # to_device = lib.map (index: "stream-writer-to_device-${toString index}") deviceWriters; - # account_data = lib.map (index: "stream-writer-account_data-${toString index}") accountDataWriters; - # receipts = lib.map (index: "stream-writer-receipts-${toString index}") receiptsWriters; - # presence = lib.map (index: "stream-writer-presence-${toString index}") presenceWriters; - # push_rules = lib.map (index: "stream-writer-push_rules-${toString index}") pusherWriters; - # }; - # }; - # - # workers = lib.listToAttrs (lib.map (index: { - # name = "stream-writerr-${toString index}"; - # value = { - # worker_app = "synapse.app.generic_worker"; - # worker_listeners = [ ]; - # }; - # }) federationSenders); - #}; + config = { + assertions = [ + { + assertion = cfg.enableUserDirWorker -> cfg.nginxVirtualHostName != null; + message = "nginxVirtualHostName must be set when enableUserDirWorker is true"; + } + ]; }; } diff --git a/host/Rory-nginx/services/matrix/synapse/workers/pusher.nix b/host/Rory-nginx/services/matrix/synapse/workers/pusher.nix index f5ef601..63d903a 100644 --- a/host/Rory-nginx/services/matrix/synapse/workers/pusher.nix +++ b/host/Rory-nginx/services/matrix/synapse/workers/pusher.nix @@ -41,6 +41,12 @@ in ]; } ]; + database = ( + import ../db.nix { + workerName = "pusher-${toString index}"; + dbGroup = "small"; + } + ); }; }) pushers ); diff --git a/host/Rory-nginx/services/matrix/synapse/workers/user-dir.nix b/host/Rory-nginx/services/matrix/synapse/workers/user-dir.nix new file mode 100644 index 0000000..4a097af --- /dev/null +++ b/host/Rory-nginx/services/matrix/synapse/workers/user-dir.nix @@ -0,0 +1,66 @@ +{ + config, + pkgs, + lib, + ... +}: + +let + cfg = config.services.matrix-synapse; +in +{ + config = lib.mkIf cfg.enableUserDirWorker { + services.matrix-synapse = { + settings = { + instance_map = { + appservice = { + path = "/run/matrix-synapse/user_dir.sock"; + }; + }; + + update_user_directory_from_worker = "user_dir"; + }; + + workers = { + user_dir = { + worker_app = "synapse.app.generic_worker"; + worker_listeners = [ + { + type = "http"; + path = "/run/matrix-synapse/user_dir.sock"; + resources = [ + { + names = [ "replication" ]; + compress = false; + } + ]; + } + { + type = "http"; + path = "/run/matrix-synapse/user_dir-client.sock"; + resources = [ + { + names = [ "client" ]; + compress = false; + } + ]; + } + ]; + + database = ( + import ../db.nix { + workerName = "user_dir"; + dbGroup = "small"; + } + ); + }; + }; + }; + + services.nginx.virtualHosts."${nginxVirtualHostName}" = { + locations."^/_matrix/client/(api/v1|r0|v3|unstable)/user_directory/search$" = { + proxyPass = "http://unix:/run/matrix-synapse/user_dir-client.sock"; + }; + }; + }; +} |