at master 1.8 kB view raw
1{ config, lib, ... }: 2let 3 mainPort = "8080"; 4 webuiName = "NixOS Test"; 5in 6{ 7 name = "open-webui"; 8 meta = with lib.maintainers; { 9 maintainers = [ shivaraj-bh ]; 10 }; 11 12 nodes = { 13 machine = 14 { ... }: 15 { 16 services.open-webui = { 17 enable = true; 18 host = ""; 19 environment = { 20 # Requires network connection 21 RAG_EMBEDDING_MODEL = ""; 22 }; 23 24 # Test that environment variables can be 25 # overridden through a file. 26 environmentFile = config.node.pkgs.writeText "test.env" '' 27 WEBUI_NAME="${webuiName}" 28 ''; 29 }; 30 }; 31 }; 32 33 testScript = '' 34 import json 35 import xml.etree.ElementTree as xml 36 37 machine.start() 38 39 machine.wait_for_unit("open-webui.service") 40 machine.wait_for_open_port(${mainPort}) 41 42 machine.succeed("curl http://127.0.0.1:${mainPort}") 43 44 # Load the Web UI config JSON and parse it. 45 webui_config_json = machine.succeed("curl http://127.0.0.1:${mainPort}/api/config") 46 webui_config = json.loads(webui_config_json) 47 48 # Check that the name was overridden via the environmentFile option. 49 assert webui_config["name"] == "${webuiName} (Open WebUI)" 50 51 webui_opensearch_xml = machine.succeed("curl http://127.0.0.1:${mainPort}/opensearch.xml") 52 webui_opensearch = xml.fromstring(webui_opensearch_xml) 53 54 webui_opensearch_url = webui_opensearch.find( 55 ".//{http://a9.com/-/spec/opensearch/1.1/}Url" 56 ) 57 assert ( 58 webui_opensearch_url is not None 59 ), f"no url tag found in {webui_opensearch_xml}" 60 assert ( 61 webui_opensearch_url.get("template") == "http://localhost:8080/?q={searchTerms}" 62 ), "opensearch url doesn't match the configured port" 63 ''; 64}