From 736705eac148d1a3ba13bff47404d0a930287555 Mon Sep 17 00:00:00 2001 From: Andre Date: Mon, 6 Jan 2025 15:44:59 -0500 Subject: [PATCH] Services: clean up Ollama --- modules/nixos/services/ollama/default.nix | 59 +++++++++++------------ systems/x86_64-linux/Hevana/default.nix | 7 +-- 2 files changed, 29 insertions(+), 37 deletions(-) diff --git a/modules/nixos/services/ollama/default.nix b/modules/nixos/services/ollama/default.nix index d2d1777..c455d32 100644 --- a/modules/nixos/services/ollama/default.nix +++ b/modules/nixos/services/ollama/default.nix @@ -1,4 +1,3 @@ -# FIXME: Clean up { config, lib, @@ -6,44 +5,41 @@ ... }: let - cfg = config.${namespace}.services; + cfg = config.${namespace}.services.open-webui; api.port = 11434; webui.port = 8130; - user = "ollama"; - group = "ollama"; + + ollamaUser = "ollama"; + ollamaGroup = ollamaUser; in { options = { - ${namespace}.services = { + ${namespace}.services.open-webui = { + enable = lib.mkEnableOption "Enables Ollama."; + url = lib.mkOption { + default = ""; + type = lib.types.str; + description = "The complete URL where Open-WebUI is hosted."; + example = "https://open-webui.example.com"; + }; + home = lib.mkOption { + default = "/var/lib/open-webui"; + type = lib.types.str; + description = "Where to store Open-webUI's files"; + }; ollama = { enable = lib.mkEnableOption "Enables Ollama."; home = lib.mkOption { - default = ""; + default = "/var/lib/ollama"; type = lib.types.str; description = "Where to store Ollama's files"; - example = "/var/lib/ollama"; - }; - }; - open-webui = { - enable = lib.mkEnableOption "Enables Ollama."; - url = lib.mkOption { - default = ""; - type = lib.types.str; - description = "The complete URL where Open-WebUI is hosted."; - example = "https://open-webui.example.com"; - }; - home = lib.mkOption { - default = "/var/lib/open-webui"; - type = lib.types.str; - description = "Where to store Open-webUI's files"; - example = "/var/lib/open-webui"; }; }; }; }; - config = lib.mkIf cfg.ollama.enable { + config = lib.mkIf cfg.enable { services = { ollama = { enable = true; @@ -57,11 +53,10 @@ in false; home = cfg.ollama.home; port = api.port; - user = user; - group = group; + user = ollamaUser; }; - open-webui = lib.mkIf cfg.open-webui.enable { + open-webui = { enable = true; port = webui.port; environment = { @@ -70,11 +65,11 @@ in SCARF_NO_ANALYTICS = "True"; OLLAMA_BASE_URL = "http://127.0.0.1:${builtins.toString api.port}"; }; - stateDir = cfg.open-webui.home; + stateDir = cfg.home; }; - nginx.virtualHosts."${cfg.open-webui.url}" = { - useACMEHost = lib.${namespace}.getDomainFromURI cfg.open-webui.url; + nginx.virtualHosts."${cfg.url}" = { + useACMEHost = lib.${namespace}.getDomainFromURI cfg.url; forceSSL = true; locations."/" = { proxyPass = "http://127.0.0.1:${builtins.toString webui.port}"; @@ -87,11 +82,11 @@ in ollama.unitConfig.RequiresMountsFor = cfg.ollama.home; open-webui = { serviceConfig = { - User = user; - Group = group; + User = ollamaUser; + Group = ollamaGroup; }; - unitConfig.RequiresMountsFor = cfg.open-webui.home; + unitConfig.RequiresMountsFor = cfg.home; wants = [ config.systemd.services.ollama.name ]; }; nginx.wants = [ config.systemd.services.open-webui.name ]; diff --git a/systems/x86_64-linux/Hevana/default.nix b/systems/x86_64-linux/Hevana/default.nix index 18eeaf9..9be3cc9 100644 --- a/systems/x86_64-linux/Hevana/default.nix +++ b/systems/x86_64-linux/Hevana/default.nix @@ -244,14 +244,11 @@ in }; }; }; - ollama = { - enable = true; - home = "${services-root}/ollama"; - }; open-webui = { - #home = "${services-root}/open-webui"; + home = "${services-root}/open-webui"; enable = true; url = config.${namespace}.secrets.services.open-webui.url; + ollama.enable = true; }; qbittorrent = { enable = true;