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; cfg = config.services.ollama;
ollamaPackage = cfg.package.override { ollamaPackage = cfg.package.override {
inherit (cfg) acceleration; inherit (cfg) acceleration;
linuxPackages = config.boot.kernelPackages // {
nvidia_x11 = config.hardware.nvidia.package;
};
}; };
in in
{ {

View File

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