nixpkgs/pkgs/servers/matrix-synapse/default.nix

176 lines
3.7 KiB
Nix
Raw Normal View History

{ lib
, stdenv
, fetchFromGitHub
, python3
, openssl
2023-11-15 17:45:16 +00:00
, libiconv
, cargo
, rustPlatform
, rustc
, nixosTests
, callPackage
}:
2021-09-07 15:57:29 +00:00
let
2021-09-28 23:56:20 +00:00
plugins = python3.pkgs.callPackage ./plugins { };
tools = callPackage ./tools { };
in
python3.pkgs.buildPythonApplication rec {
pname = "matrix-synapse";
version = "1.98.0";
format = "pyproject";
2016-01-08 14:12:00 +00:00
2022-10-18 16:42:42 +00:00
src = fetchFromGitHub {
owner = "element-hq";
2022-10-18 16:42:42 +00:00
repo = "synapse";
rev = "v${version}";
hash = "sha256-irPExb8rwQjkPp0b3x5hJG4Ay6OnITWIGRPxBSoP/Dk=";
2016-01-08 14:12:00 +00:00
};
cargoDeps = rustPlatform.fetchCargoTarball {
inherit src;
name = "${pname}-${version}";
hash = "sha256-DHKhEFXquWfHfk54mTehjchg3KsB4CfzElXMt5Mp+Vg=";
};
postPatch = ''
# Remove setuptools_rust from runtime dependencies
# https://github.com/element-hq/synapse/blob/v1.69.0/pyproject.toml#L177-L185
sed -i '/^setuptools_rust =/d' pyproject.toml
# Remove version pin on build dependencies. Upstream does this on purpose to
# be extra defensive, but we don't want to deal with updating this
sed -i 's/"poetry-core>=\([0-9.]*\),<=[0-9.]*"/"poetry-core>=\1"/' pyproject.toml
sed -i 's/"setuptools_rust>=\([0-9.]*\),<=[0-9.]*"/"setuptools_rust>=\1"/' pyproject.toml
# Don't force pillow to be 10.0.1 because we already have patched it, and
# we don't use the pillow wheels.
sed -i 's/Pillow = ".*"/Pillow = ">=5.4.0"/' pyproject.toml
'';
nativeBuildInputs = with python3.pkgs; [
poetry-core
rustPlatform.cargoSetupHook
setuptools-rust
cargo
rustc
];
buildInputs = [
openssl
2023-11-15 17:45:16 +00:00
] ++ lib.optionals stdenv.isDarwin [
libiconv
];
propagatedBuildInputs = with python3.pkgs; [
attrs
bcrypt
bleach
canonicaljson
cryptography
2021-05-25 18:08:42 +00:00
ijson
immutabledict
jinja2
jsonschema
2022-01-18 14:42:33 +00:00
matrix-common
msgpack
netaddr
packaging
phonenumbers
pillow
prometheus-client
pyasn1
pyasn1-modules
2022-08-31 13:59:46 +00:00
pydantic
pymacaroons
pyopenssl
pyyaml
service-identity
signedjson
sortedcontainers
treq
twisted
typing-extensions
2021-05-25 18:08:42 +00:00
unpaddedbase64
]
++ twisted.optional-dependencies.tls;
passthru.optional-dependencies = with python3.pkgs; {
postgres = if isPyPy then [
psycopg2cffi
] else [
psycopg2
];
saml2 = [
pysaml2
];
oidc = [
authlib
];
systemd = [
systemd
];
url-preview = [
lxml
];
sentry = [
sentry-sdk
];
jwt = [
authlib
];
redis = [
hiredis
txredisapi
];
cache-memory = [
pympler
];
user-search = [
pyicu
];
};
2016-01-08 14:12:00 +00:00
nativeCheckInputs = [
openssl
] ++ (with python3.pkgs; [
mock
parameterized
])
++ lib.flatten (lib.attrValues passthru.optional-dependencies);
2016-01-08 14:12:00 +00:00
doCheck = !stdenv.isDarwin;
matrix-synapse: limit parallelism to 4 cores to be improve stability, formatting On high core machines those easily can fail similar to: matrix-synapse> tests.storage.test_room_search.MessageSearchTest.test_postgres_web_search_for_phrase matrix-synapse> =============================================================================== matrix-synapse> [ERROR] matrix-synapse> Traceback (most recent call last): matrix-synapse> File "/build/source/tests/unittest.py", line 122, in new matrix-synapse> return code(orig, *args, **kwargs) matrix-synapse> File "/build/source/tests/unittest.py", line 216, in setUp matrix-synapse> return orig() matrix-synapse> File "/build/source/tests/unittest.py", line 338, in setUp matrix-synapse> self.hs = self.make_homeserver(self.reactor, self.clock) matrix-synapse> File "/build/source/tests/app/test_openid_listener.py", line 34, in make_homeserver matrix-synapse> hs = self.setup_test_homeserver( matrix-synapse> File "/build/source/tests/unittest.py", line 606, in setup_test_homeserver matrix-synapse> hs = setup_test_homeserver(self.addCleanup, **kwargs) matrix-synapse> File "/build/source/tests/server.py", line 921, in setup_test_homeserver matrix-synapse> prepare_database( matrix-synapse> File "/nix/store/2cc0p5apn2yg2fr5ii9mvb7fcwd74y26-matrix-synapse-1.86.0/lib/python3.10/site-packages/synapse/storage/prepare_database.py", line 155, in prepare_database matrix-synapse> raise UpgradeDatabaseException(EMPTY_DATABASE_ON_WORKER_ERROR) matrix-synapse> synapse.storage.prepare_database.UpgradeDatabaseException: Uninitialised database: run the main synapse process to prepare the database schema before starting worker processes. matrix-synapse>
2023-07-02 22:19:30 +00:00
checkPhase = ''
runHook preCheck
# remove src module, so tests use the installed module instead
rm -rf ./synapse
matrix-synapse: limit parallelism to 4 cores to be improve stability, formatting On high core machines those easily can fail similar to: matrix-synapse> tests.storage.test_room_search.MessageSearchTest.test_postgres_web_search_for_phrase matrix-synapse> =============================================================================== matrix-synapse> [ERROR] matrix-synapse> Traceback (most recent call last): matrix-synapse> File "/build/source/tests/unittest.py", line 122, in new matrix-synapse> return code(orig, *args, **kwargs) matrix-synapse> File "/build/source/tests/unittest.py", line 216, in setUp matrix-synapse> return orig() matrix-synapse> File "/build/source/tests/unittest.py", line 338, in setUp matrix-synapse> self.hs = self.make_homeserver(self.reactor, self.clock) matrix-synapse> File "/build/source/tests/app/test_openid_listener.py", line 34, in make_homeserver matrix-synapse> hs = self.setup_test_homeserver( matrix-synapse> File "/build/source/tests/unittest.py", line 606, in setup_test_homeserver matrix-synapse> hs = setup_test_homeserver(self.addCleanup, **kwargs) matrix-synapse> File "/build/source/tests/server.py", line 921, in setup_test_homeserver matrix-synapse> prepare_database( matrix-synapse> File "/nix/store/2cc0p5apn2yg2fr5ii9mvb7fcwd74y26-matrix-synapse-1.86.0/lib/python3.10/site-packages/synapse/storage/prepare_database.py", line 155, in prepare_database matrix-synapse> raise UpgradeDatabaseException(EMPTY_DATABASE_ON_WORKER_ERROR) matrix-synapse> synapse.storage.prepare_database.UpgradeDatabaseException: Uninitialised database: run the main synapse process to prepare the database schema before starting worker processes. matrix-synapse>
2023-07-02 22:19:30 +00:00
# high parallelisem makes test suite unstable
# upstream uses 2 cores but 4 seems to be also stable
# https://github.com/element-hq/synapse/blob/develop/.github/workflows/latest_deps.yml#L103
matrix-synapse: limit parallelism to 4 cores to be improve stability, formatting On high core machines those easily can fail similar to: matrix-synapse> tests.storage.test_room_search.MessageSearchTest.test_postgres_web_search_for_phrase matrix-synapse> =============================================================================== matrix-synapse> [ERROR] matrix-synapse> Traceback (most recent call last): matrix-synapse> File "/build/source/tests/unittest.py", line 122, in new matrix-synapse> return code(orig, *args, **kwargs) matrix-synapse> File "/build/source/tests/unittest.py", line 216, in setUp matrix-synapse> return orig() matrix-synapse> File "/build/source/tests/unittest.py", line 338, in setUp matrix-synapse> self.hs = self.make_homeserver(self.reactor, self.clock) matrix-synapse> File "/build/source/tests/app/test_openid_listener.py", line 34, in make_homeserver matrix-synapse> hs = self.setup_test_homeserver( matrix-synapse> File "/build/source/tests/unittest.py", line 606, in setup_test_homeserver matrix-synapse> hs = setup_test_homeserver(self.addCleanup, **kwargs) matrix-synapse> File "/build/source/tests/server.py", line 921, in setup_test_homeserver matrix-synapse> prepare_database( matrix-synapse> File "/nix/store/2cc0p5apn2yg2fr5ii9mvb7fcwd74y26-matrix-synapse-1.86.0/lib/python3.10/site-packages/synapse/storage/prepare_database.py", line 155, in prepare_database matrix-synapse> raise UpgradeDatabaseException(EMPTY_DATABASE_ON_WORKER_ERROR) matrix-synapse> synapse.storage.prepare_database.UpgradeDatabaseException: Uninitialised database: run the main synapse process to prepare the database schema before starting worker processes. matrix-synapse>
2023-07-02 22:19:30 +00:00
if (( $NIX_BUILD_CORES > 4)); then
NIX_BUILD_CORES=4
fi
PYTHONPATH=".:$PYTHONPATH" ${python3.interpreter} -m twisted.trial -j $NIX_BUILD_CORES tests
runHook postCheck
'';
2016-01-08 14:12:00 +00:00
matrix-synapse: limit parallelism to 4 cores to be improve stability, formatting On high core machines those easily can fail similar to: matrix-synapse> tests.storage.test_room_search.MessageSearchTest.test_postgres_web_search_for_phrase matrix-synapse> =============================================================================== matrix-synapse> [ERROR] matrix-synapse> Traceback (most recent call last): matrix-synapse> File "/build/source/tests/unittest.py", line 122, in new matrix-synapse> return code(orig, *args, **kwargs) matrix-synapse> File "/build/source/tests/unittest.py", line 216, in setUp matrix-synapse> return orig() matrix-synapse> File "/build/source/tests/unittest.py", line 338, in setUp matrix-synapse> self.hs = self.make_homeserver(self.reactor, self.clock) matrix-synapse> File "/build/source/tests/app/test_openid_listener.py", line 34, in make_homeserver matrix-synapse> hs = self.setup_test_homeserver( matrix-synapse> File "/build/source/tests/unittest.py", line 606, in setup_test_homeserver matrix-synapse> hs = setup_test_homeserver(self.addCleanup, **kwargs) matrix-synapse> File "/build/source/tests/server.py", line 921, in setup_test_homeserver matrix-synapse> prepare_database( matrix-synapse> File "/nix/store/2cc0p5apn2yg2fr5ii9mvb7fcwd74y26-matrix-synapse-1.86.0/lib/python3.10/site-packages/synapse/storage/prepare_database.py", line 155, in prepare_database matrix-synapse> raise UpgradeDatabaseException(EMPTY_DATABASE_ON_WORKER_ERROR) matrix-synapse> synapse.storage.prepare_database.UpgradeDatabaseException: Uninitialised database: run the main synapse process to prepare the database schema before starting worker processes. matrix-synapse>
2023-07-02 22:19:30 +00:00
passthru = {
tests = { inherit (nixosTests) matrix-synapse matrix-synapse-workers; };
matrix-synapse: limit parallelism to 4 cores to be improve stability, formatting On high core machines those easily can fail similar to: matrix-synapse> tests.storage.test_room_search.MessageSearchTest.test_postgres_web_search_for_phrase matrix-synapse> =============================================================================== matrix-synapse> [ERROR] matrix-synapse> Traceback (most recent call last): matrix-synapse> File "/build/source/tests/unittest.py", line 122, in new matrix-synapse> return code(orig, *args, **kwargs) matrix-synapse> File "/build/source/tests/unittest.py", line 216, in setUp matrix-synapse> return orig() matrix-synapse> File "/build/source/tests/unittest.py", line 338, in setUp matrix-synapse> self.hs = self.make_homeserver(self.reactor, self.clock) matrix-synapse> File "/build/source/tests/app/test_openid_listener.py", line 34, in make_homeserver matrix-synapse> hs = self.setup_test_homeserver( matrix-synapse> File "/build/source/tests/unittest.py", line 606, in setup_test_homeserver matrix-synapse> hs = setup_test_homeserver(self.addCleanup, **kwargs) matrix-synapse> File "/build/source/tests/server.py", line 921, in setup_test_homeserver matrix-synapse> prepare_database( matrix-synapse> File "/nix/store/2cc0p5apn2yg2fr5ii9mvb7fcwd74y26-matrix-synapse-1.86.0/lib/python3.10/site-packages/synapse/storage/prepare_database.py", line 155, in prepare_database matrix-synapse> raise UpgradeDatabaseException(EMPTY_DATABASE_ON_WORKER_ERROR) matrix-synapse> synapse.storage.prepare_database.UpgradeDatabaseException: Uninitialised database: run the main synapse process to prepare the database schema before starting worker processes. matrix-synapse>
2023-07-02 22:19:30 +00:00
inherit plugins tools;
python = python3;
};
meta = with lib; {
homepage = "https://matrix.org";
changelog = "https://github.com/element-hq/synapse/releases/tag/v${version}";
2016-01-08 14:12:00 +00:00
description = "Matrix reference homeserver";
2016-06-22 18:16:28 +00:00
license = licenses.asl20;
2020-06-12 01:05:26 +00:00
maintainers = teams.matrix.members;
2016-01-08 14:12:00 +00:00
};
}