Merge pull request #323249 from abysssol/ollama-driver-runpath

ollama: remove dependency on`linuxPackages.nvidia_x11`, use `autoAddDriverRunpath` instead
This commit is contained in:
Someone 2024-07-01 10:41:42 +00:00 committed by GitHub
commit 9c1849ebd0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 12 additions and 14 deletions

View File

@ -5,9 +5,6 @@ let
cfg = config.services.ollama;
ollamaPackage = cfg.package.override {
inherit (cfg) acceleration;
linuxPackages = config.boot.kernelPackages // {
nvidia_x11 = config.hardware.nvidia.package;
};
};
in
{

View File

@ -7,6 +7,7 @@
, overrideCC
, makeWrapper
, stdenv
, addDriverRunpath
, cmake
, gcc12
@ -14,8 +15,8 @@
, libdrm
, rocmPackages
, cudaPackages
, linuxPackages
, darwin
, autoAddDriverRunpath
, nixosTests
, testers
@ -118,16 +119,16 @@ let
appleFrameworks.MetalPerformanceShaders
];
runtimeLibs = lib.optionals enableRocm [
rocmPath
] ++ lib.optionals enableCuda [
linuxPackages.nvidia_x11
];
wrapperOptions = builtins.concatStringsSep " " ([
"--suffix LD_LIBRARY_PATH : '/run/opengl-driver/lib:${lib.makeLibraryPath runtimeLibs}'"
wrapperOptions = [
# ollama embeds llama-cpp binaries which actually run the ai models
# these llama-cpp binaries are unaffected by the ollama binary's DT_RUNPATH
# LD_LIBRARY_PATH is temporarily required to use the gpu
# until these llama-cpp binaries can have their runpath patched
"--suffix LD_LIBRARY_PATH : '${addDriverRunpath.driverLink}/lib'"
] ++ lib.optionals enableRocm [
"--set-default HIP_PATH '${rocmPath}'"
]);
];
wrapperArgs = builtins.concatStringsSep " " wrapperOptions;
goBuild =
@ -153,6 +154,7 @@ goBuild ((lib.optionalAttrs enableRocm {
rocmPackages.llvm.bintools
] ++ lib.optionals (enableRocm || enableCuda) [
makeWrapper
autoAddDriverRunpath
] ++ lib.optionals stdenv.isDarwin
metalFrameworks;
@ -188,8 +190,7 @@ goBuild ((lib.optionalAttrs enableRocm {
mv "$out/bin/app" "$out/bin/.ollama-app"
'' + lib.optionalString (enableRocm || enableCuda) ''
# expose runtime libraries necessary to use the gpu
mv "$out/bin/ollama" "$out/bin/.ollama-unwrapped"
makeWrapper "$out/bin/.ollama-unwrapped" "$out/bin/ollama" ${wrapperOptions}
wrapProgram "$out/bin/ollama" ${wrapperArgs}
'';
ldflags = [