From 63e0d2d52d8824e811b41d1082ac4dda02be85be Mon Sep 17 00:00:00 2001 From: phibkro <71797726+phibkro@users.noreply.github.com> Date: Thu, 4 Jun 2026 08:13:10 +0200 Subject: [PATCH 1/2] ollama: 0.24.0 -> 0.30.4 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Notable upstream build changes folded into this bump: * llama.cpp moved from in-tree vendoring to CMake FetchContent, pinned via the `LLAMA_CPP_VERSION` file at the repo root (b9493 here → llama.cpp commit a731805c). Pre-stage it as `fetchFromGitHub` and apply Ollama's compat patch in `postPatch` — neither `cmake/local.cmake` nor `llama/server/CMakeLists.txt` auto-applies the patch when the source is overridden via `FETCHCONTENT_SOURCE_DIR_LLAMA_CPP` (the parent's `ExternalProject_Add` passes `OLLAMA_LLAMA_CPP_SKIP_COMPAT_PATCH=ON` to the child build). The `apply-patch.cmake` script is idempotent. * Since 0.30, `cmake/local.cmake` splits the llama.cpp build into per-runner sub-projects gated by `OLLAMA_LLAMA_BACKENDS`. Without setting it, only the CPU runner is built — `ollama-cuda` / `ollama-rocm` / `ollama-vulkan` would all silently fall back to CPU at runtime, with `libggml-{cuda,hip,vulkan}.so` absent from `$out/lib/ollama`. Map the package's `acceleration` value to the cmake backend name the elseif chain accepts: cuda → cuda_v${cudaMajor} (cuda_v12 / cuda_v13) rocm → rocm_v${rocmMajor}_${rocmMinor} (rocm_v7_1 / rocm_v7_2) vulkan → vulkan * `cmd/launch/*_test.go` are integration tests for user-facing CLI launchers (claude, qwen, cline, codex, kimi, droid, openclaw, hermes, …) that install the target binary via npm and exec it on PATH. Both prerequisites are unavailable in the nix sandbox, so the launch subpackage's tests can't pass here. Drop them — same precedent as the existing darwin Metal test removals. * The llama.cpp sub-build is driven by ExternalProject_Add and does not inherit the parent's `CMAKE_SKIP_BUILD_RPATH` setting, so its `.so` payloads end up with build-dir entries in RPATH. Strip with `patchelf --shrink-rpath --allowed-rpath-prefixes /nix/store` in preFixup; `$ORIGIN` is preserved unconditionally (non-absolute entries always allowed) so peer-lib lookup in `$out/lib/ollama` still works. Drive-by cleanup: deadnix + statix passes (overrideModAttrs unused lambda args → `_:_`, `inherit (rocmPackages) stdenv;` / `inherit (vulkan-tools) stdenv;` for `buildGoModule.override`, drop unused `coreutils` input — the old launch-test substitutions that needed coreutils are dropped along with the tests). Release notes: https://github.com/ollama/ollama/releases/tag/v0.30.4 https://github.com/ollama/ollama/releases/tag/v0.30.0 Assisted-by: Claude Opus 4.7 --- pkgs/by-name/ol/ollama/package.nix | 101 +++++++++++++++++++++-------- 1 file changed, 74 insertions(+), 27 deletions(-) diff --git a/pkgs/by-name/ol/ollama/package.nix b/pkgs/by-name/ol/ollama/package.nix index cc0520fad3f1..4181f137fe8d 100644 --- a/pkgs/by-name/ol/ollama/package.nix +++ b/pkgs/by-name/ol/ollama/package.nix @@ -7,7 +7,6 @@ stdenv, addDriverRunpath, nix-update-script, - coreutils, cmake, gitMinimal, @@ -108,6 +107,17 @@ let cudaPath = lib.removeSuffix "-${cudaMajorVersion}" cudaToolkit; + # Since v0.30, llama.cpp is consumed via CMake FetchContent rather than + # vendored in-tree. Pre-stage the pinned commit (read from upstream's + # `LLAMA_CPP_VERSION` file — currently `b9493`) so the FetchContent step + # uses our copy instead of trying to clone over the network in the sandbox. + llamaCppSrc = fetchFromGitHub { + owner = "ggml-org"; + repo = "llama.cpp"; + rev = "a731805cedc83c0514cbd808a2e38ec46c759cc2"; # tag b9493 + hash = "sha256-DO9J1mx9Jlp6qtCiJp2ZEi6R7H2YX1/sD7DGgBCtt0U="; + }; + wrapperOptions = [ # ollama embeds llama-cpp binaries which actually run the ai models # these llama-cpp binaries are unaffected by the ollama binary's DT_RUNPATH @@ -132,25 +142,25 @@ let if enableCuda then buildGoModule.override { stdenv = cudaPackages.backendStdenv; } else if enableRocm then - buildGoModule.override { stdenv = rocmPackages.stdenv; } + buildGoModule.override { inherit (rocmPackages) stdenv; } else if enableVulkan then - buildGoModule.override { stdenv = vulkan-tools.stdenv; } + buildGoModule.override { inherit (vulkan-tools) stdenv; } else buildGoModule; inherit (lib) licenses platforms maintainers; in goBuild (finalAttrs: { pname = "ollama"; - version = "0.24.0"; + version = "0.30.4"; src = fetchFromGitHub { owner = "ollama"; repo = "ollama"; tag = "v${finalAttrs.version}"; - hash = "sha256-cSZtbF0oUI7a++baTipF6OUu+w8tBpILzE0Wm1Y6wUk="; + hash = "sha256-IHX8o1Ty4Sdht5YeUYLnNPjOV7O95WeNng/coO+MHS8="; }; - vendorHash = "sha256-Lc1Ktdqtv2VhJQssk8K1UOimeEjVNvDWePE9WkamCos="; + vendorHash = "sha256-lZdGzGb9xRjTm1Rm7/wHjqM490gLznLEndmb4mNbCX0="; proxyVendor = true; env = @@ -190,25 +200,31 @@ goBuild (finalAttrs: { ++ lib.optionals enableVulkan vulkanLibs; # replace inaccurate version number with actual release version - # and replace core utils tools from their FHS location to nix store postPatch = '' substituteInPlace version/version.go \ --replace-fail 0.0.0 '${finalAttrs.version}' - substituteInPlace cmd/launch/openclaw_test.go \ - --replace-fail '/bin/mkdir' '${coreutils}/bin/mkdir' \ - --replace-fail '/bin/cat' '${coreutils}/bin/cat' \ - --replace-fail '/usr/bin/env' '${coreutils}/bin/env' \ - --replace-fail '/usr/bin/sort' '${coreutils}/bin/sort' \ - --replace-fail '/bin/chmod' '${coreutils}/bin/chmod' - substituteInPlace cmd/launch/hermes_test.go \ - --replace-fail '/bin/mkdir' '${coreutils}/bin/mkdir' \ - --replace-fail '/bin/cat' '${coreutils}/bin/cat' \ - --replace-fail '/bin/chmod' '${coreutils}/bin/chmod' - substituteInPlace cmd/launch/kimi_test.go \ - --replace-fail '/bin/mkdir' '${coreutils}/bin/mkdir' \ - --replace-fail '/bin/cat' '${coreutils}/bin/cat' \ - --replace-fail '/bin/chmod' '${coreutils}/bin/chmod' + + # cmd/launch/*_test.go are integration tests for user-facing CLI + # launchers (claude, qwen, cline, codex, kimi, droid, openclaw, hermes, + # …) that install the target binary via npm and then exec it on PATH. + # Both prerequisites are unavailable in the nix sandbox, so the launch + # subpackage's tests can't pass here. Drop them. + rm cmd/launch/*_test.go + rm -r app + + # Pre-stage llama.cpp for the FetchContent step and apply Ollama's + # compat patch. When FETCHCONTENT_SOURCE_DIR_LLAMA_CPP is set, neither + # `cmake/local.cmake` nor `llama/server/CMakeLists.txt` auto-applies + # the patch (the parent's ExternalProject_Add passes + # OLLAMA_LLAMA_CPP_SKIP_COMPAT_PATCH=ON to the child build) — the + # caller has to. The apply-patch.cmake script is idempotent so this + # is safe to re-run. + cp -r ${llamaCppSrc} $TMPDIR/llama-cpp-src + chmod -R +w $TMPDIR/llama-cpp-src + ( cd $TMPDIR/llama-cpp-src && \ + cmake -DPATCH_DIR=$NIX_BUILD_TOP/source/llama/compat \ + -P $NIX_BUILD_TOP/source/llama/compat/apply-patch.cmake ) '' # disable tests that fail in sandbox due to Metal init failure + lib.optionalString stdenv.hostPlatform.isDarwin '' @@ -217,12 +233,10 @@ goBuild (finalAttrs: { rm model/models/nemotronh/model_omni_test.go ''; - overrideModAttrs = ( - finalAttrs: prevAttrs: { - # don't run llama.cpp build in the module fetch phase - preBuild = ""; - } - ); + overrideModAttrs = _: _: { + # don't run llama.cpp build in the module fetch phase + preBuild = ""; + }; preBuild = let @@ -236,20 +250,53 @@ goBuild (finalAttrs: { cudaArchitectures = builtins.concatStringsSep ";" (map removeSMPrefix cudaArches); rocmTargets = builtins.concatStringsSep ";" rocmGpuTargets; + # Since 0.30, Ollama splits the llama.cpp build into per-accelerator + # "runners" gated by OLLAMA_LLAMA_BACKENDS. Without setting it the + # build silently produces only the CPU runner — ollama-cuda would + # ship without `libggml-cuda.so` and fall back to CPU at runtime. + # The accepted values map to cmake/local.cmake's elseif chain + # (cuda_v12 / cuda_v13 / rocm_v7_1 / rocm_v7_2 / vulkan / cuda_jetpack*). + rocmMajorVersion = lib.versions.major rocmPackages.clr.version; + rocmMinorVersion = lib.versions.minor rocmPackages.clr.version; + llamaBackend = + if enableCuda then + "cuda_v${cudaMajorVersion}" + else if enableRocm then + "rocm_v${rocmMajorVersion}_${rocmMinorVersion}" + else if enableVulkan then + "vulkan" + else + ""; + cmakeFlagsCudaArchitectures = lib.optionalString enableCuda "-DCMAKE_CUDA_ARCHITECTURES='${cudaArchitectures}'"; cmakeFlagsRocmTargets = lib.optionalString enableRocm "-DAMDGPU_TARGETS='${rocmTargets}'"; + cmakeFlagsBackend = lib.optionalString ( + llamaBackend != "" + ) "-DOLLAMA_LLAMA_BACKENDS=${llamaBackend}"; in '' cmake -B build \ -DCMAKE_SKIP_BUILD_RPATH=ON \ -DCMAKE_BUILD_WITH_INSTALL_RPATH=ON \ + -DFETCHCONTENT_SOURCE_DIR_LLAMA_CPP="$TMPDIR/llama-cpp-src" \ ${cmakeFlagsCudaArchitectures} \ ${cmakeFlagsRocmTargets} \ + ${cmakeFlagsBackend} cmake --build build -j $NIX_BUILD_CORES ''; + # The llama.cpp sub-build is driven by ExternalProject_Add and does + # not inherit the parent's CMAKE_SKIP_BUILD_RPATH setting, so its + # `.so` payloads end up with build-dir entries in RPATH. Drop them + # before the forbidden-references check. $ORIGIN is preserved + # unconditionally; only absolute /nix/store entries are kept. + preFixup = '' + find $out/lib/ollama -type f \( -name '*.so' -o -name '*.so.*' \) \ + -exec patchelf --shrink-rpath --allowed-rpath-prefixes /nix/store {} + + ''; + # ollama looks for acceleration libs in ../lib/ollama/ (now also for CPU-only with arch specific optimizations) # https://github.com/ollama/ollama/blob/v0.21.1/docs/development.md#library-detection postInstall = '' From 6432d78bff4d326d5dc2a26b46a4091b530c437e Mon Sep 17 00:00:00 2001 From: phibkro <71797726+phibkro@users.noreply.github.com> Date: Thu, 4 Jun 2026 11:24:14 +0200 Subject: [PATCH 2/2] =?UTF-8?q?ollama:=20fix=20vulkan=20variant=20?= =?UTF-8?q?=E2=80=94=20wire=20SPIRV-Headers=20across=20the=20ExternalProje?= =?UTF-8?q?ct=20boundary?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Two layers were missing for ollama-vulkan after the 0.30.x bump's switch to per-accelerator runners via ExternalProject_Add: 1. spirv-headers wasn't in nativeBuildInputs, so the parent cmake configure never even saw `SPIRV-HeadersConfig.cmake`. Add it (header-only — native is the right slot). 2. The runner sub-builds (`ollama-llama-server-vulkan` et al.) are launched by `cmake/local.cmake`'s `ExternalProject_Add`, whose child cmake process inherits env vars but not the parent's `-D` flags. Even after fixing (1), the child's `find_package(SPIRV-Headers REQUIRED)` at `ggml-vulkan/CMakeLists.txt:14` couldn't see the config, and once that was worked around with `CMAKE_PREFIX_PATH` as env, the compile then failed with `fatal error: spirv/unified1/spirv.hpp` — because upstream's `target_link_libraries(ggml-vulkan PRIVATE Vulkan::Vulkan)` notably does NOT link `SPIRV-Headers::SPIRV-Headers`, so the interface include path the cmake config exports never flows into the compile commands. Force the include via `NIX_CFLAGS_COMPILE` rather than patching upstream's CMakeLists across llama.cpp pins. Verified: `ollama-vulkan` builds end-to-end; `$out/lib/ollama/vulkan/libggml-vulkan.so` is present (not a silent CPU fallback like the cuda variant suffered in the first 0.30 attempt). 🤖 Assisted by Claude --- pkgs/by-name/ol/ollama/package.nix | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/pkgs/by-name/ol/ollama/package.nix b/pkgs/by-name/ol/ollama/package.nix index 4181f137fe8d..ff7f72b6883c 100644 --- a/pkgs/by-name/ol/ollama/package.nix +++ b/pkgs/by-name/ol/ollama/package.nix @@ -21,6 +21,7 @@ vulkan-tools, vulkan-headers, vulkan-loader, + spirv-headers, shaderc, ccache, @@ -191,6 +192,10 @@ goBuild (finalAttrs: { ] ++ lib.optionals enableVulkan [ ccache + # ggml-vulkan/CMakeLists.txt does `find_package(SPIRV-Headers REQUIRED)` + # at configure time (it builds shader code into the vulkan backend). + # Header-only — nativeBuildInputs is the right slot. + spirv-headers ]; buildInputs = @@ -276,6 +281,28 @@ goBuild (finalAttrs: { in '' + ${lib.optionalString enableVulkan '' + # Ollama builds each per-accelerator llama.cpp runner via + # cmake/local.cmake's ExternalProject_Add(ollama-llama-server-vulkan …). + # Two things need to cross the parent → child boundary: + # + # 1. The SPIRV-Headers cmake config — so `find_package(SPIRV-Headers + # REQUIRED)` at ggml-vulkan/CMakeLists.txt:14 succeeds in the + # child. CMAKE_PREFIX_PATH as a flag wouldn't propagate; as env + # var it does. + # 2. The SPIRV-Headers include directory in the compile env. The + # ggml-vulkan target's `target_link_libraries(... Vulkan::Vulkan)` + # notably does NOT link `SPIRV-Headers::SPIRV-Headers`, so the + # interface include directory the cmake config exports never + # flows into the compile commands — even though the find_package + # call succeeded. `#include ` then + # fails at compile time. Patching upstream's CMakeLists for + # one missing link line is fragile across llama.cpp pins; + # NIX_CFLAGS_COMPILE forces the include path globally and + # survives version bumps. + export CMAKE_PREFIX_PATH="${spirv-headers}''${CMAKE_PREFIX_PATH:+:$CMAKE_PREFIX_PATH}" + export NIX_CFLAGS_COMPILE="-isystem ${spirv-headers}/include $NIX_CFLAGS_COMPILE" + ''} cmake -B build \ -DCMAKE_SKIP_BUILD_RPATH=ON \ -DCMAKE_BUILD_WITH_INSTALL_RPATH=ON \