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