From 6ea1430eeeea1d319461ac1f11170578c185f0ce Mon Sep 17 00:00:00 2001
From: Myned <dev@bjork.tech>
Date: Mon, 17 Mar 2025 22:31:19 -0500
Subject: [PATCH] ollama: move rocm option to program

---
 machines/mynix/default.nix           | 1 +
 machines/myork/default.nix           | 4 ----
 options/custom/services/ollama.nix   | 9 ++++-----
 options/custom/settings/hardware.nix | 1 +
 4 files changed, 6 insertions(+), 9 deletions(-)

diff --git a/machines/mynix/default.nix b/machines/mynix/default.nix
index b9b2c2f..f825af5 100644
--- a/machines/mynix/default.nix
+++ b/machines/mynix/default.nix
@@ -29,6 +29,7 @@
 
       hardware = {
         gpu = "amd";
+        rocm = "10.3.0"; # 10.3.1
       };
 
       storage.mnt = [
diff --git a/machines/myork/default.nix b/machines/myork/default.nix
index 90b06ca..d99c75a 100644
--- a/machines/myork/default.nix
+++ b/machines/myork/default.nix
@@ -28,10 +28,6 @@
 
     services = {
       fw-fanctrl.enable = true;
-
-      # https://github.com/ollama/ollama/blob/main/docs/gpu.md#overrides
-      #?? nix run nixpkgs#rocmPackages.rocminfo | grep gfx
-      ollama.rocmOverrideGfx = "10.3.0"; # 10.3.1
     };
 
     settings = {
diff --git a/options/custom/services/ollama.nix b/options/custom/services/ollama.nix
index 9f19402..b84716e 100644
--- a/options/custom/services/ollama.nix
+++ b/options/custom/services/ollama.nix
@@ -1,7 +1,6 @@
 {
   config,
   lib,
-  pkgs,
   ...
 }:
 with lib; let
@@ -17,11 +16,11 @@ in {
     services.ollama = {
       enable = true;
       openFirewall = true;
-      package = pkgs.ollama-rocm;
 
-      loadModels = [
-        "deepseek-r1" # https://github.com/deepseek-ai/DeepSeek-R1
-      ];
+      # https://wiki.nixos.org/wiki/Ollama#AMD_GPU_with_open_source_driver
+      # https://github.com/ollama/ollama/blob/main/docs/gpu.md#overrides
+      #?? nix run nixpkgs#rocmPackages.rocminfo | grep gfx
+      rocmOverrideGfx = with config.custom.settings.hardware; mkIf (isString rocm) rocm;
     };
   };
 }
diff --git a/options/custom/settings/hardware.nix b/options/custom/settings/hardware.nix
index d341b83..e94d31a 100644
--- a/options/custom/settings/hardware.nix
+++ b/options/custom/settings/hardware.nix
@@ -9,6 +9,7 @@ in {
   options.custom.settings.hardware = {
     enable = mkOption {default = false;};
     gpu = mkOption {default = null;};
+    rocm = mkOption {default = null;};
   };
 
   config = mkIf cfg.enable {