open-webui: Add `environmentFile` option (#334830)

Changed files
+29 -1
nixos
modules
services
tests
+12
nixos/modules/services/misc/open-webui.nix
···
'';
};
openFirewall = lib.mkOption {
type = types.bool;
default = false;
···
serviceConfig = {
ExecStart = "${lib.getExe cfg.package} serve --host ${cfg.host} --port ${toString cfg.port}";
WorkingDirectory = cfg.stateDir;
StateDirectory = "open-webui";
RuntimeDirectory = "open-webui";
···
'';
};
+
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;
···
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";
+17 -1
nixos/tests/open-webui.nix
···
-
{ lib, ... }:
let
mainPort = "8080";
in
{
name = "open-webui";
···
# Requires network connection
RAG_EMBEDDING_MODEL = "";
};
};
};
};
testScript = ''
machine.start()
machine.wait_for_unit("open-webui.service")
machine.wait_for_open_port(${mainPort})
machine.succeed("curl http://127.0.0.1:${mainPort}")
'';
}
···
+
{ config, lib, ... }:
let
mainPort = "8080";
+
webuiName = "NixOS Test";
in
{
name = "open-webui";
···
# 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)"
'';
}