15 , autoAddDriverRunpath
16 , cudaSupport ? config.cudaSupport
21 # It's necessary to consistently use backendStdenv when building with CUDA support,
22 # otherwise we get libstdc++ errors downstream.
23 # cuda imposes an upper bound on the gcc version, e.g. the latest gcc compatible with cudaPackages_11 is gcc11
24 effectiveStdenv = if cudaSupport then cudaPackages.backendStdenv else stdenv;
26 effectiveStdenv.mkDerivation (finalAttrs: {
27 pname = "whisper-cpp";
30 src = fetchFromGitHub {
33 rev = "refs/tags/v${finalAttrs.version}" ;
34 hash = "sha256-EDFUVjud79ZRCzGbOh9L9NcXfN3ikvsqkVSOME9F9oo=";
37 # The upstream download script tries to download the models to the
38 # directory of the script, which is not writable due to being
39 # inside the nix store. This patch changes the script to download
40 # the models to the current directory of where it is being run from.
41 patches = [ ./download-models.patch ];
46 ] ++ lib.optionals cudaSupport [
47 cudaPackages.cuda_nvcc
53 ] ++ lib.optionals stdenv.hostPlatform.isDarwin [
59 ] ++ lib.optionals cudaSupport ( with cudaPackages; [
60 cuda_cccl # provides nv/target
66 cudaOldStr = "-lcuda ";
67 cudaNewStr = "-lcuda -L${cudaPackages.cuda_cudart}/lib/stubs ";
68 in lib.optionalString cudaSupport ''
69 substituteInPlace Makefile \
70 --replace-fail '${cudaOldStr}' '${cudaNewStr}'
73 env = lib.optionalAttrs stdenv.hostPlatform.isDarwin {
75 WHISPER_COREML_ALLOW_FALLBACK = "1";
76 WHISPER_METAL_EMBED_LIBRARY = "1";
77 } // lib.optionalAttrs cudaSupport {
86 cp ./main $out/bin/whisper-cpp
89 if [[ -x "$file" && -f "$file" && "$file" != "main" ]]; then
90 cp "$file" "$out/bin/whisper-cpp-$file"
94 cp models/download-ggml-model.sh $out/bin/whisper-cpp-download-ggml-model
96 wrapProgram $out/bin/whisper-cpp-download-ggml-model \
97 --prefix PATH : ${lib.makeBinPath [wget]}
103 description = "Port of OpenAI's Whisper model in C/C++";
105 To download the models as described in the project's readme, you may
106 use the `whisper-cpp-download-ggml-model` binary from this package.
108 homepage = "https://github.com/ggerganov/whisper.cpp";
109 license = licenses.mit;
110 platforms = platforms.all;
111 maintainers = with maintainers; [ dit7ya hughobrien ];