From bf91b72c06d5fefae1987d3d5e7e49a7550a7118 Mon Sep 17 00:00:00 2001 From: abysssol Date: Fri, 28 Jun 2024 17:06:42 -0400 Subject: [PATCH 1/2] nixos/ollama: remove `linuxPackages` override `linuxPackages.nvidia_x11` is no longer used by the `ollama` package. --- nixos/modules/services/misc/ollama.nix | 3 --- 1 file changed, 3 deletions(-) diff --git a/nixos/modules/services/misc/ollama.nix b/nixos/modules/services/misc/ollama.nix index c460514783ef..a0a32f1702bf 100644 --- a/nixos/modules/services/misc/ollama.nix +++ b/nixos/modules/services/misc/ollama.nix @@ -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 { From 9f910d23b4529c1b10fddd0dc7de7da391489dfa Mon Sep 17 00:00:00 2001 From: abysssol Date: Fri, 28 Jun 2024 16:50:10 -0400 Subject: [PATCH 2/2] ollama: switch to `autoAddDriverRunpath` `linuxPackages.nvidia_x11` is a driver, and isn't intended to be directly linked like a library. `autoAddDriverRunpath` should be able to make ollama work without it. --- pkgs/by-name/ol/ollama/package.nix | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/pkgs/by-name/ol/ollama/package.nix b/pkgs/by-name/ol/ollama/package.nix index 94de36bce94d..8d27dec89402 100644 --- a/pkgs/by-name/ol/ollama/package.nix +++ b/pkgs/by-name/ol/ollama/package.nix @@ -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 = [