1
0
Fork 1
mirror of https://github.com/NixOS/nixpkgs.git synced 2024-11-17 11:10:03 +00:00

open-webui: Add environmentFile option (#334830)

This commit is contained in:
Pol Dellaiera 2024-09-09 03:28:37 +02:00 committed by GitHub
commit bcb04b0967
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 29 additions and 1 deletions

View file

@ -60,6 +60,17 @@ in
'';
};
environmentFile = lib.mkOption {
description = ''
Environment file to be passed to the systemd service.
Useful for passing secrets to the service to prevent them from being
world-readable in the Nix store.
'';
type = lib.types.nullOr lib.types.path;
default = null;
example = "/var/lib/secrets/openWebuiSecrets";
};
openFirewall = lib.mkOption {
type = types.bool;
default = false;
@ -86,6 +97,7 @@ in
serviceConfig = {
ExecStart = "${lib.getExe cfg.package} serve --host ${cfg.host} --port ${toString cfg.port}";
EnvironmentFile = lib.optional (cfg.environmentFile != null) cfg.environmentFile;
WorkingDirectory = cfg.stateDir;
StateDirectory = "open-webui";
RuntimeDirectory = "open-webui";

View file

@ -1,6 +1,7 @@
{ lib, ... }:
{ config, lib, ... }:
let
mainPort = "8080";
webuiName = "NixOS Test";
in
{
name = "open-webui";
@ -18,16 +19,31 @@ in
# Requires network connection
RAG_EMBEDDING_MODEL = "";
};
# Test that environment variables can be
# overridden through a file.
environmentFile = config.node.pkgs.writeText "test.env" ''
WEBUI_NAME="${webuiName}"
'';
};
};
};
testScript = ''
import json
machine.start()
machine.wait_for_unit("open-webui.service")
machine.wait_for_open_port(${mainPort})
machine.succeed("curl http://127.0.0.1:${mainPort}")
# Load the Web UI config JSON and parse it.
webui_config_json = machine.succeed("curl http://127.0.0.1:${mainPort}/api/config")
webui_config = json.loads(webui_config_json)
# Check that the name was overridden via the environmentFile option.
assert webui_config["name"] == "${webuiName} (Open WebUI)"
'';
}