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;
35 broken = true; # times out after spending many hours
39 homeserver = { pkgs, ... }: {
40 services.matrix-synapse = {
43 database.name = "sqlite3";
44 tls_certificate_path = "${cert}";
45 tls_private_key_path = "${key}";
46 enable_registration = true;
47 enable_registration_without_verification = true;
48 registration_shared_secret = "supersecret-registration";
51 # The default but tls=false
61 names = [ "federation" ];
70 networking.firewall.allowedTCPPorts = [ 8448 ];
72 environment.systemPackages = [
73 (pkgs.writeShellScriptBin "register_mjolnir_user" ''
74 exec ${pkgs.matrix-synapse}/bin/register_new_matrix_user \
78 --shared-secret supersecret-registration \
82 (pkgs.writeShellScriptBin "register_moderator_user" ''
83 exec ${pkgs.matrix-synapse}/bin/register_new_matrix_user \
85 -p moderator-password \
87 --shared-secret supersecret-registration \
94 mjolnir = { pkgs, ... }: {
97 homeserverUrl = "http://homeserver:8448";
100 username = "mjolnir";
101 passwordFile = pkgs.writeText "password.txt" "mjolnir-password";
103 managementRoom = "#moderators:homeserver";
107 client = { pkgs, ... }: {
108 environment.systemPackages = [
109 (pkgs.writers.writePython3Bin "create_management_room_and_invite_mjolnir"
110 { libraries = [ pkgs.python3Packages.matrix-nio ]; } ''
115 EnableEncryptionBuilder
119 async def main() -> None:
120 client = AsyncClient("http://homeserver:8448", "moderator")
122 await client.login("moderator-password")
124 room = await client.room_create(
127 initial_state=[EnableEncryptionBuilder().as_dict()],
130 await client.join(room.room_id)
131 await client.room_invite(room.room_id, "@mjolnir:homeserver")
141 with subtest("start homeserver"):
144 homeserver.wait_for_unit("matrix-synapse.service")
145 homeserver.wait_until_succeeds("curl --fail -L http://localhost:8448/")
147 with subtest("register users"):
148 # register mjolnir user
149 homeserver.succeed("register_mjolnir_user")
150 # register moderator user
151 homeserver.succeed("register_moderator_user")
153 with subtest("start mjolnir"):
156 # wait for pantalaimon to be ready
157 mjolnir.wait_for_unit("pantalaimon-mjolnir.service")
158 mjolnir.wait_for_unit("mjolnir.service")
160 mjolnir.wait_until_succeeds("curl --fail -L http://localhost:8009/")
162 with subtest("ensure mjolnir can be invited to the management room"):
165 client.wait_until_succeeds("curl --fail -L http://homeserver:8448/")
167 client.succeed("create_management_room_and_invite_mjolnir")
169 mjolnir.wait_for_console_text("Startup complete. Now monitoring rooms")