From cb8670469be17ae0a658385de59ee55c3a293faf Mon Sep 17 00:00:00 2001 From: Pol Dellaiera Date: Tue, 4 Jun 2024 21:03:48 +0200 Subject: [PATCH 1/8] nixos/ollama: add `openFirewall` option --- nixos/modules/services/misc/ollama.nix | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/nixos/modules/services/misc/ollama.nix b/nixos/modules/services/misc/ollama.nix index 6f00dbfa7531..47ff201ef780 100644 --- a/nixos/modules/services/misc/ollama.nix +++ b/nixos/modules/services/misc/ollama.nix @@ -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`. + ''; + }; }; }; @@ -142,6 +150,8 @@ in }; }; + networking.firewall = lib.mkIf cfg.openFirewall { allowedTCPPorts = [ cfg.port ]; }; + environment.systemPackages = [ ollamaPackage ]; }; From c54890e2263658f5f73b11fb451ea35d9bb69ee2 Mon Sep 17 00:00:00 2001 From: Pol Dellaiera Date: Wed, 5 Jun 2024 07:13:11 +0200 Subject: [PATCH 2/8] nixos/ollama: update `port` option, use `types.port` --- nixos/modules/services/misc/ollama.nix | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/nixos/modules/services/misc/ollama.nix b/nixos/modules/services/misc/ollama.nix index 47ff201ef780..886eaa180b9e 100644 --- a/nixos/modules/services/misc/ollama.nix +++ b/nixos/modules/services/misc/ollama.nix @@ -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 { @@ -135,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"; From 8ea262601a3dca68369f5ce1a3f2ff44e3c6d011 Mon Sep 17 00:00:00 2001 From: Pol Dellaiera Date: Tue, 4 Jun 2024 21:10:14 +0200 Subject: [PATCH 3/8] nixos/open-webui: add release note entry --- nixos/doc/manual/release-notes/rl-2411.section.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/nixos/doc/manual/release-notes/rl-2411.section.md b/nixos/doc/manual/release-notes/rl-2411.section.md index 28264b0b3429..66eb2d8e22ac 100644 --- a/nixos/doc/manual/release-notes/rl-2411.section.md +++ b/nixos/doc/manual/release-notes/rl-2411.section.md @@ -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} From 709eb8ebaf385269866963928e5b97c8ed68f408 Mon Sep 17 00:00:00 2001 From: Pol Dellaiera Date: Tue, 4 Jun 2024 21:05:18 +0200 Subject: [PATCH 4/8] nixos/open-webui: add `openFirewall` option --- nixos/modules/services/misc/open-webui.nix | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/nixos/modules/services/misc/open-webui.nix b/nixos/modules/services/misc/open-webui.nix index de61ff80e922..47d1b4623a39 100644 --- a/nixos/modules/services/misc/open-webui.nix +++ b/nixos/modules/services/misc/open-webui.nix @@ -45,6 +45,15 @@ in ''; 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`. + ''; + }; }; }; @@ -88,6 +97,8 @@ in UMask = "0077"; }; }; + + networking.firewall = lib.mkIf cfg.openFirewall { allowedTCPPorts = [ cfg.port ]; }; }; meta.maintainers = with lib.maintainers; [ shivaraj-bh ]; From 61ab4de94c4fa4daf7af7520c114404723862994 Mon Sep 17 00:00:00 2001 From: Pol Dellaiera Date: Tue, 4 Jun 2024 21:34:39 +0200 Subject: [PATCH 5/8] nixos/open-webui: update option and service descriptions --- nixos/modules/services/misc/open-webui.nix | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/nixos/modules/services/misc/open-webui.nix b/nixos/modules/services/misc/open-webui.nix index 47d1b4623a39..7f1a7c5b538f 100644 --- a/nixos/modules/services/misc/open-webui.nix +++ b/nixos/modules/services/misc/open-webui.nix @@ -12,25 +12,29 @@ 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."; + description = "State directory of Open-WebUI."; }; host = lib.mkOption { type = types.str; default = "localhost"; - description = "Host of open-webui"; + 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"; + description = '' + Which port the Open-WebUI server listens to. + ''; }; environment = lib.mkOption { @@ -43,7 +47,7 @@ in WEBUI_AUTH = "False"; } ''; - description = "Extra environment variables for open-webui"; + description = "Extra environment variables for Open-WebUI"; }; openFirewall = lib.mkOption { @@ -59,7 +63,7 @@ in 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" ]; From a8670536e5d3c6ee9561372f0f94bb1d788fb351 Mon Sep 17 00:00:00 2001 From: Pol Dellaiera Date: Tue, 4 Jun 2024 21:35:55 +0200 Subject: [PATCH 6/8] nixos/open-webui: remove `preStart` step nixos/open-webui: remove `preStart` step --- nixos/modules/services/misc/open-webui.nix | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/nixos/modules/services/misc/open-webui.nix b/nixos/modules/services/misc/open-webui.nix index 7f1a7c5b538f..fad81fb1ee2a 100644 --- a/nixos/modules/services/misc/open-webui.nix +++ b/nixos/modules/services/misc/open-webui.nix @@ -67,13 +67,9 @@ in 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 = { From 5664bb78991bffa5f86ad951ebbe95dd414b7c32 Mon Sep 17 00:00:00 2001 From: Pol Dellaiera Date: Tue, 4 Jun 2024 21:49:05 +0200 Subject: [PATCH 7/8] nixos/open-webui: add example in options --- nixos/modules/services/misc/open-webui.nix | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/nixos/modules/services/misc/open-webui.nix b/nixos/modules/services/misc/open-webui.nix index fad81fb1ee2a..636e4b7e66f4 100644 --- a/nixos/modules/services/misc/open-webui.nix +++ b/nixos/modules/services/misc/open-webui.nix @@ -18,12 +18,14 @@ in stateDir = lib.mkOption { type = types.path; default = "/var/lib/open-webui"; + example = "/home/foo"; description = "State directory of Open-WebUI."; }; host = lib.mkOption { type = types.str; default = "localhost"; + example = "0.0.0.0"; description = '' The host address which the Open-WebUI server HTTP interface listens to. ''; @@ -32,6 +34,7 @@ in port = lib.mkOption { type = types.port; default = 8080; + example = 11111; description = '' Which port the Open-WebUI server listens to. ''; @@ -42,7 +45,7 @@ in default = { }; example = '' { - OLLAMA_API_BASE_URL = "http://localhost:11434"; + OLLAMA_API_BASE_URL = "http://127.0.0.1:11434"; # Disable authentication WEBUI_AUTH = "False"; } From 309451127f372e35354665063411fbfe6739a965 Mon Sep 17 00:00:00 2001 From: Pol Dellaiera Date: Tue, 4 Jun 2024 21:07:56 +0200 Subject: [PATCH 8/8] nixos/open-webui: update options default values --- nixos/modules/services/misc/open-webui.nix | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/nixos/modules/services/misc/open-webui.nix b/nixos/modules/services/misc/open-webui.nix index 636e4b7e66f4..a43e819aac80 100644 --- a/nixos/modules/services/misc/open-webui.nix +++ b/nixos/modules/services/misc/open-webui.nix @@ -24,7 +24,7 @@ in host = lib.mkOption { type = types.str; - default = "localhost"; + default = "127.0.0.1"; example = "0.0.0.0"; description = '' The host address which the Open-WebUI server HTTP interface listens to. @@ -42,7 +42,11 @@ in 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://127.0.0.1:11434";