diff --git a/modules/services/matrix-synapse/default.nix b/modules/services/matrix-synapse/default.nix index c913ac0..8f73272 100644 --- a/modules/services/matrix-synapse/default.nix +++ b/modules/services/matrix-synapse/default.nix @@ -7,6 +7,10 @@ let cfg = config.modules.services.matrix-synapse; + validBridges = [ + "signal" + "whatsapp" + ]; in { options.modules.services.matrix-synapse = { enable = lib.mkOption { @@ -17,6 +21,16 @@ in { default = true; example = false; }; + bridges = lib.mkOption { + type = lib.types.listOf lib.types.str; + description = "A list of bridges to configure with Synapse."; + example = [ "signal" "whatsapp" ]; + default = []; + apply = bridges: + if lib.all (bridge: lib.elem bridge validBridges) bridges + then bridges + else throw "Invalid bridge(s) specified. Valid bridges are: ${lib.concatStringsSep ", " validBridges}"; + }; serverName = lib.mkOption { type = lib.types.str; default = "vimium.com"; @@ -29,6 +43,27 @@ in { }; config = let + commonBridgeSettings = bridge: { + appservice = { + database = lib.mkIf cfg.usePostgresql { + type = "postgres"; + uri = "postgresql:///mautrix-${bridge}?host=/run/postgresql"; + }; + }; + bridge = { + encryption = { + allow = true; + default = true; + require = true; + }; + permissions = { + "${cfg.serverName}" = "user"; + }; + provisioning = { + shared_secret = "disable"; + }; + }; + }; matrixClientConfig = { "m.homeserver" = { base_url = "https://matrix.${cfg.serverName}"; @@ -149,5 +184,25 @@ in { "matrix-synapse" ]; }; + + services.mautrix-signal = lib.mkIf (lib.elem "signal" cfg.bridges) { + enable = true; + settings = commonBridgeSettings "signal"; + }; + + services.mautrix-whatsapp = lib.mkIf (lib.elem "whatsapp" cfg.bridges) { + enable = true; + settings = { + bridge = { + history_sync = { + backfill = true; + max_initial_conversations = -1; + message_count = 50; + request_full_sync = false; + }; + mute_bridging = true; + }; + } // commonBridgeSettings "whatsapp"; + }; }; }