Skip to content

Commit db27914

Browse files
authored
ollama: 0.5.7 -> 0.5.11 (#383387)
2 parents ae3835c + 2186263 commit db27914

File tree

1 file changed

+40
-18
lines changed

1 file changed

+40
-18
lines changed

pkgs/by-name/ol/ollama/package.nix

Lines changed: 40 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,22 @@
22
lib,
33
buildGoModule,
44
fetchFromGitHub,
5+
fetchpatch,
56
buildEnv,
67
linkFarm,
7-
overrideCC,
88
makeWrapper,
99
stdenv,
1010
addDriverRunpath,
1111
nix-update-script,
1212

1313
cmake,
14-
gcc12,
1514
gitMinimal,
1615
clblast,
1716
libdrm,
1817
rocmPackages,
18+
rocmGpuTargets ? rocmPackages.clr.gpuTargets or [ ],
1919
cudaPackages,
20+
cudaArches ? cudaPackages.cudaFlags.realArches or [ ],
2021
darwin,
2122
autoAddDriverRunpath,
2223
versionCheckHook,
@@ -43,17 +44,17 @@ assert builtins.elem acceleration [
4344
let
4445
pname = "ollama";
4546
# don't forget to invalidate all hashes each update
46-
version = "0.5.7";
47+
version = "0.5.11";
4748

4849
src = fetchFromGitHub {
4950
owner = "ollama";
5051
repo = "ollama";
5152
tag = "v${version}";
52-
hash = "sha256-DW7gHNyW1ML8kqgMFsqTxS/30bjNlWmYmeov2/uZn00=";
53+
hash = "sha256-Yc/FwIoPvzYSxlrhjkc6xFL5iCunDYmZkG16MiWVZck=";
5354
fetchSubmodules = true;
5455
};
5556

56-
vendorHash = "sha256-1uk3Oi0n4Q39DVZe3PnZqqqmlwwoHmEolcRrib0uu4I=";
57+
vendorHash = "sha256-wtmtuwuu+rcfXsyte1C4YLQA4pnjqqxFmH1H18Fw75g=";
5758

5859
validateFallback = lib.warnIf (config.rocmSupport && config.cudaSupport) (lib.concatStrings [
5960
"both `nixpkgs.config.rocmSupport` and `nixpkgs.config.cudaSupport` are enabled, "
@@ -172,6 +173,15 @@ goBuild {
172173
++ lib.optionals enableCuda cudaLibs
173174
++ lib.optionals stdenv.hostPlatform.isDarwin metalFrameworks;
174175

176+
patches = [
177+
# don't try to build x86_64 architectures on linux-aarch64
178+
# NOTE: should be removed after 0.5.11
179+
(fetchpatch {
180+
url = "https://github.com/ollama/ollama/commit/08a299e1d0636056b09d669f9aa347139cde6ec0.patch";
181+
hash = "sha256-PC9jQklPAN/ZdHlQEQ6/RweGGBiUPDehHyaboX0tRZk=";
182+
})
183+
];
184+
175185
# replace inaccurate version number with actual release version
176186
postPatch = ''
177187
substituteInPlace version/version.go \
@@ -187,24 +197,35 @@ goBuild {
187197

188198
preBuild =
189199
let
190-
dist_cmd =
191-
if cudaRequested then
192-
"dist_cuda_v${cudaMajorVersion}"
193-
else if rocmRequested then
194-
"dist_rocm"
195-
else
196-
"dist";
200+
removeSMPrefix =
201+
str:
202+
let
203+
matched = builtins.match "sm_(.*)" str;
204+
in
205+
if matched == null then str else builtins.head matched;
206+
207+
cudaArchitectures = builtins.concatStringsSep ";" (builtins.map removeSMPrefix cudaArches);
208+
rocmTargets = builtins.concatStringsSep ";" rocmGpuTargets;
209+
210+
cmakeFlagsCudaArchitectures = lib.optionalString enableCuda "-DCMAKE_CUDA_ARCHITECTURES='${cudaArchitectures}'";
211+
cmakeFlagsRocmTargets = lib.optionalString enableRocm "-DAMDGPU_TARGETS='${rocmTargets}'";
212+
197213
in
198-
# build llama.cpp libraries for ollama
199214
''
200-
make ${dist_cmd} -j $NIX_BUILD_CORES
215+
cmake -B build \
216+
-DCMAKE_SKIP_BUILD_RPATH=ON \
217+
-DCMAKE_BUILD_WITH_INSTALL_RPATH=ON \
218+
${cmakeFlagsCudaArchitectures} \
219+
${cmakeFlagsRocmTargets} \
220+
221+
cmake --build build -j $NIX_BUILD_CORES
201222
'';
202223

203-
postInstall = lib.optionalString (stdenv.hostPlatform.isx86 || enableRocm || enableCuda) ''
204-
# copy libggml_*.so and runners into lib
205-
# https://github.com/ollama/ollama/blob/v0.4.4/llama/make/gpu.make#L90
224+
# ollama looks for acceleration libs in ../lib/ollama/ (now also for CPU-only with arch specific optimizations)
225+
# https://github.com/ollama/ollama/blob/v0.5.11/docs/development.md#library-detection
226+
postInstall = ''
206227
mkdir -p $out/lib
207-
cp -r dist/*/lib/* $out/lib/
228+
cp -r build/lib/ollama $out/lib/
208229
'';
209230

210231
postFixup =
@@ -261,6 +282,7 @@ goBuild {
261282
abysssol
262283
dit7ya
263284
elohmeier
285+
prusnak
264286
roydubnium
265287
];
266288
};

0 commit comments

Comments
 (0)