From 20455180f9f67309e87cc7bc83ab6407a01336ce Mon Sep 17 00:00:00 2001 From: rnhmjoj Date: Sun, 3 Sep 2023 02:13:13 +0200 Subject: [PATCH] matrix: add whatsapp bridge --- matrix.nix | 45 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-) diff --git a/matrix.nix b/matrix.nix index ff8df99..e5cc206 100644 --- a/matrix.nix +++ b/matrix.nix @@ -131,7 +131,12 @@ in event_cache_size = "2K"; max_upload_size = "1000M"; turn_user_lifetime = "1d"; + + # bridges configuration + app_service_config_files = + [ "/var/lib/mautrix-whatsapp/whatsapp-registration.yaml" ]; }; + # Secrets services.matrix-synapse.extraConfigFiles = [ @@ -151,13 +156,19 @@ in ### Database services.postgresql.enable = true; - # Create database on the first run + # Create databases on the first run services.postgresql.initialScript = pkgs.writeText "synapse-init.sql" '' CREATE ROLE "matrix-synapse" WITH LOGIN PASSWORD 'synapse'; CREATE DATABASE "matrix-synapse" WITH OWNER "matrix-synapse" TEMPLATE template0 LC_COLLATE = "C" LC_CTYPE = "C"; + + CREATE ROLE "mautrix-whatsapp" WITH LOGIN PASSWORD 'whatsapp'; + CREATE DATABASE "mautrix-whatsapp" WITH OWNER "mautrix-whatsapp" + TEMPLATE template0 + LC_COLLATE = "C" + LC_CTYPE = "C"; ''; @@ -201,4 +212,36 @@ in ''; }; + ### Whatsapp bridge + + # allow synapse to read the shared secrets + users.users.matrix-synapse.extraGroups = [ "mautrix-whatsapp" ]; + + services.mautrix-whatsapp = + { + enable = true; + serviceDependencies = [ "postgresql.service" ]; + settings.appservice = + { database.type = "postgres"; + database.uri = "postgresql:///mautrix-whatsapp?host=/run/postgresql"; + }; + settings.bridge = + { encryption = + { allow = true; + default = true; + require = true; + }; + permissions = + { "maxwell.ydns.eu" = "user"; + "@rnhmjoj:maxwell.ydns.eu" = "admin"; + }; + relay.enabled = false; + mute_bridging = true; + }; + settings.whatsapp = + { os_name = "Chrome (Linux)"; + browser_name = "chrome"; + }; + }; + }