From 13b8ae5c1366a6e53b4d92fb6f65ce1b05df896d Mon Sep 17 00:00:00 2001
From: stuebinm <stuebinm@disroot.org>
Date: Thu, 22 Apr 2021 22:45:52 +0200
Subject: [PATCH] matrix-synapse: update twisted (mail library)

This overrides the python38Packages.twisted derivation to a more recent
version that /hopefully/ doesn't force old tls versions. This includes
using and override on the actual twisted package, and another on the
matrix-synapse packages, which now has parts of its definition repeated
in the overlay since overlays apparently don't propagate into
dependencies of packages (since packages are essentiall functions which
have already been called).

On the one hand, this may break things in case the definition of
matrix-synapse changes too much upstream. On the other hand, it doesn't
seem like anyone update the python packages too often, so probably that
won't happen for a long while.

Additionally, prohibitively long to build, since synapse insists on
running a complete test suite while building itself, and there doesn't
appear to be an obvious version to turn this off. If this situation
continues (also with some of the other packages) I guess at some point
we should just set up hainich as a substitution server for Nix ...
---
 pkgs/matrix/default.nix     | 54 +++++++++++++++++++++++++++++++++++++
 services/matrix-synapse.nix |  3 +++
 2 files changed, 57 insertions(+)
 create mode 100644 pkgs/matrix/default.nix

diff --git a/pkgs/matrix/default.nix b/pkgs/matrix/default.nix
new file mode 100644
index 0000000..b58a98c
--- /dev/null
+++ b/pkgs/matrix/default.nix
@@ -0,0 +1,54 @@
+self: super:
+{
+  python38Packages = super.python3Packages // {
+    twisted = with super.python3Packages;
+      twisted.overrideAttrs (old: rec {
+        version = "21.2.0";
+        src = fetchPypi {
+          inherit version;
+          extension = "tar.gz";
+          pname = "Twisted";
+          sha256 = "04jsr67swzj8vn8z64fzbha7vpkm1jz9ns26566vjsfg8n4llm3p";
+        };
+      });
+  };
+
+  matrix-synapse = super.matrix-synapse.overrideAttrs (old: {
+    propagatedBuildInputs = with self.python3Packages; [
+      setuptools
+      bcrypt
+      bleach
+      canonicaljson
+      daemonize
+      frozendict
+      jinja2
+      jsonschema
+      lxml
+      msgpack
+      netaddr
+      phonenumbers
+      pillow
+      prometheus_client
+      psutil
+      psycopg2
+      pyasn1
+      pymacaroons
+      pynacl
+      pyopenssl
+      pysaml2
+      pyyaml
+      requests
+      signedjson
+      sortedcontainers
+      treq
+      twisted
+      unpaddedbase64
+      typing-extensions
+      authlib
+      pyjwt
+      systemd
+      hiredis
+    ];
+    python = self.python3;
+  });
+}
diff --git a/services/matrix-synapse.nix b/services/matrix-synapse.nix
index 7e88452..2084821 100644
--- a/services/matrix-synapse.nix
+++ b/services/matrix-synapse.nix
@@ -3,6 +3,9 @@
 {
   networking.firewall.allowedTCPPorts = [ 80 443 ];
 
+  nixpkgs.overlays = [ (import ./../../../pkgs/matrix) ];
+
+
   services.postgresql.enable = true;
   services.postgresql.initialScript = pkgs.writeText "synapse-init.sql" ''
     CREATE ROLE "matrix-synapse" WITH LOGIN PASSWORD 'synapse';