2025-02-05 20:15:36 -06:00
|
|
|
{
|
|
|
|
flake,
|
|
|
|
config,
|
|
|
|
pkgs,
|
|
|
|
...
|
|
|
|
}:
|
|
|
|
let
|
|
|
|
inherit (flake.config.machines.devices)
|
2025-03-01 15:55:23 -06:00
|
|
|
mars
|
2025-02-17 18:52:02 -06:00
|
|
|
ceres
|
2025-02-05 20:15:36 -06:00
|
|
|
;
|
|
|
|
inherit (flake.config.services.instances)
|
|
|
|
ollama
|
|
|
|
web
|
|
|
|
;
|
|
|
|
service = ollama;
|
|
|
|
localhost = web.localhost.address0;
|
|
|
|
hostname = config.networking.hostName;
|
|
|
|
host = "${service.subdomain}.${web.domains.url0}";
|
|
|
|
|
|
|
|
caddyLogic =
|
2025-02-17 18:52:02 -06:00
|
|
|
if hostname == ceres.name then
|
2025-02-05 20:15:36 -06:00
|
|
|
{
|
|
|
|
caddy = {
|
|
|
|
virtualHosts = {
|
|
|
|
${host} = {
|
|
|
|
extraConfig = ''
|
|
|
|
reverse_proxy ${localhost}:${toString service.ports.port0}
|
|
|
|
|
|
|
|
tls ${service.ssl.cert} ${service.ssl.key}
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{ };
|
|
|
|
|
|
|
|
mountLogic =
|
2025-02-17 18:52:02 -06:00
|
|
|
if hostname == ceres.name then
|
2025-02-05 20:15:36 -06:00
|
|
|
{
|
|
|
|
"/var/lib/${service.name}" = {
|
|
|
|
device = service.paths.path0;
|
|
|
|
fsType = "none";
|
|
|
|
options = [
|
|
|
|
"bind"
|
|
|
|
];
|
|
|
|
depends = [
|
2025-02-17 18:52:02 -06:00
|
|
|
ceres.storage0.mount
|
2025-02-05 20:15:36 -06:00
|
|
|
];
|
|
|
|
};
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{ };
|
|
|
|
in
|
|
|
|
{
|
|
|
|
services = {
|
|
|
|
ollama =
|
|
|
|
{
|
|
|
|
enable = true;
|
|
|
|
group = service.name;
|
|
|
|
host = "http://${localhost}";
|
|
|
|
user = service.name;
|
|
|
|
}
|
|
|
|
// (
|
2025-03-01 15:55:23 -06:00
|
|
|
if hostname == mars.name then
|
2025-02-05 20:15:36 -06:00
|
|
|
{
|
2025-03-09 19:37:13 -05:00
|
|
|
# models = service.paths.path1;
|
|
|
|
acceleration = "rocm";
|
|
|
|
package = pkgs.ollama.override {
|
|
|
|
config = {
|
|
|
|
rocmSupport = true;
|
|
|
|
cudaSupport = false;
|
|
|
|
};
|
|
|
|
};
|
2025-02-05 20:15:36 -06:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
port = service.ports.port1;
|
|
|
|
acceleration = false;
|
2025-02-17 16:29:19 -06:00
|
|
|
models = service.paths.path0;
|
2025-02-05 20:15:36 -06:00
|
|
|
}
|
|
|
|
);
|
|
|
|
open-webui = {
|
|
|
|
enable = true;
|
|
|
|
host = localhost;
|
|
|
|
port = service.ports.port0;
|
|
|
|
environment = {
|
|
|
|
ENABLE_OLLAMA_API = "True";
|
|
|
|
ANONYMIZED_TELEMETRY = "False";
|
|
|
|
DO_NOT_TRACK = "True";
|
|
|
|
SCARF_NO_ANALYTICS = "True";
|
|
|
|
OLLAMA_BASE_URL = "http://${localhost}:${toString service.ports.port1}";
|
|
|
|
WEBUI_AUTH = "True";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
} // caddyLogic;
|
|
|
|
|
|
|
|
systemd.tmpfiles.rules = [
|
|
|
|
(
|
2025-03-01 15:55:23 -06:00
|
|
|
if hostname == mars.name then
|
2025-02-05 20:15:36 -06:00
|
|
|
"Z ${service.paths.path1} 0777 ${service.name} ${service.name} -"
|
|
|
|
else
|
|
|
|
"Z ${service.paths.path0} 0755 ${service.name} ${service.name} -"
|
|
|
|
)
|
|
|
|
];
|
|
|
|
|
|
|
|
networking = {
|
|
|
|
firewall = {
|
|
|
|
allowedTCPPorts = [
|
|
|
|
# 8080
|
|
|
|
service.ports.port0
|
|
|
|
service.ports.port1
|
|
|
|
];
|
|
|
|
};
|
|
|
|
};
|
|
|
|
fileSystems = mountLogic;
|
|
|
|
}
|