ollama: fix vulkan variant — wire SPIRV-Headers across the ExternalProject boundary

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
This commit is contained in:
phibkro
2026-06-04 11:24:14 +02:00
parent 63e0d2d52d
commit 6432d78bff

View File

@@ -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 <spirv/unified1/spirv.hpp>` 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 \