From 3068460c4fd8a185b7a4c1d08235898476eb3225 Mon Sep 17 00:00:00 2001 From: LuoChen Date: Thu, 16 Jul 2026 20:20:12 +0800 Subject: [PATCH] mautrix-telegram: fix crash and unbreak default-python build Two independent issues currently break mautrix-telegram on master: 1. setuptools 81+ removed the pkg_resources module, causing a crash on startup (ModuleNotFoundError: No module named 'pkg_resources'). The upstream Python version is unmaintained (the main branch was rewritten in Go), so pkg_resources is replaced with the standard library importlib.resources, available since Python 3.9. 2. The default python3 is now 3.14, but telethon is `disabled = pythonAtLeast "3.14"` (only because telethon's *tests* fail on 3.14). mautrix-telegram's tulir-telethon fork was derived via telethon.overrideAttrs and thus inherited the disable, breaking the default build. Build tulir-telethon standalone so it is no longer affected by telethon's test-only disable (this fork already skips the test suite). Assisted-by: opencode (glm-5.2) --- .../0002-use-importlib-resources.patch | 36 +++++++++++++ pkgs/by-name/ma/mautrix-telegram/package.nix | 50 +++++++++++++------ 2 files changed, 72 insertions(+), 14 deletions(-) create mode 100644 pkgs/by-name/ma/mautrix-telegram/0002-use-importlib-resources.patch diff --git a/pkgs/by-name/ma/mautrix-telegram/0002-use-importlib-resources.patch b/pkgs/by-name/ma/mautrix-telegram/0002-use-importlib-resources.patch new file mode 100644 index 000000000000..bcacda11ca52 --- /dev/null +++ b/pkgs/by-name/ma/mautrix-telegram/0002-use-importlib-resources.patch @@ -0,0 +1,36 @@ +diff --git a/mautrix_telegram/web/public/__init__.py b/mautrix_telegram/web/public/__init__.py +index cde3735..d911779 100644 +--- a/mautrix_telegram/web/public/__init__.py ++++ b/mautrix_telegram/web/public/__init__.py +@@ -23,7 +23,7 @@ import time + + from aiohttp import web + from mako.template import Template +-import pkg_resources ++from importlib.resources import files + + from mautrix.types import UserID + from mautrix.util.signed_token import sign_token, verify_token +@@ -45,11 +45,11 @@ class PublicBridgeWebsite(AuthAPI): + self.secret_key = "".join(random.choices(string.ascii_lowercase + string.digits, k=64)) + + self.login = Template( +- pkg_resources.resource_string("mautrix_telegram", "web/public/login.html.mako") ++ files("mautrix_telegram").joinpath("web/public/login.html.mako").read_bytes() + ) + + self.mx_login = Template( +- pkg_resources.resource_string("mautrix_telegram", "web/public/matrix-login.html.mako") ++ files("mautrix_telegram").joinpath("web/public/matrix-login.html.mako").read_bytes() + ) + + self.app = web.Application(loop=loop) +@@ -58,7 +58,7 @@ class PublicBridgeWebsite(AuthAPI): + self.app.router.add_route("GET", "/matrix-login", self.get_matrix_login) + self.app.router.add_route("POST", "/matrix-login", self.post_matrix_login) + self.app.router.add_static( +- "/", pkg_resources.resource_filename("mautrix_telegram", "web/public/") ++ "/", str(files("mautrix_telegram").joinpath("web/public/")) + ) + + def make_token(self, mxid: str, endpoint: str = "/login", expires_in: int = 900) -> str: diff --git a/pkgs/by-name/ma/mautrix-telegram/package.nix b/pkgs/by-name/ma/mautrix-telegram/package.nix index 4a80fc9c9b36..2f6546a74b33 100644 --- a/pkgs/by-name/ma/mautrix-telegram/package.nix +++ b/pkgs/by-name/ma/mautrix-telegram/package.nix @@ -3,24 +3,43 @@ fetchPypi, fetchFromGitHub, python3, + openssl, withE2BE ? true, }: let - tulir-telethon = python3.pkgs.telethon.overrideAttrs ( - finalAttrs: previousAttrs: { - version = "1.99.0a6"; - pname = "tulir_telethon"; - src = fetchFromGitHub { - owner = "tulir"; - repo = "Telethon"; - tag = "v${finalAttrs.version}"; - hash = "sha256-ulnA+xKbZDOTzXYmF9oBWNBNhgxSiF+mKx1ijoCyo/w="; - }; - dontUsePytestCheck = true; - } - ); + # tulir-telethon is a fork of telethon used only by mautrix-telegram. It is + # built standalone rather than via telethon.overrideAttrs so it does not + # inherit telethon's `disabled = pythonAtLeast "3.14"` (which exists only + # because telethon's *tests* fail on 3.14). This fork skips the test suite. + # + # Kept as a local let binding rather than a top-level package: the upstream + # Python version is EOL (being rewritten in Go), so splitting it out would + # only add maintenance surface for code that will soon be replaced. + tulir-telethon = python3.pkgs.buildPythonPackage { + pname = "tulir_telethon"; + version = "1.99.0a6"; + pyproject = true; + src = fetchFromGitHub { + owner = "tulir"; + repo = "Telethon"; + tag = "v1.99.0a6"; + hash = "sha256-ulnA+xKbZDOTzXYmF9oBWNBNhgxSiF+mKx1ijoCyo/w="; + }; + postPatch = '' + substituteInPlace telethon/crypto/libssl.py --replace-fail \ + "ctypes.util.find_library('ssl')" "'${lib.getLib openssl}/lib/libssl.so'" + ''; + build-system = [ + python3.pkgs.setuptools + ]; + dependencies = with python3.pkgs; [ + pyaes + rsa + ]; + dontUsePytestCheck = true; + }; in python3.pkgs.buildPythonApplication (finalAttrs: { pname = "mautrix-telegram"; @@ -36,7 +55,10 @@ python3.pkgs.buildPythonApplication (finalAttrs: { build-system = with python3.pkgs; [ setuptools ]; - patches = [ ./0001-Re-add-entrypoint.patch ]; + patches = [ + ./0001-Re-add-entrypoint.patch + ./0002-use-importlib-resources.patch + ]; pythonRelaxDeps = [ "mautrix"