2025-01-06 14:59:51 +00:00
|
|
|
# FIXME: Clean up
|
2024-12-15 19:54:34 +00:00
|
|
|
{
|
|
|
|
config,
|
|
|
|
lib,
|
|
|
|
namespace,
|
|
|
|
...
|
|
|
|
}:
|
|
|
|
let
|
2025-01-06 14:59:51 +00:00
|
|
|
cfg = config.${namespace}.services;
|
2024-12-15 19:54:34 +00:00
|
|
|
|
|
|
|
api.port = 11434;
|
|
|
|
webui.port = 8130;
|
2025-01-06 14:59:51 +00:00
|
|
|
user = "ollama";
|
|
|
|
group = "ollama";
|
2024-12-15 19:54:34 +00:00
|
|
|
in
|
|
|
|
{
|
|
|
|
options = {
|
2025-01-06 14:59:51 +00:00
|
|
|
${namespace}.services = {
|
|
|
|
ollama = {
|
|
|
|
enable = lib.mkEnableOption "Enables Ollama.";
|
|
|
|
home = lib.mkOption {
|
2024-12-15 19:54:34 +00:00
|
|
|
default = "";
|
|
|
|
type = lib.types.str;
|
2025-01-06 14:59:51 +00:00
|
|
|
description = "Where to store Ollama's files";
|
|
|
|
example = "/var/lib/ollama";
|
2024-12-15 19:54:34 +00:00
|
|
|
};
|
2025-01-06 14:59:51 +00:00
|
|
|
};
|
|
|
|
open-webui = {
|
|
|
|
enable = lib.mkEnableOption "Enables Ollama.";
|
|
|
|
url = lib.mkOption {
|
|
|
|
default = "";
|
2024-12-15 19:54:34 +00:00
|
|
|
type = lib.types.str;
|
2025-01-06 14:59:51 +00:00
|
|
|
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";
|
2024-12-15 19:54:34 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2025-01-06 14:59:51 +00:00
|
|
|
config = lib.mkIf cfg.ollama.enable {
|
2024-12-15 19:54:34 +00:00
|
|
|
services = {
|
|
|
|
ollama = {
|
|
|
|
enable = true;
|
|
|
|
acceleration =
|
|
|
|
with config.${namespace}.gpu;
|
|
|
|
if amd.enable then
|
|
|
|
"rocm"
|
|
|
|
else if nvidia.enable then
|
|
|
|
"cuda"
|
|
|
|
else
|
|
|
|
false;
|
2025-01-06 14:59:51 +00:00
|
|
|
home = cfg.ollama.home;
|
|
|
|
port = api.port;
|
|
|
|
user = user;
|
|
|
|
group = group;
|
2024-12-15 19:54:34 +00:00
|
|
|
};
|
|
|
|
|
2025-01-06 14:59:51 +00:00
|
|
|
open-webui = lib.mkIf cfg.open-webui.enable {
|
2024-12-15 19:54:34 +00:00
|
|
|
enable = true;
|
|
|
|
port = webui.port;
|
|
|
|
environment = {
|
|
|
|
ANONYMIZED_TELEMETRY = "False";
|
|
|
|
DO_NOT_TRACK = "True";
|
|
|
|
SCARF_NO_ANALYTICS = "True";
|
2025-01-06 14:59:51 +00:00
|
|
|
OLLAMA_BASE_URL = "http://127.0.0.1:${builtins.toString api.port}";
|
2024-12-15 19:54:34 +00:00
|
|
|
};
|
2025-01-06 14:59:51 +00:00
|
|
|
stateDir = cfg.open-webui.home;
|
2024-12-15 19:54:34 +00:00
|
|
|
};
|
|
|
|
|
2025-01-06 14:59:51 +00:00
|
|
|
nginx.virtualHosts."${cfg.open-webui.url}" = {
|
|
|
|
useACMEHost = lib.${namespace}.getDomainFromURI cfg.open-webui.url;
|
2024-12-15 19:54:34 +00:00
|
|
|
forceSSL = true;
|
|
|
|
locations."/" = {
|
2025-01-06 14:59:51 +00:00
|
|
|
proxyPass = "http://127.0.0.1:${builtins.toString webui.port}";
|
2024-12-15 19:54:34 +00:00
|
|
|
extraConfig = "proxy_ssl_server_name on;";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
systemd.services = {
|
2025-01-06 14:59:51 +00:00
|
|
|
ollama.unitConfig.RequiresMountsFor = cfg.ollama.home;
|
|
|
|
open-webui = {
|
|
|
|
serviceConfig = {
|
|
|
|
User = user;
|
|
|
|
Group = group;
|
|
|
|
};
|
|
|
|
|
|
|
|
unitConfig.RequiresMountsFor = cfg.open-webui.home;
|
|
|
|
wants = [ config.systemd.services.ollama.name ];
|
|
|
|
};
|
|
|
|
nginx.wants = [ config.systemd.services.open-webui.name ];
|
2024-12-15 19:54:34 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|