2023-01-11 07:51:40 +00:00
|
|
|
{ lib
|
|
|
|
, stdenv
|
|
|
|
, fetchFromGitHub
|
|
|
|
, SDL2
|
|
|
|
, makeWrapper
|
|
|
|
, wget
|
2024-02-29 20:09:43 +00:00
|
|
|
, which
|
2023-01-11 07:51:40 +00:00
|
|
|
, Accelerate
|
|
|
|
, CoreGraphics
|
2023-07-15 17:15:38 +00:00
|
|
|
, CoreML
|
2023-01-11 07:51:40 +00:00
|
|
|
, CoreVideo
|
2024-01-13 08:15:51 +00:00
|
|
|
, MetalKit
|
2024-01-25 14:12:00 +00:00
|
|
|
|
|
|
|
, config
|
2024-04-21 15:54:59 +00:00
|
|
|
, autoAddDriverRunpath
|
2024-01-25 14:12:00 +00:00
|
|
|
, cudaSupport ? config.cudaSupport
|
|
|
|
, cudaPackages ? {}
|
2023-01-11 07:51:40 +00:00
|
|
|
}:
|
|
|
|
|
2024-01-25 14:12:00 +00:00
|
|
|
let
|
|
|
|
# It's necessary to consistently use backendStdenv when building with CUDA support,
|
|
|
|
# otherwise we get libstdc++ errors downstream.
|
|
|
|
# cuda imposes an upper bound on the gcc version, e.g. the latest gcc compatible with cudaPackages_11 is gcc11
|
|
|
|
effectiveStdenv = if cudaSupport then cudaPackages.backendStdenv else stdenv;
|
|
|
|
in
|
|
|
|
effectiveStdenv.mkDerivation (finalAttrs: {
|
2023-01-11 07:51:40 +00:00
|
|
|
pname = "whisper-cpp";
|
2024-10-23 06:41:50 +00:00
|
|
|
version = "1.7.1";
|
2023-01-11 07:51:40 +00:00
|
|
|
|
|
|
|
src = fetchFromGitHub {
|
|
|
|
owner = "ggerganov";
|
|
|
|
repo = "whisper.cpp";
|
2024-01-25 14:12:00 +00:00
|
|
|
rev = "refs/tags/v${finalAttrs.version}" ;
|
2024-10-23 06:41:50 +00:00
|
|
|
hash = "sha256-EDFUVjud79ZRCzGbOh9L9NcXfN3ikvsqkVSOME9F9oo=";
|
2023-01-11 07:51:40 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
# The upstream download script tries to download the models to the
|
|
|
|
# directory of the script, which is not writable due to being
|
|
|
|
# inside the nix store. This patch changes the script to download
|
|
|
|
# the models to the current directory of where it is being run from.
|
|
|
|
patches = [ ./download-models.patch ];
|
|
|
|
|
2024-01-25 14:12:00 +00:00
|
|
|
nativeBuildInputs = [
|
2024-02-29 20:09:43 +00:00
|
|
|
which
|
2024-01-25 14:12:00 +00:00
|
|
|
makeWrapper
|
2024-04-21 15:54:59 +00:00
|
|
|
] ++ lib.optionals cudaSupport [
|
|
|
|
cudaPackages.cuda_nvcc
|
|
|
|
autoAddDriverRunpath
|
|
|
|
];
|
2024-01-25 14:12:00 +00:00
|
|
|
|
|
|
|
buildInputs = [
|
|
|
|
SDL2
|
2024-09-26 11:04:55 +00:00
|
|
|
] ++ lib.optionals stdenv.hostPlatform.isDarwin [
|
2024-01-25 14:12:00 +00:00
|
|
|
Accelerate
|
|
|
|
CoreGraphics
|
|
|
|
CoreML
|
|
|
|
CoreVideo
|
|
|
|
MetalKit
|
|
|
|
] ++ lib.optionals cudaSupport ( with cudaPackages; [
|
2024-07-27 06:49:29 +00:00
|
|
|
cuda_cccl # provides nv/target
|
|
|
|
cuda_cudart
|
|
|
|
libcublas
|
2024-01-25 14:12:00 +00:00
|
|
|
]);
|
|
|
|
|
|
|
|
postPatch = let
|
|
|
|
cudaOldStr = "-lcuda ";
|
2024-07-27 06:49:29 +00:00
|
|
|
cudaNewStr = "-lcuda -L${cudaPackages.cuda_cudart}/lib/stubs ";
|
2024-01-25 14:12:00 +00:00
|
|
|
in lib.optionalString cudaSupport ''
|
|
|
|
substituteInPlace Makefile \
|
2024-10-23 06:41:50 +00:00
|
|
|
--replace-fail '${cudaOldStr}' '${cudaNewStr}'
|
2024-01-25 14:12:00 +00:00
|
|
|
'';
|
2023-07-15 17:15:38 +00:00
|
|
|
|
2024-09-26 11:04:55 +00:00
|
|
|
env = lib.optionalAttrs stdenv.hostPlatform.isDarwin {
|
2023-07-15 17:15:38 +00:00
|
|
|
WHISPER_COREML = "1";
|
|
|
|
WHISPER_COREML_ALLOW_FALLBACK = "1";
|
2024-06-24 18:47:55 +00:00
|
|
|
WHISPER_METAL_EMBED_LIBRARY = "1";
|
2024-01-25 14:12:00 +00:00
|
|
|
} // lib.optionalAttrs cudaSupport {
|
2024-10-23 06:41:50 +00:00
|
|
|
GGML_CUDA = "1";
|
2023-07-15 17:15:38 +00:00
|
|
|
};
|
2023-01-11 07:51:40 +00:00
|
|
|
|
|
|
|
installPhase = ''
|
|
|
|
runHook preInstall
|
|
|
|
|
|
|
|
mkdir -p $out/bin
|
2024-10-23 06:41:50 +00:00
|
|
|
|
2023-01-11 07:51:40 +00:00
|
|
|
cp ./main $out/bin/whisper-cpp
|
2024-10-23 06:41:50 +00:00
|
|
|
|
|
|
|
for file in *; do
|
|
|
|
if [[ -x "$file" && -f "$file" && "$file" != "main" ]]; then
|
|
|
|
cp "$file" "$out/bin/whisper-cpp-$file"
|
|
|
|
fi
|
|
|
|
done
|
2023-01-11 07:51:40 +00:00
|
|
|
|
|
|
|
cp models/download-ggml-model.sh $out/bin/whisper-cpp-download-ggml-model
|
|
|
|
|
|
|
|
wrapProgram $out/bin/whisper-cpp-download-ggml-model \
|
|
|
|
--prefix PATH : ${lib.makeBinPath [wget]}
|
|
|
|
|
|
|
|
runHook postInstall
|
|
|
|
'';
|
|
|
|
|
|
|
|
meta = with lib; {
|
|
|
|
description = "Port of OpenAI's Whisper model in C/C++";
|
|
|
|
longDescription = ''
|
|
|
|
To download the models as described in the project's readme, you may
|
|
|
|
use the `whisper-cpp-download-ggml-model` binary from this package.
|
|
|
|
'';
|
|
|
|
homepage = "https://github.com/ggerganov/whisper.cpp";
|
|
|
|
license = licenses.mit;
|
2023-03-04 12:14:45 +00:00
|
|
|
platforms = platforms.all;
|
2023-05-24 13:37:59 +00:00
|
|
|
maintainers = with maintainers; [ dit7ya hughobrien ];
|
2023-01-11 07:51:40 +00:00
|
|
|
};
|
2024-01-25 14:12:00 +00:00
|
|
|
})
|