1
0
Fork 0
nix-configuration/modules/nixos/services/ollama/default.nix

96 lines
2.4 KiB
Nix
Raw Normal View History

2024-12-15 19:54:34 +00:00
{
config,
lib,
namespace,
...
}:
let
2025-01-06 20:44:59 +00:00
cfg = config.${namespace}.services.open-webui;
2024-12-15 19:54:34 +00:00
api.port = 11434;
webui.port = 8130;
2025-01-06 20:44:59 +00:00
ollamaUser = "ollama";
ollamaGroup = ollamaUser;
2024-12-15 19:54:34 +00:00
in
{
options = {
2025-01-06 20:44:59 +00:00
${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";
};
2025-01-06 14:59:51 +00:00
ollama = {
enable = lib.mkEnableOption "Enables Ollama.";
home = lib.mkOption {
2025-01-06 20:44:59 +00:00
default = "/var/lib/ollama";
2024-12-15 19:54:34 +00:00
type = lib.types.str;
2025-01-06 14:59:51 +00:00
description = "Where to store Ollama's files";
2024-12-15 19:54:34 +00:00
};
};
};
};
2025-01-06 20:44:59 +00:00
config = lib.mkIf cfg.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;
2025-01-06 20:44:59 +00:00
user = ollamaUser;
2024-12-15 19:54:34 +00:00
};
2025-01-06 20:44:59 +00:00
open-webui = {
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
};
stateDir = cfg.home; # FIXME: complains of a read-only fs when writing to certain directories. The default seems to work.
2024-12-15 19:54:34 +00:00
};
2025-01-06 20:44:59 +00:00
nginx.virtualHosts."${cfg.url}" = {
useACMEHost = lib.${namespace}.getDomainFromURI cfg.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 = {
2025-01-06 20:44:59 +00:00
User = ollamaUser;
Group = ollamaGroup;
2025-01-06 14:59:51 +00:00
};
2025-01-06 20:44:59 +00:00
unitConfig.RequiresMountsFor = cfg.home;
2025-01-06 14:59:51 +00:00
wants = [ config.systemd.services.ollama.name ];
};
nginx.wants = [ config.systemd.services.open-webui.name ];
2024-12-15 19:54:34 +00:00
};
};
}