flake.nix 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. {
  2. inputs = {
  3. nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
  4. flake-utils.url = "github:numtide/flake-utils";
  5. };
  6. outputs = { self, nixpkgs, flake-utils }:
  7. flake-utils.lib.eachDefaultSystem (system:
  8. let
  9. pkgs = import nixpkgs {
  10. inherit system;
  11. };
  12. llama-python = pkgs.python310.withPackages (ps: with ps; [
  13. numpy
  14. sentencepiece
  15. ]);
  16. in
  17. {
  18. packages.default = pkgs.stdenv.mkDerivation {
  19. name = "llama.cpp";
  20. src = ./.;
  21. 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") [
  26. "-DCMAKE_C_FLAGS=-D__ARM_FEATURE_DOTPROD=1"
  27. ];
  28. installPhase = ''
  29. mkdir -p $out/bin
  30. mv bin/* $out/bin/
  31. mv $out/bin/main $out/bin/llama
  32. echo "#!${llama-python}/bin/python" > $out/bin/convert.py
  33. cat ${./convert.py} >> $out/bin/convert.py
  34. chmod +x $out/bin/convert.py
  35. '';
  36. meta.mainProgram = "llama";
  37. };
  38. devShells.default = pkgs.mkShell {
  39. packages = with pkgs; [
  40. cmake
  41. llama-python
  42. ] ++ lib.optionals stdenv.isDarwin [
  43. darwin.apple_sdk.frameworks.Accelerate
  44. ];
  45. };
  46. }
  47. );
  48. }