File tree Expand file tree Collapse file tree 2 files changed +42
-14
lines changed Expand file tree Collapse file tree 2 files changed +42
-14
lines changed Original file line number Diff line number Diff line change 6
6
outputs = { self , nixpkgs , flake-utils } :
7
7
flake-utils . lib . eachDefaultSystem ( system :
8
8
let
9
+ inherit ( pkgs . stdenv ) isAarch64 isDarwin ;
10
+ inherit ( pkgs . lib ) optionals ;
11
+ isM1 = isAarch64 && isDarwin ;
12
+ osSpecific =
13
+ if isM1 then with pkgs . darwin . apple_sdk_11_0 . frameworks ; [ Accelerate MetalKit MetalPerformanceShaders MetalPerformanceShadersGraph ]
14
+ else if isDarwin then with pkgs . darwin . apple_sdk . frameworks ; [ Accelerate CoreGraphics CoreVideo ]
15
+ else [ ] ;
9
16
pkgs = import nixpkgs {
10
17
inherit system ;
11
18
} ;
18
25
packages . default = pkgs . stdenv . mkDerivation {
19
26
name = "llama.cpp" ;
20
27
src = ./. ;
28
+ postPatch =
29
+ if isM1 then ''
30
+ substituteInPlace ./ggml-metal.m \
31
+ --replace '[[NSBundle mainBundle] pathForResource:@"ggml-metal" ofType:@"metal"];' "@\"$out/ggml-metal.metal\";"
32
+ '' else "" ;
21
33
nativeBuildInputs = with pkgs ; [ cmake ] ;
22
- buildInputs = with pkgs ; lib . optionals stdenv . isDarwin [
23
- darwin . apple_sdk . frameworks . Accelerate
24
- ] ;
25
- cmakeFlags = with pkgs ; lib . optionals ( system == "aarch64-darwin" ) [
34
+ buildInputs = osSpecific ;
35
+ cmakeFlags = [ "-DLLAMA_BUILD_SERVER=ON" ] ++ ( optionals isM1 [
26
36
"-DCMAKE_C_FLAGS=-D__ARM_FEATURE_DOTPROD=1"
27
- ] ;
37
+ "-DLLAMA_METAL=ON"
38
+ ] ) ;
28
39
installPhase = ''
29
40
mkdir -p $out/bin
30
41
mv bin/* $out/bin/
31
42
mv $out/bin/main $out/bin/llama
43
+ mv $out/bin/server $out/bin/llama-server
32
44
33
45
echo "#!${ llama-python } /bin/python" > $out/bin/convert.py
34
46
cat ${ ./convert.py } >> $out/bin/convert.py
40
52
packages = with pkgs ; [
41
53
cmake
42
54
llama-python
43
- ] ++ lib . optionals stdenv . isDarwin [
44
- darwin . apple_sdk . frameworks . Accelerate
45
- ] ;
55
+ ] ++ osSpecific ;
46
56
} ;
47
57
}
48
58
) ;
You can’t perform that action at this time.
0 commit comments