2024-06-04 10:37:06 +00:00
|
|
|
{
|
|
|
|
config,
|
|
|
|
lib,
|
|
|
|
pkgs,
|
|
|
|
...
|
|
|
|
}:
|
|
|
|
let
|
|
|
|
inherit (lib) types;
|
|
|
|
|
|
|
|
cfg = config.services.open-webui;
|
|
|
|
in
|
|
|
|
{
|
|
|
|
options = {
|
|
|
|
services.open-webui = {
|
2024-06-04 19:34:39 +00:00
|
|
|
enable = lib.mkEnableOption "Open-WebUI server";
|
2024-06-04 10:37:06 +00:00
|
|
|
package = lib.mkPackageOption pkgs "open-webui" { };
|
|
|
|
|
|
|
|
stateDir = lib.mkOption {
|
|
|
|
type = types.path;
|
|
|
|
default = "/var/lib/open-webui";
|
2024-06-04 19:49:05 +00:00
|
|
|
example = "/home/foo";
|
2024-06-04 19:34:39 +00:00
|
|
|
description = "State directory of Open-WebUI.";
|
2024-06-04 10:37:06 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
host = lib.mkOption {
|
|
|
|
type = types.str;
|
2024-06-04 19:07:56 +00:00
|
|
|
default = "127.0.0.1";
|
2024-06-04 19:49:05 +00:00
|
|
|
example = "0.0.0.0";
|
2024-06-04 19:34:39 +00:00
|
|
|
description = ''
|
|
|
|
The host address which the Open-WebUI server HTTP interface listens to.
|
|
|
|
'';
|
2024-06-04 10:37:06 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
port = lib.mkOption {
|
|
|
|
type = types.port;
|
|
|
|
default = 8080;
|
2024-06-04 19:49:05 +00:00
|
|
|
example = 11111;
|
2024-06-04 19:34:39 +00:00
|
|
|
description = ''
|
|
|
|
Which port the Open-WebUI server listens to.
|
|
|
|
'';
|
2024-06-04 10:37:06 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
environment = lib.mkOption {
|
|
|
|
type = types.attrsOf types.str;
|
2024-06-04 19:07:56 +00:00
|
|
|
default = {
|
|
|
|
SCARF_NO_ANALYTICS = "True";
|
|
|
|
DO_NOT_TRACK = "True";
|
|
|
|
ANONYMIZED_TELEMETRY = "False";
|
|
|
|
};
|
2024-06-04 10:37:06 +00:00
|
|
|
example = ''
|
|
|
|
{
|
2024-06-04 19:49:05 +00:00
|
|
|
OLLAMA_API_BASE_URL = "http://127.0.0.1:11434";
|
2024-06-04 10:37:06 +00:00
|
|
|
# Disable authentication
|
|
|
|
WEBUI_AUTH = "False";
|
|
|
|
}
|
|
|
|
'';
|
2024-06-04 19:34:39 +00:00
|
|
|
description = "Extra environment variables for Open-WebUI";
|
2024-06-04 10:37:06 +00:00
|
|
|
};
|
2024-06-04 19:05:18 +00:00
|
|
|
|
|
|
|
openFirewall = lib.mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
|
|
|
description = ''
|
|
|
|
Whether to open the firewall for Open-WebUI.
|
|
|
|
This adds `services.open-webui.port` to `networking.firewall.allowedTCPPorts`.
|
|
|
|
'';
|
|
|
|
};
|
2024-06-04 10:37:06 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = lib.mkIf cfg.enable {
|
|
|
|
systemd.services.open-webui = {
|
2024-06-04 19:34:39 +00:00
|
|
|
description = "User-friendly WebUI for LLMs";
|
2024-06-04 10:37:06 +00:00
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
after = [ "network.target" ];
|
|
|
|
|
|
|
|
environment = {
|
2024-06-04 19:35:55 +00:00
|
|
|
STATIC_DIR = ".";
|
|
|
|
DATA_DIR = ".";
|
2024-06-07 21:15:54 +00:00
|
|
|
HF_HOME = ".";
|
|
|
|
SENTENCE_TRANSFORMERS_HOME = ".";
|
2024-06-04 10:37:06 +00:00
|
|
|
} // cfg.environment;
|
|
|
|
|
|
|
|
serviceConfig = {
|
|
|
|
ExecStart = "${lib.getExe cfg.package} serve --host ${cfg.host} --port ${toString cfg.port}";
|
|
|
|
WorkingDirectory = cfg.stateDir;
|
|
|
|
StateDirectory = "open-webui";
|
|
|
|
RuntimeDirectory = "open-webui";
|
|
|
|
RuntimeDirectoryMode = "0755";
|
|
|
|
PrivateTmp = true;
|
|
|
|
DynamicUser = true;
|
|
|
|
DevicePolicy = "closed";
|
|
|
|
LockPersonality = true;
|
|
|
|
MemoryDenyWriteExecute = false; # onnxruntime/capi/onnxruntime_pybind11_state.so: cannot enable executable stack as shared object requires: Permission Denied
|
|
|
|
PrivateUsers = true;
|
|
|
|
ProtectHome = true;
|
|
|
|
ProtectHostname = true;
|
|
|
|
ProtectKernelLogs = true;
|
|
|
|
ProtectKernelModules = true;
|
|
|
|
ProtectKernelTunables = true;
|
|
|
|
ProtectControlGroups = true;
|
|
|
|
ProcSubset = "all"; # Error in cpuinfo: failed to parse processor information from /proc/cpuinfo
|
|
|
|
RestrictNamespaces = true;
|
|
|
|
RestrictRealtime = true;
|
|
|
|
SystemCallArchitectures = "native";
|
|
|
|
UMask = "0077";
|
|
|
|
};
|
|
|
|
};
|
2024-06-04 19:05:18 +00:00
|
|
|
|
|
|
|
networking.firewall = lib.mkIf cfg.openFirewall { allowedTCPPorts = [ cfg.port ]; };
|
2024-06-04 10:37:06 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
meta.maintainers = with lib.maintainers; [ shivaraj-bh ];
|
|
|
|
}
|