1import ./make-test-python.nix ({ pkgs, ... } : let
2
3
4 runWithOpenSSL = file: cmd: pkgs.runCommand file {
5 buildInputs = [ pkgs.openssl ];
6 } cmd;
7
8
9 ca_key = runWithOpenSSL "ca-key.pem" "openssl genrsa -out $out 2048";
10 ca_pem = runWithOpenSSL "ca.pem" ''
11 openssl req \
12 -x509 -new -nodes -key ${ca_key} \
13 -days 10000 -out $out -subj "/CN=snakeoil-ca"
14 '';
15 key = runWithOpenSSL "matrix_key.pem" "openssl genrsa -out $out 2048";
16 csr = runWithOpenSSL "matrix.csr" ''
17 openssl req \
18 -new -key ${key} \
19 -out $out -subj "/CN=localhost" \
20 '';
21 cert = runWithOpenSSL "matrix_cert.pem" ''
22 openssl x509 \
23 -req -in ${csr} \
24 -CA ${ca_pem} -CAkey ${ca_key} \
25 -CAcreateserial -out $out \
26 -days 365
27 '';
28
29in {
30
31 name = "matrix-synapse";
32 meta = with pkgs.lib; {
33 maintainers = teams.matrix.members;
34 };
35
36 nodes = {
37 # Since 0.33.0, matrix-synapse doesn't allow underscores in server names
38 serverpostgres = { pkgs, ... }: {
39 services.matrix-synapse = {
40 enable = true;
41 database_type = "psycopg2";
42 tls_certificate_path = "${cert}";
43 tls_private_key_path = "${key}";
44 database_args = {
45 password = "synapse";
46 };
47 };
48 services.postgresql = {
49 enable = true;
50
51 # The database name and user are configured by the following options:
52 # - services.matrix-synapse.database_name
53 # - services.matrix-synapse.database_user
54 #
55 # The values used here represent the default values of the module.
56 initialScript = pkgs.writeText "synapse-init.sql" ''
57 CREATE ROLE "matrix-synapse" WITH LOGIN PASSWORD 'synapse';
58 CREATE DATABASE "matrix-synapse" WITH OWNER "matrix-synapse"
59 TEMPLATE template0
60 LC_COLLATE = "C"
61 LC_CTYPE = "C";
62 '';
63 };
64 };
65
66 serversqlite = args: {
67 services.matrix-synapse = {
68 enable = true;
69 database_type = "sqlite3";
70 tls_certificate_path = "${cert}";
71 tls_private_key_path = "${key}";
72 };
73 };
74 };
75
76 testScript = ''
77 start_all()
78 serverpostgres.wait_for_unit("matrix-synapse.service")
79 serverpostgres.wait_until_succeeds(
80 "curl --fail -L --cacert ${ca_pem} https://localhost:8448/"
81 )
82 serverpostgres.require_unit_state("postgresql.service")
83 serversqlite.wait_for_unit("matrix-synapse.service")
84 serversqlite.wait_until_succeeds(
85 "curl --fail -L --cacert ${ca_pem} https://localhost:8448/"
86 )
87 serversqlite.succeed("[ -e /var/lib/matrix-synapse/homeserver.db ]")
88 '';
89
90})