1 import ../make-test-python.nix (
4 # Set up SSL certs for Synapse to be happy.
5 runWithOpenSSL = file: cmd: pkgs.runCommand file
7 buildInputs = [ pkgs.openssl ];
11 ca_key = runWithOpenSSL "ca-key.pem" "openssl genrsa -out $out 2048";
12 ca_pem = runWithOpenSSL "ca.pem" ''
14 -x509 -new -nodes -key ${ca_key} \
15 -days 10000 -out $out -subj "/CN=snakeoil-ca"
17 key = runWithOpenSSL "matrix_key.pem" "openssl genrsa -out $out 2048";
18 csr = runWithOpenSSL "matrix.csr" ''
21 -out $out -subj "/CN=localhost" \
23 cert = runWithOpenSSL "matrix_cert.pem" ''
26 -CA ${ca_pem} -CAkey ${ca_key} \
27 -CAcreateserial -out $out \
33 meta = with pkgs.lib; {
34 maintainers = teams.matrix.members;
38 homeserver = { pkgs, ... }: {
39 services.matrix-synapse = {
42 database.name = "sqlite3";
43 tls_certificate_path = "${cert}";
44 tls_private_key_path = "${key}";
45 enable_registration = true;
46 enable_registration_without_verification = true;
47 registration_shared_secret = "supersecret-registration";
50 # The default but tls=false
60 names = [ "federation" ];
69 networking.firewall.allowedTCPPorts = [ 8448 ];
71 environment.systemPackages = [
72 (pkgs.writeShellScriptBin "register_mjolnir_user" ''
73 exec ${pkgs.matrix-synapse}/bin/register_new_matrix_user \
77 --shared-secret supersecret-registration \
81 (pkgs.writeShellScriptBin "register_moderator_user" ''
82 exec ${pkgs.matrix-synapse}/bin/register_new_matrix_user \
84 -p moderator-password \
86 --shared-secret supersecret-registration \
93 mjolnir = { pkgs, ... }: {
96 homeserverUrl = "http://homeserver:8448";
100 passwordFile = pkgs.writeText "password.txt" "mjolnir-password";
101 # otherwise mjolnir tries to connect to ::1, which is not listened by pantalaimon
102 options.listenAddress = "127.0.0.1";
104 managementRoom = "#moderators:homeserver";
108 client = { pkgs, ... }: {
109 environment.systemPackages = [
110 (pkgs.writers.writePython3Bin "create_management_room_and_invite_mjolnir"
111 { libraries = with pkgs.python3Packages; [
112 (matrix-nio.override { withOlm = true; })
119 EnableEncryptionBuilder
123 async def main() -> None:
124 client = AsyncClient("http://homeserver:8448", "moderator")
126 await client.login("moderator-password")
128 room = await client.room_create(
131 initial_state=[EnableEncryptionBuilder().as_dict()],
134 await client.join(room.room_id)
135 await client.room_invite(room.room_id, "@mjolnir:homeserver")
145 with subtest("start homeserver"):
148 homeserver.wait_for_unit("matrix-synapse.service")
149 homeserver.wait_until_succeeds("curl --fail -L http://localhost:8448/")
151 with subtest("register users"):
152 # register mjolnir user
153 homeserver.succeed("register_mjolnir_user")
154 # register moderator user
155 homeserver.succeed("register_moderator_user")
157 with subtest("start mjolnir"):
160 # wait for pantalaimon to be ready
161 mjolnir.wait_for_unit("pantalaimon-mjolnir.service")
162 mjolnir.wait_for_unit("mjolnir.service")
164 mjolnir.wait_until_succeeds("curl --fail -L http://localhost:8009/")
166 with subtest("ensure mjolnir can be invited to the management room"):
169 client.wait_until_succeeds("curl --fail -L http://homeserver:8448/")
171 client.succeed("create_management_room_and_invite_mjolnir")
173 mjolnir.wait_for_console_text("Startup complete. Now monitoring rooms")