2024-10-06 15:25:05 -05:00
|
|
|
{flake, ...}: let
|
|
|
|
inherit (flake.config.people) user0;
|
|
|
|
inherit (flake.config.people.user.${user0}) domain;
|
|
|
|
inherit (flake.config.system.device) server wildcard;
|
2024-10-07 14:47:09 -05:00
|
|
|
inherit (flake.config.service.instance) ollama acme;
|
2024-10-06 15:25:05 -05:00
|
|
|
localhost = wildcard.ip.address0;
|
2024-10-07 14:47:09 -05:00
|
|
|
host = "${ollama.subdomain}.${domain.url0}";
|
2024-10-06 15:25:05 -05:00
|
|
|
in {
|
|
|
|
services = {
|
|
|
|
ollama = {
|
|
|
|
acceleration = false;
|
|
|
|
enable = true;
|
2024-10-07 14:47:09 -05:00
|
|
|
group = ollama.name;
|
2024-10-06 15:25:05 -05:00
|
|
|
host = "http://${localhost}";
|
2024-10-07 14:47:09 -05:00
|
|
|
port = ollama.ports.port1;
|
|
|
|
user = ollama.name;
|
2024-10-06 15:25:05 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
open-webui = {
|
|
|
|
enable = true;
|
|
|
|
host = localhost;
|
2024-10-07 14:47:09 -05:00
|
|
|
port = ollama.ports.port0;
|
2024-10-06 15:25:05 -05:00
|
|
|
environment = {
|
|
|
|
ENABLE_OLLAMA_API = "True";
|
|
|
|
ANONYMIZED_TELEMETRY = "False";
|
|
|
|
DO_NOT_TRACK = "True";
|
|
|
|
SCARF_NO_ANALYTICS = "True";
|
2024-10-07 14:47:09 -05:00
|
|
|
OLLAMA_BASE_URL = "http://${localhost}:${toString ollama.ports.port1}";
|
2024-10-06 15:25:05 -05:00
|
|
|
WEBUI_AUTH = "True";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2024-10-07 14:28:40 -05:00
|
|
|
# caddy = {
|
|
|
|
# virtualHosts = {
|
|
|
|
# ${host} = {
|
|
|
|
# extraConfig = ''
|
|
|
|
# reverse_proxy ${localhost}:${toString ports.port0}
|
|
|
|
|
2024-10-07 14:47:09 -05:00
|
|
|
# tls ${ollama.ssl.cert} ${ollama.ssl.key}
|
2024-10-07 14:28:40 -05:00
|
|
|
# '';
|
|
|
|
# };
|
|
|
|
# };
|
|
|
|
# };
|
2024-10-06 15:25:05 -05:00
|
|
|
|
2024-10-07 14:28:40 -05:00
|
|
|
nginx = {
|
|
|
|
enable = true;
|
|
|
|
virtualHosts.${host} = {
|
2024-10-07 14:40:26 -05:00
|
|
|
onlySSL = true;
|
2024-10-07 14:47:09 -05:00
|
|
|
sslCertificate = ollama.ssl.cert;
|
|
|
|
sslCertificateKey = ollama.ssl.key;
|
2024-10-07 14:28:40 -05:00
|
|
|
listen = [
|
|
|
|
{
|
2024-10-07 14:35:02 -05:00
|
|
|
addr = localhost;
|
|
|
|
port = 4443;
|
2024-10-07 14:28:40 -05:00
|
|
|
ssl = true;
|
|
|
|
}
|
|
|
|
];
|
|
|
|
locations."/" = {
|
2024-10-07 14:47:09 -05:00
|
|
|
proxyPass = "http://${localhost}:${toString ollama.ports.port0}";
|
2024-10-07 14:28:40 -05:00
|
|
|
extraConfig = ''
|
|
|
|
proxy_set_header Host $host;
|
|
|
|
proxy_set_header X-Real-IP $remote_addr;
|
|
|
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
|
|
|
proxy_set_header X-Forwarded-Proto $scheme;
|
2024-10-06 15:25:05 -05:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2024-10-07 14:47:09 -05:00
|
|
|
fileSystems."/var/lib/${ollama.name}" = {
|
|
|
|
device = ollama.paths.path0;
|
2024-10-06 15:25:05 -05:00
|
|
|
fsType = "none";
|
|
|
|
options = ["bind"];
|
|
|
|
depends = [server.storage0.mount];
|
|
|
|
};
|
|
|
|
|
2024-10-07 14:47:09 -05:00
|
|
|
systemd.tmpfiles.rules = [
|
|
|
|
"Z ${ollama.paths.path0} 0755 ${ollama.name} ${ollama.name} -"
|
|
|
|
"Z ${acme.paths.path0}/${host} 0755 ${ollama.name} ${ollama.name} -"
|
|
|
|
];
|
2024-10-06 15:25:05 -05:00
|
|
|
|
|
|
|
networking = {
|
|
|
|
firewall = {
|
|
|
|
allowedTCPPorts = [
|
2024-10-07 14:47:09 -05:00
|
|
|
ollama.ports.port0
|
|
|
|
ollama.ports.port1
|
2024-10-06 15:25:05 -05:00
|
|
|
];
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|