From ff44839229c1bd6fb2a1f5a20c86fb1fe038bed8 Mon Sep 17 00:00:00 2001
From: Rouven Seifert <rouven@rfive.de>
Date: Thu, 1 May 2025 20:20:28 +0200
Subject: [PATCH] fix mautrix-telegram

---
 .../nuc/modules/mautrix-telegram/default.nix  | 27 +------------------
 1 file changed, 1 insertion(+), 26 deletions(-)

diff --git a/hosts/nuc/modules/mautrix-telegram/default.nix b/hosts/nuc/modules/mautrix-telegram/default.nix
index ed71fdc..03b2fac 100644
--- a/hosts/nuc/modules/mautrix-telegram/default.nix
+++ b/hosts/nuc/modules/mautrix-telegram/default.nix
@@ -1,9 +1,6 @@
 { config, lib, pkgs, ... }:
 let
   homeserverDomain = config.services.matrix-synapse.settings.server_name;
-  registrationFileSynapse = "/var/lib/matrix-synapse/telegram-registration.yaml";
-  registrationFileMautrix = "/var/lib/mautrix-telegram/telegram-registration.yaml";
-  settingsFile = builtins.head (builtins.match ".*--config='(.*)' \\\\.*" config.systemd.services.mautrix-telegram.preStart);
 in
 {
   services.postgresql = {
@@ -20,23 +17,11 @@ in
     owner = config.systemd.services.matrix-synapse.serviceConfig.User;
   };
 
-
-  services.matrix-synapse.settings.app_service_config_files = [
-    # The registration file is automatically generated after starting the
-    # appservice for the first time.
-    registrationFileSynapse
-  ];
-
-  systemd.tmpfiles.rules = [
-    # copy registration file over to synapse
-    "C ${registrationFileSynapse} - - - - ${registrationFileMautrix}"
-    "Z /var/lib/matrix-synapse/ - matrix-synapse matrix-synapse - -"
-  ];
-
   services.mautrix-telegram = {
     enable = true;
 
     environmentFile = config.age.secrets.mautrix-telegram.path;
+    registerToSynapse = true;
 
     settings = {
       homeserver = {
@@ -60,15 +45,5 @@ in
       };
     };
   };
-
-  # If we don't explicitly set {a,h}s_token, mautrix-telegram will try to read them from the registrationFile
-  # and write them to the settingsFile in /nix/store, which obviously fails.
-  # systemd.services.mautrix-telegram.serviceConfig.ExecStart =
-  #   lib.mkForce (pkgs.writeShellScript "start" ''
-  #     export MAUTRIX_TELEGRAM_APPSERVICE_AS_TOKEN=$(grep as_token ${registrationFileMautrix} | cut -d' ' -f2-)
-  #     export MAUTRIX_TELEGRAM_APPSERVICE_HS_TOKEN=$(grep hs_token ${registrationFileMautrix} | cut -d' ' -f2-)
-
-  #     ${pkgs.mautrix-telegram}/bin/mautrix-telegram --config='${settingsFile}'
-  #   '');
 }