From b9cd8c1abbaa3e69986ce3a554945f35d7fe84c4 Mon Sep 17 00:00:00 2001 From: Nick Date: Mon, 3 Nov 2025 02:37:40 -0600 Subject: [PATCH] feat: broke up ollama file into two --- modules/nixos/services/ollama/default.nix | 118 ------------------ .../services/ollama/ollamaCeres/default.nix | 75 +++++++++++ .../services/ollama/ollamaMars/default.nix | 47 +++++++ 3 files changed, 122 insertions(+), 118 deletions(-) delete mode 100755 modules/nixos/services/ollama/default.nix create mode 100644 modules/nixos/services/ollama/ollamaCeres/default.nix create mode 100644 modules/nixos/services/ollama/ollamaMars/default.nix diff --git a/modules/nixos/services/ollama/default.nix b/modules/nixos/services/ollama/default.nix deleted file mode 100755 index 04ecee8..0000000 --- a/modules/nixos/services/ollama/default.nix +++ /dev/null @@ -1,118 +0,0 @@ -{ - flake, - config, - pkgs, - ... -}: -let - inherit (flake.config.machines.devices) - mars - ceres - ; - inherit (flake.config.services.instances) - ollama - web - ; - service = ollama; - localhost1 = web.localhost.address0; - localhost2 = web.localhost.address1; - hostname = config.networking.hostName; - host = service.domains.url0; - - localhostLogic = if hostname == mars.name then localhost2 else localhost1; - caddyLogic = - if hostname == ceres.name then - { - caddy = { - virtualHosts = { - ${host} = { - extraConfig = '' - reverse_proxy ${localhostLogic}:${toString service.ports.port0} - - tls ${service.ssl.cert} ${service.ssl.key} - ''; - }; - }; - }; - } - else - { }; - - mountLogic = - if hostname == ceres.name then - { - "/var/lib/${service.name}" = { - device = service.paths.path0; - fsType = "none"; - options = [ - "bind" - ]; - depends = [ - ceres.storage0.mount - ]; - }; - } - else - { }; -in -{ - services = { - ollama = { - enable = true; - group = service.name; - host = "http://${localhostLogic}"; - user = service.name; - } - // ( - if hostname == mars.name then - { - # models = service.paths.path1; - acceleration = "rocm"; - # package = pkgs.ollama.override { - # acceleration = "rocm"; - # }; - } - else - { - port = service.ports.port1; - acceleration = "cuda"; - models = service.paths.path0; - } - ); - open-webui = { - enable = true; - package = (flake.inputs.nixpkgs-stable.legacyPackages.${pkgs.system}.open-webui); - host = localhostLogic; - port = service.ports.port0; - environment = { - ENABLE_OLLAMA_API = "True"; - ANONYMIZED_TELEMETRY = "False"; - DO_NOT_TRACK = "True"; - SCARF_NO_ANALYTICS = "True"; - OLLAMA_BASE_URL = "http://${localhostLogic}:${toString service.ports.port1}"; - WEBUI_AUTH = "True"; - }; - }; - } - // caddyLogic; - - systemd.tmpfiles.rules = [ - ( - if hostname == mars.name then - "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; -} diff --git a/modules/nixos/services/ollama/ollamaCeres/default.nix b/modules/nixos/services/ollama/ollamaCeres/default.nix new file mode 100644 index 0000000..1caf8a2 --- /dev/null +++ b/modules/nixos/services/ollama/ollamaCeres/default.nix @@ -0,0 +1,75 @@ +{ + flake, + ... +}: +let + inherit (flake.config.machines.devices) + ceres + ; + inherit (flake.config.services.instances) + ollama + web + ; + service = ollama; + localhost = web.localhost.address0; + host = service.domains.url0; +in +{ + services = { + ollama = { + enable = true; + group = service.name; + host = "http://${localhost}"; + user = service.name; + port = service.ports.port1; + acceleration = "cuda"; + models = service.paths.path0; + }; + 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"; + }; + }; + caddy = { + virtualHosts = { + ${host} = { + extraConfig = '' + reverse_proxy ${localhost}:${toString service.ports.port0} + tls ${service.ssl.cert} ${service.ssl.key} + ''; + }; + }; + }; + }; + systemd.tmpfiles.rules = [ + "Z ${service.paths.path0} 0755 ${service.name} ${service.name} -" + ]; + networking = { + firewall = { + allowedTCPPorts = [ + service.ports.port0 + service.ports.port1 + ]; + }; + }; + fileSystems = { + "/var/lib/${service.name}" = { + device = service.paths.path0; + fsType = "none"; + options = [ + "bind" + ]; + depends = [ + ceres.storage0.mount + ]; + }; + }; +} diff --git a/modules/nixos/services/ollama/ollamaMars/default.nix b/modules/nixos/services/ollama/ollamaMars/default.nix new file mode 100644 index 0000000..3d1b272 --- /dev/null +++ b/modules/nixos/services/ollama/ollamaMars/default.nix @@ -0,0 +1,47 @@ +{ + flake, + ... +}: +let + inherit (flake.config.services.instances) + ollama + web + ; + service = ollama; + localhost = web.localhost.address1; +in +{ + services = { + ollama = { + enable = true; + group = service.name; + host = "http://${localhost}"; + user = service.name; + acceleration = "rocm"; + }; + 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"; + }; + }; + }; + systemd.tmpfiles.rules = [ + "Z ${service.paths.path1} 0777 ${service.name} ${service.name} -" + ]; + networking = { + firewall = { + allowedTCPPorts = [ + service.ports.port0 + service.ports.port1 + ]; + }; + }; +}