at master 3.3 kB view raw
1{ lib, ... }: 2let 3 name = "continuwuity"; 4in 5{ 6 inherit name; 7 8 nodes = { 9 continuwuity = { 10 services.matrix-continuwuity = { 11 enable = true; 12 settings.global = { 13 server_name = name; 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; 17 }; 18 extraEnvironment.RUST_BACKTRACE = "yes"; 19 }; 20 networking.firewall.allowedTCPPorts = [ 6167 ]; 21 }; 22 client = 23 { pkgs, ... }: 24 { 25 environment.systemPackages = [ 26 (pkgs.writers.writePython3Bin "do_test" { libraries = [ pkgs.python3Packages.matrix-nio ]; } '' 27 import asyncio 28 import nio 29 30 31 async def main() -> None: 32 # Connect to continuwuity 33 client = nio.AsyncClient("http://continuwuity:6167", "alice") 34 35 # Register as user alice 36 response = await client.register("alice", "my-secret-password") 37 38 # Log in as user alice 39 response = await client.login("my-secret-password") 40 41 # Create a new room 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 46 47 # Join the room 48 response = await client.join(room_id) 49 print("Matrix join response:", response) 50 assert isinstance(response, nio.JoinResponse) 51 52 # Send a message to the room 53 response = await client.room_send( 54 room_id=room_id, 55 message_type="m.room.message", 56 content={ 57 "msgtype": "m.text", 58 "body": "Hello continuwuity!" 59 } 60 ) 61 print("Matrix room send response:", response) 62 assert isinstance(response, nio.RoomSendResponse) 63 64 # Sync responses 65 response = await client.sync(timeout=30000) 66 print("Matrix sync response:", response) 67 assert isinstance(response, nio.SyncResponse) 68 69 # Check the message was received by continuwuity 70 last_message = response.rooms.join[room_id].timeline.events[-1].body 71 assert last_message == "Hello continuwuity!" 72 73 # Leave the room 74 response = await client.room_leave(room_id) 75 print("Matrix room leave response:", response) 76 assert isinstance(response, nio.RoomLeaveResponse) 77 78 # Close the client 79 await client.close() 80 81 82 if __name__ == "__main__": 83 asyncio.run(main()) 84 '') 85 ]; 86 }; 87 }; 88 89 testScript = '' 90 start_all() 91 92 with subtest("start continuwuity"): 93 continuwuity.wait_for_unit("continuwuity.service") 94 continuwuity.wait_for_open_port(6167) 95 96 with subtest("ensure messages can be exchanged"): 97 client.succeed("do_test >&2") 98 ''; 99 100 meta.maintainers = with lib.maintainers; [ 101 nyabinary 102 snaki 103 ]; 104}