From 83b1350904d3f4756d56efb95eab25b3adfb7946 Mon Sep 17 00:00:00 2001 From: pinage404 Date: Mon, 30 Sep 2024 13:55:09 +0200 Subject: [PATCH] nixos/open-webui: fix opensearch When [adding Open WebUI as search engine in Firefox](https://docs.openwebui.com/tutorials/integrations/browser-search-engine/#for-firefox) it always links to `http://localhost:3000` instead of the configured port It is because [the response use `WEBUI_URL` environment variable](https://github.com/open-webui/open-webui/blob/1d225dd804575af9ae5981528dfdce695f7f7040/backend/open_webui/main.py#L2370) which [is set by default to `http://localhost:3000`](https://github.com/open-webui/open-webui/blob/1d225dd804575af9ae5981528dfdce695f7f7040/backend/open_webui/env.py#L106) --- nixos/modules/services/misc/open-webui.nix | 1 + nixos/tests/open-webui.nix | 14 ++++++++++++++ 2 files changed, 15 insertions(+) diff --git a/nixos/modules/services/misc/open-webui.nix b/nixos/modules/services/misc/open-webui.nix index abe27ccdbcf7..fd6fa64b9e19 100644 --- a/nixos/modules/services/misc/open-webui.nix +++ b/nixos/modules/services/misc/open-webui.nix @@ -93,6 +93,7 @@ in DATA_DIR = "."; HF_HOME = "."; SENTENCE_TRANSFORMERS_HOME = "."; + WEBUI_URL = "http://localhost:${toString cfg.port}"; } // cfg.environment; serviceConfig = { diff --git a/nixos/tests/open-webui.nix b/nixos/tests/open-webui.nix index faf4dae671d0..27f913dbffd5 100644 --- a/nixos/tests/open-webui.nix +++ b/nixos/tests/open-webui.nix @@ -31,6 +31,7 @@ in testScript = '' import json + import xml.etree.ElementTree as xml machine.start() @@ -45,5 +46,18 @@ in # Check that the name was overridden via the environmentFile option. assert webui_config["name"] == "${webuiName} (Open WebUI)" + + webui_opensearch_xml = machine.succeed("curl http://127.0.0.1:${mainPort}/opensearch.xml") + webui_opensearch = xml.fromstring(webui_opensearch_xml) + + webui_opensearch_url = webui_opensearch.find( + ".//{http://a9.com/-/spec/opensearch/1.1/}Url" + ) + assert ( + webui_opensearch_url is not None + ), f"no url tag found in {webui_opensearch_xml}" + assert ( + webui_opensearch_url.get("template") == "http://localhost:8080/?q={searchTerms}" + ), "opensearch url doesn't match the configured port" ''; }