fix(nix): enable Vulkan GPU inference for pywhispercpp (#942)

Nice work, Vulkan acceleration on Nix has been a long time coming.
This commit is contained in:
Depfrost
2026-10-11 23:07:31 -07:00
committed by GitHub
parent 4beb58c585
commit f10eb64fa0
3 changed files with 22 additions and 9 deletions
+17 -6
View File
@@ -9,6 +9,10 @@
setuptools,
wheel,
cmake,
shaderc,
spirv-headers,
vulkan-headers,
vulkan-loader,
numpy,
requests,
tqdm,
@@ -48,10 +52,10 @@ buildPythonPackage rec {
env = {
# The sdist ships no version.txt; setup.py falls back to this env var.
PYWHISPERCPP_VERSION = version;
# One static extension module (BUILD_SHARED_LIBS defaults ON upstream and
# would need $ORIGIN rpath repair that never runs outside cibuildwheel) and
# a portable baseline instead of -march=native.
CMAKE_ARGS = "-DBUILD_SHARED_LIBS=OFF -DGGML_NATIVE=OFF -DCMAKE_POSITION_INDEPENDENT_CODE=ON";
# Build Vulkan as a shared backend: Vocalinux's GPU detector looks for
# libggml-vulkan.so. CMake's build-tree RPATH can leak /build into the
# wheel; disable CMake RPATHs and let autoPatchelfHook set Nix runtime paths.
CMAKE_ARGS = "-DBUILD_SHARED_LIBS=ON -DGGML_NATIVE=OFF -DGGML_VULKAN=ON -DCMAKE_POSITION_INDEPENDENT_CODE=ON -DCMAKE_SKIP_RPATH=ON";
};
# env attrs are exported verbatim; expanding the core count needs a shell
@@ -67,6 +71,7 @@ buildPythonPackage rec {
nativeBuildInputs = [
cmake
shaderc # provides glslc, used to compile whisper.cpp's Vulkan shaders
autoPatchelfHook
];
@@ -75,8 +80,14 @@ buildPythonPackage rec {
wheel
];
# libstdc++/libgomp for the compiled extension.
buildInputs = [ stdenv.cc.cc.lib ];
# CMake's Vulkan backend calls find_package(SPIRV-Headers CONFIG REQUIRED),
# so expose the package configuration as well as the Vulkan headers/loader.
buildInputs = [
stdenv.cc.cc.lib
spirv-headers
vulkan-headers
vulkan-loader
];
dependencies = [
numpy