From 778cc3144c1362eaaf2d65e3ef95d058c509f7f7 Mon Sep 17 00:00:00 2001 From: abysssol Date: Fri, 28 Nov 2025 11:34:13 -0500 Subject: [PATCH 1/3] ollama-cpu: init --- pkgs/top-level/all-packages.nix | 1 + 1 file changed, 1 insertion(+) diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index 594372aac537..6e8debd51e9b 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -390,6 +390,7 @@ with pkgs; oletools = with python3.pkgs; toPythonApplication oletools; + ollama-cpu = callPackage ../by-name/ol/ollama/package.nix { acceleration = false; }; ollama-rocm = callPackage ../by-name/ol/ollama/package.nix { acceleration = "rocm"; }; ollama-cuda = callPackage ../by-name/ol/ollama/package.nix { acceleration = "cuda"; }; ollama-vulkan = callPackage ../by-name/ol/ollama/package.nix { acceleration = "vulkan"; }; From b3074a5df8a4610ac109657510d496c4595faa84 Mon Sep 17 00:00:00 2001 From: abysssol Date: Fri, 28 Nov 2025 11:36:52 -0500 Subject: [PATCH 2/3] ollama: refactor --- pkgs/by-name/ol/ollama/package.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkgs/by-name/ol/ollama/package.nix b/pkgs/by-name/ol/ollama/package.nix index b8157801d5de..274f50064e2a 100644 --- a/pkgs/by-name/ol/ollama/package.nix +++ b/pkgs/by-name/ol/ollama/package.nix @@ -57,7 +57,7 @@ let rocmRequested = shouldEnable "rocm" config.rocmSupport; cudaRequested = shouldEnable "cuda" config.cudaSupport; - vulkanRequested = shouldEnable "vulkan" false; + vulkanRequested = acceleration == "vulkan"; enableRocm = rocmRequested && stdenv.hostPlatform.isLinux; enableCuda = cudaRequested && stdenv.hostPlatform.isLinux; From 1aa800def6a24855b809c4bc5b4f51bc7fb3f01c Mon Sep 17 00:00:00 2001 From: abysssol Date: Fri, 28 Nov 2025 11:57:32 -0500 Subject: [PATCH 3/3] nixos/ollama: remove `acceleration` option in favor of setting `package` --- nixos/modules/services/misc/ollama.nix | 59 ++++++++++++-------------- nixos/tests/ollama-cuda.nix | 4 +- nixos/tests/ollama-rocm.nix | 4 +- nixos/tests/ollama-vulkan.nix | 4 +- 4 files changed, 33 insertions(+), 38 deletions(-) diff --git a/nixos/modules/services/misc/ollama.nix b/nixos/modules/services/misc/ollama.nix index 3d17fa484f43..975421e05162 100644 --- a/nixos/modules/services/misc/ollama.nix +++ b/nixos/modules/services/misc/ollama.nix @@ -8,7 +8,7 @@ let inherit (lib) literalExpression types; cfg = config.services.ollama; - ollamaPackage = cfg.package.override { inherit (cfg) acceleration; }; + ollama = lib.getExe cfg.package; staticUser = cfg.user != null && cfg.group != null; in @@ -32,12 +32,33 @@ in ] "The `models` directory is now always writable. To make other directories writable, use `systemd.services.ollama.serviceConfig.ReadWritePaths`." ) + (lib.mkRemovedOptionModule [ + "services" + "ollama" + "acceleration" + ] "Set `services.ollama.package` to one of `pkgs.ollama[,-vulkan,-rocm,-cuda,-cpu]` instead.") ]; options = { services.ollama = { enable = lib.mkEnableOption "ollama server for local large language models"; - package = lib.mkPackageOption pkgs "ollama" { }; + package = lib.mkPackageOption pkgs "ollama" { + example = "pkgs.ollama-rocm"; + extraDescription = '' + Different packages use different hardware acceleration. + + - `ollama`: default behavior; usually equivalent to `ollama-cpu` + - if `nixpkgs.config.rocmSupport` is enabled, is equivalent to `ollama-rocm` + - if `nixpkgs.config.cudaSupport` is enabled, is equivalent to `ollama-cuda` + - otherwise defaults to `false` + - `ollama-cpu`: disable GPU; only use CPU + - `ollama-rocm`: supported by most modern AMD GPUs + - may require overriding gpu type with `services.ollama.rocmOverrideGfx` + if rocm doesn't detect your AMD gpu + - `ollama-cuda`: supported by most modern NVIDIA GPUs + - `ollama-vulkan`: supported by most GPUs + ''; + }; user = lib.mkOption { type = with types; nullOr str; @@ -97,32 +118,6 @@ in ''; }; - acceleration = lib.mkOption { - type = types.nullOr ( - types.enum [ - false - "rocm" - "cuda" - "vulkan" - ] - ); - default = null; - example = "rocm"; - description = '' - What interface to use for hardware acceleration. - - - `null`: default behavior - - if `nixpkgs.config.rocmSupport` is enabled, uses `"rocm"` - - if `nixpkgs.config.cudaSupport` is enabled, uses `"cuda"` - - otherwise defaults to `false` - - `false`: disable GPU, only use CPU - - `"rocm"`: supported by most modern AMD GPUs - - may require overriding gpu type with `services.ollama.rocmOverrideGfx` - if rocm doesn't detect your AMD gpu - - `"cuda"`: supported by most modern NVIDIA GPUs - - `"vulkan"`: supported by most modern GPUs on Linux - ''; - }; rocmOverrideGfx = lib.mkOption { type = types.nullOr types.str; default = null; @@ -152,6 +147,7 @@ in Since `ollama run` is mostly a shell around the ollama server, this is usually sufficient. ''; }; + loadModels = lib.mkOption { type = types.listOf types.str; apply = builtins.filter (model: model != ""); @@ -180,6 +176,7 @@ in removing any models that are installed but not currently declared there. ''; }; + openFirewall = lib.mkOption { type = types.bool; default = false; @@ -224,7 +221,7 @@ in // { Type = "exec"; DynamicUser = true; - ExecStart = "${lib.getExe ollamaPackage} serve"; + ExecStart = "${ollama} serve"; WorkingDirectory = cfg.home; StateDirectory = [ "ollama" ]; ReadWritePaths = [ @@ -309,13 +306,11 @@ in script = let binaryInputs = lib.mapAttrs (_: lib.getExe) { - ollama = ollamaPackage; parallel = pkgs.parallel; awk = pkgs.gawk; sed = pkgs.gnused; }; inherit (binaryInputs) - ollama parallel awk sed @@ -355,7 +350,7 @@ in networking.firewall = lib.mkIf cfg.openFirewall { allowedTCPPorts = [ cfg.port ]; }; - environment.systemPackages = [ ollamaPackage ]; + environment.systemPackages = [ cfg.package ]; }; meta.maintainers = with lib.maintainers; [ diff --git a/nixos/tests/ollama-cuda.nix b/nixos/tests/ollama-cuda.nix index bbab7e24d35c..433b05f8bebe 100644 --- a/nixos/tests/ollama-cuda.nix +++ b/nixos/tests/ollama-cuda.nix @@ -1,4 +1,4 @@ -{ lib, ... }: +{ lib, pkgs, ... }: { name = "ollama-cuda"; meta.maintainers = with lib.maintainers; [ abysssol ]; @@ -7,7 +7,7 @@ { ... }: { services.ollama.enable = true; - services.ollama.acceleration = "cuda"; + services.ollama.package = pkgs.ollama-cuda; }; testScript = '' diff --git a/nixos/tests/ollama-rocm.nix b/nixos/tests/ollama-rocm.nix index 81915630d950..9d9d22c2c6ca 100644 --- a/nixos/tests/ollama-rocm.nix +++ b/nixos/tests/ollama-rocm.nix @@ -1,4 +1,4 @@ -{ lib, ... }: +{ lib, pkgs, ... }: { name = "ollama-rocm"; meta.maintainers = with lib.maintainers; [ abysssol ]; @@ -7,7 +7,7 @@ { ... }: { services.ollama.enable = true; - services.ollama.acceleration = "rocm"; + services.ollama.package = pkgs.ollama-rocm; }; testScript = '' diff --git a/nixos/tests/ollama-vulkan.nix b/nixos/tests/ollama-vulkan.nix index c4f210ad26c8..b721b3079aa2 100644 --- a/nixos/tests/ollama-vulkan.nix +++ b/nixos/tests/ollama-vulkan.nix @@ -1,4 +1,4 @@ -{ lib, ... }: +{ lib, pkgs, ... }: { name = "ollama-vulkan"; meta.maintainers = with lib.maintainers; [ abysssol ]; @@ -7,7 +7,7 @@ { ... }: { services.ollama.enable = true; - services.ollama.acceleration = "vulkan"; + services.ollama.package = pkgs.ollama-vulkan; }; testScript = ''