1
0
Fork 0

Services: clean up Ollama

This commit is contained in:
Aires 2025-01-06 15:44:59 -05:00
parent 0328a2349f
commit 736705eac1
2 changed files with 29 additions and 37 deletions

View file

@ -1,4 +1,3 @@
# FIXME: Clean up
{ {
config, config,
lib, lib,
@ -6,26 +5,17 @@
... ...
}: }:
let let
cfg = config.${namespace}.services; cfg = config.${namespace}.services.open-webui;
api.port = 11434; api.port = 11434;
webui.port = 8130; webui.port = 8130;
user = "ollama";
group = "ollama"; ollamaUser = "ollama";
ollamaGroup = ollamaUser;
in in
{ {
options = { options = {
${namespace}.services = { ${namespace}.services.open-webui = {
ollama = {
enable = lib.mkEnableOption "Enables Ollama.";
home = lib.mkOption {
default = "";
type = lib.types.str;
description = "Where to store Ollama's files";
example = "/var/lib/ollama";
};
};
open-webui = {
enable = lib.mkEnableOption "Enables Ollama."; enable = lib.mkEnableOption "Enables Ollama.";
url = lib.mkOption { url = lib.mkOption {
default = ""; default = "";
@ -37,13 +27,19 @@ in
default = "/var/lib/open-webui"; default = "/var/lib/open-webui";
type = lib.types.str; type = lib.types.str;
description = "Where to store Open-webUI's files"; description = "Where to store Open-webUI's files";
example = "/var/lib/open-webui"; };
ollama = {
enable = lib.mkEnableOption "Enables Ollama.";
home = lib.mkOption {
default = "/var/lib/ollama";
type = lib.types.str;
description = "Where to store Ollama's files";
}; };
}; };
}; };
}; };
config = lib.mkIf cfg.ollama.enable { config = lib.mkIf cfg.enable {
services = { services = {
ollama = { ollama = {
enable = true; enable = true;
@ -57,11 +53,10 @@ in
false; false;
home = cfg.ollama.home; home = cfg.ollama.home;
port = api.port; port = api.port;
user = user; user = ollamaUser;
group = group;
}; };
open-webui = lib.mkIf cfg.open-webui.enable { open-webui = {
enable = true; enable = true;
port = webui.port; port = webui.port;
environment = { environment = {
@ -70,11 +65,11 @@ in
SCARF_NO_ANALYTICS = "True"; SCARF_NO_ANALYTICS = "True";
OLLAMA_BASE_URL = "http://127.0.0.1:${builtins.toString api.port}"; 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}" = { nginx.virtualHosts."${cfg.url}" = {
useACMEHost = lib.${namespace}.getDomainFromURI cfg.open-webui.url; useACMEHost = lib.${namespace}.getDomainFromURI cfg.url;
forceSSL = true; forceSSL = true;
locations."/" = { locations."/" = {
proxyPass = "http://127.0.0.1:${builtins.toString webui.port}"; proxyPass = "http://127.0.0.1:${builtins.toString webui.port}";
@ -87,11 +82,11 @@ in
ollama.unitConfig.RequiresMountsFor = cfg.ollama.home; ollama.unitConfig.RequiresMountsFor = cfg.ollama.home;
open-webui = { open-webui = {
serviceConfig = { serviceConfig = {
User = user; User = ollamaUser;
Group = group; Group = ollamaGroup;
}; };
unitConfig.RequiresMountsFor = cfg.open-webui.home; unitConfig.RequiresMountsFor = cfg.home;
wants = [ config.systemd.services.ollama.name ]; wants = [ config.systemd.services.ollama.name ];
}; };
nginx.wants = [ config.systemd.services.open-webui.name ]; nginx.wants = [ config.systemd.services.open-webui.name ];

View file

@ -244,14 +244,11 @@ in
}; };
}; };
}; };
ollama = {
enable = true;
home = "${services-root}/ollama";
};
open-webui = { open-webui = {
#home = "${services-root}/open-webui"; home = "${services-root}/open-webui";
enable = true; enable = true;
url = config.${namespace}.secrets.services.open-webui.url; url = config.${namespace}.secrets.services.open-webui.url;
ollama.enable = true;
}; };
qbittorrent = { qbittorrent = {
enable = true; enable = true;