1{
2 buildPythonPackage,
3 lib,
4 python,
5 fetchFromGitHub,
6 fetchpatch,
7 pyopenssl,
8 webcolors,
9 future,
10 atomicwrites,
11 attrs,
12 logbook,
13 pygments,
14 matrix-nio,
15 aiohttp,
16 requests,
17}:
18
19let
20 scriptPython = python.withPackages (
21 ps: with ps; [
22 aiohttp
23 requests
24 python-magic
25 ]
26 );
27
28 version = "0.3.0";
29in
30buildPythonPackage {
31 pname = "weechat-matrix";
32 inherit version;
33
34 src = fetchFromGitHub {
35 owner = "poljar";
36 repo = "weechat-matrix";
37 rev = version;
38 hash = "sha256-o4kgneszVLENG167nWnk2FxM+PsMzi+PSyMUMIktZcc=";
39 };
40
41 patches = [
42 # server: remove set_npn_protocols()
43 (fetchpatch {
44 url = "https://patch-diff.githubusercontent.com/raw/poljar/weechat-matrix/pull/309.patch";
45 hash = "sha256-Grdht+TOFvCYRpL7uhPivqL7YzLoNVF3iQNHgbv1Te0=";
46 })
47 # Fix compatibility with matrix-nio 0.21
48 (fetchpatch {
49 url = "https://github.com/poljar/weechat-matrix/commit/feae9fda26ea9de98da9cd6733980a203115537e.patch";
50 hash = "sha256-MAfxJ85dqz5PNwp/GJdHA2VvXVdWh+Ayx5g0oHiw9rs=";
51 includes = [ "matrix/config.py" ];
52 })
53 ];
54
55 propagatedBuildInputs = [
56 pyopenssl
57 webcolors
58 future
59 atomicwrites
60 attrs
61 logbook
62 pygments
63 (matrix-nio.override { withOlm = true; })
64 aiohttp
65 requests
66 ];
67
68 passthru.scripts = [ "matrix.py" ];
69
70 dontBuild = true;
71 doCheck = false;
72
73 format = "other";
74
75 installPhase = ''
76 mkdir -p $out/share $out/bin
77 cp main.py $out/share/matrix.py
78
79 cp contrib/matrix_upload.py $out/bin/matrix_upload
80 cp contrib/matrix_decrypt.py $out/bin/matrix_decrypt
81 cp contrib/matrix_sso_helper.py $out/bin/matrix_sso_helper
82 substituteInPlace $out/bin/matrix_upload \
83 --replace-fail '/usr/bin/env -S python3' '${scriptPython}/bin/python'
84 substituteInPlace $out/bin/matrix_sso_helper \
85 --replace-fail '/usr/bin/env -S python3' '${scriptPython}/bin/python'
86 substituteInPlace $out/bin/matrix_decrypt \
87 --replace-fail '/usr/bin/env python3' '${scriptPython}/bin/python'
88
89 mkdir -p $out/${python.sitePackages}
90 cp -r matrix $out/${python.sitePackages}/matrix
91 '';
92
93 dontPatchShebangs = true;
94 postFixup = ''
95 addToSearchPath program_PYTHONPATH $out/${python.sitePackages}
96 patchPythonScript $out/share/matrix.py
97 substituteInPlace $out/${python.sitePackages}/matrix/server.py --replace-fail \"matrix_sso_helper\" \"$out/bin/matrix_sso_helper\"
98 substituteInPlace $out/${python.sitePackages}/matrix/uploads.py --replace-fail \"matrix_upload\" \"$out/bin/matrix_upload\"
99 '';
100
101 meta = with lib; {
102 description = "Python plugin for Weechat that lets Weechat communicate over the Matrix protocol";
103 homepage = "https://github.com/poljar/weechat-matrix";
104 license = licenses.isc;
105 platforms = platforms.unix;
106 maintainers = with maintainers; [ tilpner ];
107 };
108}