From b4443ea1317506ba795dff739815404a9fc23580 Mon Sep 17 00:00:00 2001 From: emmatherock Date: Mon, 31 Aug 2026 03:59:06 -0300 Subject: [PATCH] feat(homelab): add Ollama service with ROCm --- hosts/miku-homelab/default.nix | 8 ++++++++ modules/services/ollama.nix | 35 ++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+) create mode 100644 modules/services/ollama.nix diff --git a/hosts/miku-homelab/default.nix b/hosts/miku-homelab/default.nix index 4ee7778..135d8a9 100644 --- a/hosts/miku-homelab/default.nix +++ b/hosts/miku-homelab/default.nix @@ -5,6 +5,7 @@ ./hardware-configuration.nix ../../modules/profiles/desktop.nix ../../modules/profiles/server.nix + ../../modules/services/ollama.nix ../../modules/services/samba.nix ../../modules/system/home-profile.nix ../../modules/system/nix-ld.nix @@ -157,5 +158,12 @@ experimental-features = [ "nix-command" "flakes" ]; }; + zramSwap = { + enable = true; + algorithm = "zstd"; + memoryPercent = 50; + priority = 100; + }; + system.stateVersion = "25.11"; } diff --git a/modules/services/ollama.nix b/modules/services/ollama.nix new file mode 100644 index 0000000..0f272b4 --- /dev/null +++ b/modules/services/ollama.nix @@ -0,0 +1,35 @@ +{ pkgs, ... }: + +{ + services.ollama = { + enable = true; + # `services.ollama.acceleration` does not exist (that option only lives on + # services.tabby); GPU backend selection for ollama is done by package choice. + package = pkgs.ollama-rocm; + + # Same "don't expose services directly" pattern as the rest of the homelab: + # bind to localhost only. If this needs to be reachable from other devices + # later, put it behind Traefik + Headscale like the other services instead + # of opening it up directly. + host = "127.0.0.1"; + port = 11434; + + environmentVariables = { + # Ollama is on-demand by design: it loads a model into VRAM on the first + # request and unloads it after this much idle time. 5m is already the + # ollama default, set explicitly so it's not an implicit behavior. + OLLAMA_KEEP_ALIVE = "5m"; + }; + + # RDNA4 (gfx1200/gfx1201, incl. the RX 9060 XT) has official ROCm support + # since ROCm 6.4.4. Verified on this host (2026-08-30) with rocmPackages.clr + # 7.2.3: `rocminfo` correctly reports "Name: gfx1200" and `rocm-smi + # --showmeminfo vram` reports the full 16GiB, so the "detected with 0 VRAM, + # falls back to CPU" issue does not reproduce here and rocmOverrideGfx is + # not needed. If a future nixpkgs bump regresses this, re-check with: + # nix shell nixpkgs#rocmPackages.rocminfo -c rocminfo | grep -i gfx + # nix shell nixpkgs#rocmPackages.rocm-smi -c rocm-smi --showmeminfo vram + # and only then set rocmOverrideGfx = "12.0.0"; (gfx1200) if VRAM reports 0. + # rocmOverrideGfx = "12.0.0"; + }; +}