10 services.conduwuit = {
14 address = [ "0.0.0.0" ];
15 allow_registration = true;
16 yes_i_am_very_very_sure_i_want_an_open_registration_server_prone_to_abuse = true;
18 extraEnvironment.RUST_BACKTRACE = "yes";
20 networking.firewall.allowedTCPPorts = [ 6167 ];
25 environment.systemPackages = [
26 (pkgs.writers.writePython3Bin "do_test" { libraries = [ pkgs.python3Packages.matrix-nio ]; } ''
31 async def main() -> None:
32 # Connect to conduwuit
33 client = nio.AsyncClient("http://conduwuit:6167", "alice")
35 # Register as user alice
36 response = await client.register("alice", "my-secret-password")
38 # Log in as user alice
39 response = await client.login("my-secret-password")
42 response = await client.room_create(federate=False)
43 print("Matrix room create response:", response)
44 assert isinstance(response, nio.RoomCreateResponse)
45 room_id = response.room_id
48 response = await client.join(room_id)
49 print("Matrix join response:", response)
50 assert isinstance(response, nio.JoinResponse)
52 # Send a message to the room
53 response = await client.room_send(
55 message_type="m.room.message",
58 "body": "Hello conduwuit!"
61 print("Matrix room send response:", response)
62 assert isinstance(response, nio.RoomSendResponse)
65 response = await client.sync(timeout=30000)
66 print("Matrix sync response:", response)
67 assert isinstance(response, nio.SyncResponse)
69 # Check the message was received by conduwuit
70 last_message = response.rooms.join[room_id].timeline.events[-1].body
71 assert last_message == "Hello conduwuit!"
74 response = await client.room_leave(room_id)
75 print("Matrix room leave response:", response)
76 assert isinstance(response, nio.RoomLeaveResponse)
82 if __name__ == "__main__":
92 with subtest("start conduwuit"):
93 conduwuit.wait_for_unit("conduwuit.service")
94 conduwuit.wait_for_open_port(6167)
96 with subtest("ensure messages can be exchanged"):
97 client.succeed("do_test >&2")
100 meta.maintainers = with lib.maintainers; [