2024-06-05 15:53:02 +00:00
|
|
|
{
|
|
|
|
lib,
|
|
|
|
fetchFromGitHub,
|
|
|
|
stdenv,
|
|
|
|
makeWrapper,
|
|
|
|
gitUpdater,
|
2024-07-27 06:49:29 +00:00
|
|
|
python3Packages,
|
|
|
|
python311Packages ? null, # Ignored. Kept for compatibility with the release
|
2024-06-05 15:53:02 +00:00
|
|
|
tk,
|
2024-07-27 06:49:29 +00:00
|
|
|
addDriverRunpath,
|
2024-06-05 15:53:02 +00:00
|
|
|
|
|
|
|
darwin,
|
|
|
|
|
|
|
|
koboldLiteSupport ? true,
|
|
|
|
|
|
|
|
config,
|
|
|
|
cudaPackages ? { },
|
|
|
|
|
|
|
|
openblasSupport ? !stdenv.isDarwin,
|
|
|
|
openblas,
|
|
|
|
|
|
|
|
cublasSupport ? config.cudaSupport,
|
2024-07-27 06:49:29 +00:00
|
|
|
# You can find a full list here: https://arnon.dk/matching-sm-architectures-arch-and-gencode-for-various-nvidia-cards/
|
|
|
|
# For example if you're on an GTX 1080 that means you're using "Pascal" and you need to pass "sm_60"
|
|
|
|
cudaArches ? cudaPackages.cudaFlags.arches or [ ],
|
2024-06-05 15:53:02 +00:00
|
|
|
|
|
|
|
clblastSupport ? stdenv.isLinux,
|
|
|
|
clblast,
|
|
|
|
ocl-icd,
|
|
|
|
|
|
|
|
vulkanSupport ? true,
|
|
|
|
vulkan-loader,
|
|
|
|
|
|
|
|
metalSupport ? stdenv.isDarwin && stdenv.isAarch64,
|
|
|
|
march ? "",
|
|
|
|
mtune ? "",
|
|
|
|
}:
|
|
|
|
|
|
|
|
let
|
|
|
|
makeBool = option: bool: (if bool then "${option}=1" else "");
|
|
|
|
|
2024-07-27 06:49:29 +00:00
|
|
|
libraryPathWrapperArgs = lib.optionalString config.cudaSupport ''
|
|
|
|
--prefix LD_LIBRARY_PATH: "${lib.makeLibraryPath [ addDriverRunpath.driverLink ]}"
|
|
|
|
'';
|
|
|
|
|
|
|
|
darwinFrameworks =
|
|
|
|
if (stdenv.isDarwin && stdenv.isx86_64) then
|
|
|
|
darwin.apple_sdk.frameworks
|
|
|
|
else
|
|
|
|
darwin.apple_sdk_11_0.frameworks;
|
|
|
|
|
2024-06-05 15:53:02 +00:00
|
|
|
effectiveStdenv = if cublasSupport then cudaPackages.backendStdenv else stdenv;
|
|
|
|
in
|
|
|
|
effectiveStdenv.mkDerivation (finalAttrs: {
|
|
|
|
pname = "koboldcpp";
|
2024-07-27 06:49:29 +00:00
|
|
|
version = "1.70.1";
|
2024-06-05 15:53:02 +00:00
|
|
|
|
|
|
|
src = fetchFromGitHub {
|
|
|
|
owner = "LostRuins";
|
|
|
|
repo = "koboldcpp";
|
|
|
|
rev = "refs/tags/v${finalAttrs.version}";
|
2024-07-27 06:49:29 +00:00
|
|
|
sha256 = "sha256-wtSkmjx5mzESMvIflqH+QEavH5oeBgKBz8/JjU+CASo=";
|
2024-06-05 15:53:02 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
enableParallelBuilding = true;
|
|
|
|
|
|
|
|
nativeBuildInputs = [
|
|
|
|
makeWrapper
|
2024-07-27 06:49:29 +00:00
|
|
|
python3Packages.wrapPython
|
2024-06-05 15:53:02 +00:00
|
|
|
];
|
|
|
|
|
2024-07-27 06:49:29 +00:00
|
|
|
pythonInputs = builtins.attrValues { inherit (python3Packages) tkinter customtkinter packaging; };
|
2024-06-05 15:53:02 +00:00
|
|
|
|
|
|
|
buildInputs =
|
|
|
|
[ tk ]
|
|
|
|
++ finalAttrs.pythonInputs
|
|
|
|
++ lib.optionals effectiveStdenv.isDarwin [
|
2024-07-27 06:49:29 +00:00
|
|
|
darwinFrameworks.Accelerate
|
|
|
|
darwinFrameworks.CoreVideo
|
|
|
|
darwinFrameworks.CoreGraphics
|
|
|
|
darwinFrameworks.CoreServices
|
2024-06-05 15:53:02 +00:00
|
|
|
]
|
|
|
|
++ lib.optionals metalSupport [
|
2024-07-27 06:49:29 +00:00
|
|
|
darwinFrameworks.MetalKit
|
|
|
|
darwinFrameworks.Foundation
|
|
|
|
darwinFrameworks.MetalPerformanceShaders
|
2024-06-05 15:53:02 +00:00
|
|
|
]
|
|
|
|
++ lib.optionals openblasSupport [ openblas ]
|
|
|
|
++ lib.optionals cublasSupport [
|
|
|
|
cudaPackages.libcublas
|
|
|
|
cudaPackages.cuda_nvcc
|
|
|
|
cudaPackages.cuda_cudart
|
|
|
|
cudaPackages.cuda_cccl
|
|
|
|
]
|
|
|
|
++ lib.optionals clblastSupport [
|
|
|
|
clblast
|
|
|
|
ocl-icd
|
|
|
|
]
|
|
|
|
++ lib.optionals vulkanSupport [ vulkan-loader ];
|
|
|
|
|
|
|
|
pythonPath = finalAttrs.pythonInputs;
|
|
|
|
|
|
|
|
darwinLdFlags = lib.optionals stdenv.isDarwin [
|
2024-07-27 06:49:29 +00:00
|
|
|
"-F${darwinFrameworks.CoreServices}/Library/Frameworks"
|
|
|
|
"-F${darwinFrameworks.Accelerate}/Library/Frameworks"
|
2024-06-05 15:53:02 +00:00
|
|
|
"-framework CoreServices"
|
|
|
|
"-framework Accelerate"
|
|
|
|
];
|
|
|
|
metalLdFlags = lib.optionals metalSupport [
|
2024-07-27 06:49:29 +00:00
|
|
|
"-F${darwinFrameworks.Foundation}/Library/Frameworks"
|
|
|
|
"-F${darwinFrameworks.Metal}/Library/Frameworks"
|
2024-06-05 15:53:02 +00:00
|
|
|
"-framework Foundation"
|
|
|
|
"-framework Metal"
|
|
|
|
];
|
|
|
|
|
|
|
|
env.NIX_LDFLAGS = lib.concatStringsSep " " (finalAttrs.darwinLdFlags ++ finalAttrs.metalLdFlags);
|
|
|
|
|
|
|
|
env.NIX_CFLAGS_COMPILE =
|
2024-07-27 06:49:29 +00:00
|
|
|
lib.optionalString (march != "") (
|
|
|
|
lib.warn "koboldcpp: the march argument is only kept for compatibility; use overrideAttrs intead" "-march=${march}"
|
|
|
|
)
|
|
|
|
+ lib.optionalString (mtune != "") (
|
|
|
|
lib.warn "koboldcpp: the mtune argument is only kept for compatibility; use overrideAttrs intead" "-mtune=${mtune}"
|
|
|
|
);
|
2024-06-05 15:53:02 +00:00
|
|
|
|
|
|
|
makeFlags = [
|
|
|
|
(makeBool "LLAMA_OPENBLAS" openblasSupport)
|
|
|
|
(makeBool "LLAMA_CUBLAS" cublasSupport)
|
|
|
|
(makeBool "LLAMA_CLBLAST" clblastSupport)
|
|
|
|
(makeBool "LLAMA_VULKAN" vulkanSupport)
|
|
|
|
(makeBool "LLAMA_METAL" metalSupport)
|
2024-07-27 06:49:29 +00:00
|
|
|
(lib.optionals cublasSupport "CUDA_DOCKER_ARCH=sm_${builtins.head cudaArches}")
|
2024-06-05 15:53:02 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
installPhase = ''
|
|
|
|
runHook preInstall
|
|
|
|
|
|
|
|
mkdir -p "$out/bin"
|
|
|
|
|
|
|
|
install -Dm755 koboldcpp.py "$out/bin/koboldcpp.unwrapped"
|
|
|
|
cp *.so "$out/bin"
|
|
|
|
cp *.embd "$out/bin"
|
|
|
|
|
|
|
|
${lib.optionalString (!koboldLiteSupport) ''
|
|
|
|
rm "$out/bin/kcpp_docs.embd"
|
|
|
|
rm "$out/bin/klite.embd"
|
|
|
|
''}
|
|
|
|
|
|
|
|
runHook postInstall
|
|
|
|
'';
|
|
|
|
|
2024-07-27 06:49:29 +00:00
|
|
|
# Remove an unused argument, mainly intended for Darwin to reduce warnings
|
|
|
|
postPatch = ''
|
|
|
|
substituteInPlace Makefile \
|
|
|
|
--replace-warn " -s " " "
|
|
|
|
'';
|
|
|
|
|
2024-06-05 15:53:02 +00:00
|
|
|
postFixup = ''
|
|
|
|
wrapPythonProgramsIn "$out/bin" "$pythonPath"
|
|
|
|
makeWrapper "$out/bin/koboldcpp.unwrapped" "$out/bin/koboldcpp" \
|
2024-07-27 06:49:29 +00:00
|
|
|
--prefix PATH ${lib.makeBinPath [ tk ]} ${libraryPathWrapperArgs}
|
2024-06-05 15:53:02 +00:00
|
|
|
'';
|
|
|
|
|
|
|
|
passthru.updateScript = gitUpdater { rev-prefix = "v"; };
|
|
|
|
|
|
|
|
meta = {
|
2024-06-20 14:57:18 +00:00
|
|
|
description = "Way to run various GGML and GGUF models";
|
2024-06-05 15:53:02 +00:00
|
|
|
license = lib.licenses.agpl3Only;
|
|
|
|
maintainers = with lib.maintainers; [
|
|
|
|
maxstrid
|
|
|
|
donteatoreo
|
|
|
|
];
|
|
|
|
mainProgram = "koboldcpp";
|
|
|
|
platforms = lib.platforms.unix;
|
|
|
|
};
|
|
|
|
})
|