2023-03-17 23:03:48 +01:00
|
|
|
{
|
|
|
|
inputs = {
|
|
|
|
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
|
|
|
|
flake-utils.url = "github:numtide/flake-utils";
|
|
|
|
};
|
|
|
|
outputs = { self, nixpkgs, flake-utils }:
|
|
|
|
flake-utils.lib.eachDefaultSystem (system:
|
|
|
|
let
|
2023-06-07 06:15:31 +02:00
|
|
|
inherit (pkgs.stdenv) isAarch64 isDarwin;
|
|
|
|
inherit (pkgs.lib) optionals;
|
|
|
|
isM1 = isAarch64 && isDarwin;
|
2023-06-24 13:07:08 +02:00
|
|
|
osSpecific = if isM1 then
|
|
|
|
with pkgs.darwin.apple_sdk_11_0.frameworks; [
|
|
|
|
Accelerate
|
|
|
|
MetalKit
|
|
|
|
MetalPerformanceShaders
|
|
|
|
MetalPerformanceShadersGraph
|
|
|
|
]
|
|
|
|
else if isDarwin then
|
|
|
|
with pkgs.darwin.apple_sdk.frameworks; [
|
|
|
|
Accelerate
|
|
|
|
CoreGraphics
|
|
|
|
CoreVideo
|
|
|
|
]
|
|
|
|
else
|
|
|
|
[ ];
|
|
|
|
pkgs = import nixpkgs { inherit system; };
|
|
|
|
llama-python =
|
|
|
|
pkgs.python310.withPackages (ps: with ps; [ numpy sentencepiece ]);
|
|
|
|
in {
|
2023-03-17 23:03:48 +01:00
|
|
|
packages.default = pkgs.stdenv.mkDerivation {
|
|
|
|
name = "llama.cpp";
|
|
|
|
src = ./.;
|
2023-06-24 13:07:08 +02:00
|
|
|
postPatch = if isM1 then ''
|
|
|
|
substituteInPlace ./ggml-metal.m \
|
|
|
|
--replace '[bundle pathForResource:@"ggml-metal" ofType:@"metal"];' "@\"$out/bin/ggml-metal.metal\";"
|
|
|
|
'' else
|
|
|
|
"";
|
2023-03-17 23:03:48 +01:00
|
|
|
nativeBuildInputs = with pkgs; [ cmake ];
|
2023-06-07 06:15:31 +02:00
|
|
|
buildInputs = osSpecific;
|
|
|
|
cmakeFlags = [ "-DLLAMA_BUILD_SERVER=ON" ] ++ (optionals isM1 [
|
2023-03-17 23:03:48 +01:00
|
|
|
"-DCMAKE_C_FLAGS=-D__ARM_FEATURE_DOTPROD=1"
|
2023-06-07 06:15:31 +02:00
|
|
|
"-DLLAMA_METAL=ON"
|
|
|
|
]);
|
2023-03-17 23:03:48 +01:00
|
|
|
installPhase = ''
|
2023-07-14 21:13:38 +02:00
|
|
|
runHook preInstall
|
|
|
|
|
2023-03-17 23:03:48 +01:00
|
|
|
mkdir -p $out/bin
|
2023-04-13 15:49:05 +02:00
|
|
|
mv bin/* $out/bin/
|
|
|
|
mv $out/bin/main $out/bin/llama
|
2023-06-07 06:15:31 +02:00
|
|
|
mv $out/bin/server $out/bin/llama-server
|
2023-04-08 12:04:23 +02:00
|
|
|
|
2023-04-25 23:19:57 +02:00
|
|
|
echo "#!${llama-python}/bin/python" > $out/bin/convert.py
|
|
|
|
cat ${./convert.py} >> $out/bin/convert.py
|
|
|
|
chmod +x $out/bin/convert.py
|
2023-07-14 21:13:38 +02:00
|
|
|
|
|
|
|
runHook postInstall
|
2023-03-17 23:03:48 +01:00
|
|
|
'';
|
2023-03-20 22:44:30 +01:00
|
|
|
meta.mainProgram = "llama";
|
2023-03-17 23:03:48 +01:00
|
|
|
};
|
2023-06-17 14:13:05 +02:00
|
|
|
apps.llama-server = {
|
|
|
|
type = "app";
|
|
|
|
program = "${self.packages.${system}.default}/bin/llama-server";
|
|
|
|
};
|
|
|
|
apps.llama-embedding = {
|
|
|
|
type = "app";
|
|
|
|
program = "${self.packages.${system}.default}/bin/embedding";
|
|
|
|
};
|
|
|
|
apps.llama = {
|
|
|
|
type = "app";
|
|
|
|
program = "${self.packages.${system}.default}/bin/llama";
|
|
|
|
};
|
|
|
|
apps.default = self.apps.${system}.llama;
|
2023-03-17 23:03:48 +01:00
|
|
|
devShells.default = pkgs.mkShell {
|
2023-06-24 13:07:08 +02:00
|
|
|
packages = with pkgs; [ cmake llama-python ] ++ osSpecific;
|
2023-03-17 23:03:48 +01:00
|
|
|
};
|
2023-06-24 13:07:08 +02:00
|
|
|
});
|
2023-03-17 23:03:48 +01:00
|
|
|
}
|