summary refs log tree commit diff stats
path: root/modules/matrix
diff options
context:
space:
mode:
authorChristian Krinitsin <mail@krinitsin.com>2025-04-09 16:02:53 +0200
committerChristian Krinitsin <mail@krinitsin.com>2025-04-09 16:02:53 +0200
commit141c10e17c9aaca4b422f2bcb204b73e0e1ada2a (patch)
tree8ded92a9ba93ee6ee6c22fb55729f0cd8ec7a513 /modules/matrix
parent96d0c89447d00e7cee5d26b5cb1e08f01deae768 (diff)
downloadnosix-141c10e17c9aaca4b422f2bcb204b73e0e1ada2a.tar.gz
nosix-141c10e17c9aaca4b422f2bcb204b73e0e1ada2a.zip
add matrix server with signal and whatsapp bridges
Diffstat (limited to 'modules/matrix')
-rw-r--r--modules/matrix/element.nix19
-rw-r--r--modules/matrix/matrix.nix41
-rw-r--r--modules/matrix/mautrix-signal.nix58
-rw-r--r--modules/matrix/mautrix-whatsapp.nix56
4 files changed, 174 insertions, 0 deletions
diff --git a/modules/matrix/element.nix b/modules/matrix/element.nix
new file mode 100644
index 0000000..20290be
--- /dev/null
+++ b/modules/matrix/element.nix
@@ -0,0 +1,19 @@
+{ pkgs, libs, config, ... }:
+let
+  clientConfig."m.homeserver".base_url = "https://matrix.krinitsin.com/";
+in
+{
+
+  services.nginx.virtualHosts."element.krinitsin.com" = {
+    forceSSL = true;
+    useACMEHost = "krinitsin.com";
+    root = pkgs.element-web.override {
+      conf = {
+        default_server_config = clientConfig;
+      };
+    };
+  };
+
+  security.acme.certs."krinitsin.com".extraDomainNames = [ "element.krinitsin.com" ];
+
+}
diff --git a/modules/matrix/matrix.nix b/modules/matrix/matrix.nix
new file mode 100644
index 0000000..34acafd
--- /dev/null
+++ b/modules/matrix/matrix.nix
@@ -0,0 +1,41 @@
+{ pkgs, libs, config, ... }:
+{
+
+  imports = 
+    [
+      ./mautrix-whatsapp.nix
+      ./mautrix-signal.nix
+      ./element.nix
+    ];
+
+  nixpkgs.config.permittedInsecurePackages = [ "olm-3.2.16" ];
+
+  services.postgresql = {
+    enable = true;
+  };
+
+  services.matrix-synapse = {
+    enable = true;
+    settings = {
+      server_name = "krinitsin.com";
+      public_baseurl = "https://matrix.krinitsin.com/";
+      presence.enabled = false;
+    };
+    extraConfigFiles = [ "/secret/matrix" ];
+  };
+
+  services.nginx.virtualHosts."matrix.krinitsin.com" = {
+    forceSSL = true;
+    useACMEHost = "krinitsin.com";
+    locations."/".proxyPass = "http://localhost:8008";
+  };
+
+  security.acme.certs."krinitsin.com".extraDomainNames = [ "matrix.krinitsin.com" ];
+
+  services.monit.config = ''
+    check process synapse with matching "synapse"
+    start program = "${pkgs.systemd}/bin/systemctl start synapse"
+    stop program = "${pkgs.systemd}/bin/systemctl stop synapse"
+  '';
+
+}
diff --git a/modules/matrix/mautrix-signal.nix b/modules/matrix/mautrix-signal.nix
new file mode 100644
index 0000000..df9201e
--- /dev/null
+++ b/modules/matrix/mautrix-signal.nix
@@ -0,0 +1,58 @@
+{ pkgs, libs, config, ... }:
+{
+
+  services.mautrix-signal = {
+    enable = true;
+    settings = {
+    
+      appservice = {
+        as_token = "";
+        bot = {
+          displayname = "Signal Bridge Bot";
+          username = "signalbot";
+        };
+        hostname = "[::]";
+        hs_token = "";
+        id = "signal";
+        port = 29328;
+        username_template = "signal_{{.}}";
+      };
+
+      bridge = {
+        command_prefix = "!signal";
+        permissions = {
+          "krinitsin.com" = "admin";
+        };
+        relay = {
+          enabled = true;
+        };
+      };
+
+      database = {
+        type = "sqlite3";
+        uri = "file:/var/lib/mautrix-signal/mautrix-signal.db";
+      };
+
+      homeserver = {
+        address = "http://localhost:8008";
+      };
+
+      logging = {
+        min_level = "info";
+        writers = [
+          {
+            format = "pretty-colored";
+            time_format = " ";
+            type = "stdout";
+          }
+        ];
+      };
+
+      network = {
+        displayname_template = "{{or .ProfileName .PhoneNumber \"Unknown user\"}}";
+      };
+
+    };
+  };
+
+}
diff --git a/modules/matrix/mautrix-whatsapp.nix b/modules/matrix/mautrix-whatsapp.nix
new file mode 100644
index 0000000..a7322d2
--- /dev/null
+++ b/modules/matrix/mautrix-whatsapp.nix
@@ -0,0 +1,56 @@
+{ pkgs, libs, config, ... }:
+{
+
+  services.mautrix-whatsapp = {
+    enable = true;
+    settings = {
+
+      appservice = {
+        as_token = "";
+        bot = {
+          displayname = "WhatsApp Bridge Bot";
+          username = "whatsappbot";
+        };
+        database = {
+          type = "sqlite3";
+          uri = "/var/lib/mautrix-whatsapp/mautrix-whatsapp.db";
+        };
+        hostname = "[::]";
+        hs_token = "";
+        id = "whatsapp";
+        port = 29318;
+      };
+
+      bridge = {
+        command_prefix = "!wa";
+        displayname_template = "{{if .BusinessName}}{{.BusinessName}}{{else if .PushName}}{{.PushName}}{{else}}{{.JID}}{{end}} (WA)";
+        double_puppet_server_map = { };
+        login_shared_secret_map = { };
+        permissions = {
+          "krinitsin.com" = "admin";
+        };
+        relay = {
+          enabled = true;
+        };
+        username_template = "whatsapp_{{.}}";
+      };
+
+      homeserver = {
+        address = "http://localhost:8008";
+      };
+
+      logging = {
+        min_level = "info";
+        writers = [
+          {
+            format = "pretty-colored";
+            time_format = " ";
+            type = "stdout";
+          }
+        ];
+      };
+
+    };
+  };
+
+}