about summary refs log tree commit diff
path: root/nixos/modules/services/misc/ollama.nix
diff options
context:
space:
mode:
authorabysssol <abysssol@pm.me>2024-02-22 23:41:25 -0500
committerabysssol <abysssol@pm.me>2024-02-25 15:57:58 -0500
commitb8d8c1f207a8c80f7267920efa70db785e5d441e (patch)
treec2e3652d3df6e8e62005d786b92ab4e1a9d611d9 /nixos/modules/services/misc/ollama.nix
parent70e834c19b24957546e5e54c9ffbe33ace422d27 (diff)
nixos/ollama: add option for hardware acceleration
Diffstat (limited to 'nixos/modules/services/misc/ollama.nix')
-rw-r--r--nixos/modules/services/misc/ollama.nix33
1 files changed, 23 insertions, 10 deletions
diff --git a/nixos/modules/services/misc/ollama.nix b/nixos/modules/services/misc/ollama.nix
index d9359d2b5cd44..0d3574a2bac08 100644
--- a/nixos/modules/services/misc/ollama.nix
+++ b/nixos/modules/services/misc/ollama.nix
@@ -1,9 +1,14 @@
-{ config, lib, pkgs, ... }: let
+{ config, lib, pkgs, ... }:
+let
+  inherit (lib.types) nullOr enum;
 
   cfg = config.services.ollama;
-
-in {
-
+  ollamaPackage = cfg.package.override {
+    inherit (cfg) acceleration;
+    linuxPackages.nvidia_x11 = config.hardware.nvidia.package;
+  };
+in
+{
   options = {
     services.ollama = {
       enable = lib.mkEnableOption (
@@ -16,12 +21,22 @@ in {
           Specifies the bind address on which the ollama server HTTP interface listens.
         '';
       };
+      acceleration = lib.mkOption {
+        type = nullOr (enum [ "rocm" "cuda" ]);
+        default = null;
+        example = "rocm";
+        description = lib.mdDoc ''
+          Specifies the interface to use for hardware acceleration.
+
+          - `rocm`: supported by modern AMD GPUs
+          - `cuda`: supported by modern NVIDIA GPUs
+        '';
+      };
       package = lib.mkPackageOption pkgs "ollama" { };
     };
   };
 
   config = lib.mkIf cfg.enable {
-
     systemd = {
       services.ollama = {
         wantedBy = [ "multi-user.target" ];
@@ -33,7 +48,7 @@ in {
           OLLAMA_HOST = cfg.listenAddress;
         };
         serviceConfig = {
-          ExecStart = "${lib.getExe cfg.package} serve";
+          ExecStart = "${lib.getExe ollamaPackage} serve";
           WorkingDirectory = "/var/lib/ollama";
           StateDirectory = [ "ollama" ];
           DynamicUser = true;
@@ -41,10 +56,8 @@ in {
       };
     };
 
-    environment.systemPackages = [ cfg.package ];
-
+    environment.systemPackages = [ ollamaPackage ];
   };
 
-  meta.maintainers = with lib.maintainers; [ onny ];
-
+  meta.maintainers = with lib.maintainers; [ abysssol onny ];
 }