From 50ae1b6e57f8c845799a0adf76ec7d84d083247f Mon Sep 17 00:00:00 2001 From: Daniel Olsen Date: Thu, 21 Sep 2023 19:29:04 +0200 Subject: [PATCH] Implement easy sliding sync setup Co-authored-by: h7x4 --- README.MD | 16 ++++++++++++++++ sliding-sync/default.nix | 15 +++++++++++++++ synapse-module/default.nix | 16 ++++++++++++++++ synapse-module/nginx.nix | 3 +++ 4 files changed, 50 insertions(+) diff --git a/README.MD b/README.MD index e1906ab..0874d6c 100644 --- a/README.MD +++ b/README.MD @@ -36,3 +36,19 @@ With matrix.YOURDOMAIN pointing at the server: ``` is ~enough to get a functional matrix-server running with some workers + +## Sliding Sync (Element X) + +Just add the following to your config and point `slidingsync.YOURDOMAIN` at the server + +``` +services.matrix-synapse-next = { + enableSlidingSync = true; +}; + +matrix-synapse.sliding-sync.environmentFile = "/some/file/containing/SYNCV3_SECRET="; + +``` + +If using well-known delagation make sure `YOURDOMAIN/.well-known/matrix/client` matches +what's in `matrix.YOURDOMAIN/.well-known/matrix/client` diff --git a/sliding-sync/default.nix b/sliding-sync/default.nix index 509a3af..a2953d5 100644 --- a/sliding-sync/default.nix +++ b/sliding-sync/default.nix @@ -15,6 +15,13 @@ in description = "What package to use for the sliding-sync proxy."; }; + enableNginx = lib.mkEnableOption (lib.mdDoc "autogenerated nginx config"); + publicBaseUrl = lib.mkOption { + type = lib.types.str; + description = "The domain where clients connect, only has an effect with enableNginx"; + example = "slidingsync.matrix.org"; + }; + settings = lib.mkOption { type = lib.types.submodule { freeformType = with lib.types; attrsOf str; @@ -98,5 +105,13 @@ in WorkingDirectory = "%S/matrix-sliding-sync"; }; }; + + services.nginx.virtualHosts.${cfg.publicBaseUrl} = lib.mkIf cfg.enableNginx { + enableACME = true; + forceSSL = true; + locations."/" = { + proxyPass = lib.replaceStrings [ "0.0.0.0" "::" ] [ "127.0.0.1" "::1" ] "http://${cfg.settings.SYNCV3_BINDADDR}"; + }; + }; }; } diff --git a/synapse-module/default.nix b/synapse-module/default.nix index 435eb2a..54dc8e1 100644 --- a/synapse-module/default.nix +++ b/synapse-module/default.nix @@ -84,6 +84,8 @@ in description = "A yaml python logging config file"; }; + enableSlidingSync = mkEnableOption (lib.mdDoc "automatic Sliding Sync setup at `slidingsync.`"); + settings = mkOption { type = types.submodule { freeformType = format.type; @@ -394,5 +396,19 @@ in }; }; }; + + services.matrix-synapse-next.settings.extra_well_known_client_content."org.matrix.msc3575.proxy" = mkIf cfg.enableSlidingSync { + url = "https://${config.services.matrix-synapse.sliding-sync.publicBaseUrl}"; + }; + services.matrix-synapse.sliding-sync = mkIf cfg.enableSlidingSync { + enable = true; + enableNginx = lib.mkDefault cfg.enableNginx; + publicBaseUrl = lib.mkDefault "slidingsync.${cfg.settings.server_name}"; + + settings = { + SYNCV3_SERVER = lib.mkDefault "https://${cfg.public_baseurl}"; + SYNCV3_PROM = lib.mkIf cfg.settings.enable_metrics (lib.mkDefault "127.0.0.1:9001"); + }; + }; }; } diff --git a/synapse-module/nginx.nix b/synapse-module/nginx.nix index d20673e..6259ba5 100644 --- a/synapse-module/nginx.nix +++ b/synapse-module/nginx.nix @@ -230,6 +230,9 @@ in locations."/_synapse/client" = { proxyPass = "http://$synapse_backend"; }; + locations."/.well-known/matrix" = { + proxyPass = "http://$synapse_backend"; + }; }; }; }