Merge pull request #317286 from drupol/open-webui-add-more-env

nixos/{ollama,open-webui}: minor service update
This commit is contained in:
Pol Dellaiera 2024-06-05 09:12:28 +02:00 committed by GitHub
commit 133aa44c38
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 49 additions and 23 deletions

View File

@ -8,7 +8,9 @@
## New Services {#sec-release-24.11-new-services}
- Create the first release note entry in this section!
- [Open-WebUI](https://github.com/open-webui/open-webui), a user-friendly WebUI
for LLMs. Available as [services.open-webui](#opt-services.open-webui.enable)
service.
## Backward Incompatibilities {#sec-release-24.11-incompatibilities}

View File

@ -78,11 +78,11 @@ in
'';
};
port = lib.mkOption {
type = types.nullOr types.ints.u16;
type = types.port;
default = 11434;
example = 11111;
description = ''
Which port the ollama server listens to. Set to `null` to not specify a port.
Which port the ollama server listens to.
'';
};
acceleration = lib.mkOption {
@ -116,6 +116,14 @@ in
Since `ollama run` is mostly a shell around the ollama server, this is usually sufficient.
'';
};
openFirewall = lib.mkOption {
type = types.bool;
default = false;
description = ''
Whether to open the firewall for ollama.
This adds `services.ollama.port` to `networking.firewall.allowedTCPPorts`.
'';
};
};
};
@ -127,11 +135,7 @@ in
environment = cfg.environmentVariables // {
HOME = cfg.home;
OLLAMA_MODELS = cfg.models;
OLLAMA_HOST =
if cfg.port == null then
cfg.host
else
"${cfg.host}:${toString cfg.port}";
OLLAMA_HOST = "${cfg.host}:${toString cfg.port}";
};
serviceConfig = {
ExecStart = "${lib.getExe ollamaPackage} serve";
@ -142,6 +146,8 @@ in
};
};
networking.firewall = lib.mkIf cfg.openFirewall { allowedTCPPorts = [ cfg.port ]; };
environment.systemPackages = [ ollamaPackage ];
};

View File

@ -12,55 +12,71 @@ in
{
options = {
services.open-webui = {
enable = lib.mkEnableOption "Enable open-webui, an interactive chat web app";
enable = lib.mkEnableOption "Open-WebUI server";
package = lib.mkPackageOption pkgs "open-webui" { };
stateDir = lib.mkOption {
type = types.path;
default = "/var/lib/open-webui";
description = "State directory of open-webui.";
example = "/home/foo";
description = "State directory of Open-WebUI.";
};
host = lib.mkOption {
type = types.str;
default = "localhost";
description = "Host of open-webui";
default = "127.0.0.1";
example = "0.0.0.0";
description = ''
The host address which the Open-WebUI server HTTP interface listens to.
'';
};
port = lib.mkOption {
type = types.port;
default = 8080;
description = "Port of open-webui";
example = 11111;
description = ''
Which port the Open-WebUI server listens to.
'';
};
environment = lib.mkOption {
type = types.attrsOf types.str;
default = { };
default = {
SCARF_NO_ANALYTICS = "True";
DO_NOT_TRACK = "True";
ANONYMIZED_TELEMETRY = "False";
};
example = ''
{
OLLAMA_API_BASE_URL = "http://localhost:11434";
OLLAMA_API_BASE_URL = "http://127.0.0.1:11434";
# Disable authentication
WEBUI_AUTH = "False";
}
'';
description = "Extra environment variables for open-webui";
description = "Extra environment variables for Open-WebUI";
};
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`.
'';
};
};
};
config = lib.mkIf cfg.enable {
systemd.services.open-webui = {
description = "User-friendly WebUI for LLMs (Formerly Ollama WebUI)";
description = "User-friendly WebUI for LLMs";
wantedBy = [ "multi-user.target" ];
after = [ "network.target" ];
preStart = ''
mkdir -p ${cfg.stateDir}/static
'';
environment = {
STATIC_DIR = "${cfg.stateDir}/static";
DATA_DIR = "${cfg.stateDir}";
STATIC_DIR = ".";
DATA_DIR = ".";
} // cfg.environment;
serviceConfig = {
@ -88,6 +104,8 @@ in
UMask = "0077";
};
};
networking.firewall = lib.mkIf cfg.openFirewall { allowedTCPPorts = [ cfg.port ]; };
};
meta.maintainers = with lib.maintainers; [ shivaraj-bh ];