diff options
Diffstat (limited to 'pkgs/by-name/ta/tabby/package.nix')
-rw-r--r-- | pkgs/by-name/ta/tabby/package.nix | 220 |
1 files changed, 131 insertions, 89 deletions
diff --git a/pkgs/by-name/ta/tabby/package.nix b/pkgs/by-name/ta/tabby/package.nix index 4ebc77e741b1..725cbb669f66 100644 --- a/pkgs/by-name/ta/tabby/package.nix +++ b/pkgs/by-name/ta/tabby/package.nix @@ -1,28 +1,27 @@ -{ config -, lib -, rustPlatform -, fetchFromGitHub -, nix-update-script -, stdenv - -, git -, openssl -, pkg-config -, protobuf - -, llama-cpp - -, autoAddDriverRunpath -, cudaSupport ? config.cudaSupport -, cudaPackages ? { } - -, rocmSupport ? config.rocmSupport - -, darwin -, metalSupport ? stdenv.isDarwin && stdenv.isAarch64 - +{ + config, + lib, + rustPlatform, + fetchFromGitHub, + nix-update-script, + stdenv, + + git, + openssl, + pkg-config, + protobuf, + + llama-cpp, + + apple-sdk_15, + autoAddDriverRunpath, + versionCheckHook, + + cudaSupport ? config.cudaSupport, + rocmSupport ? config.rocmSupport, + metalSupport ? stdenv.hostPlatform.isDarwin && stdenv.hostPlatform.isAarch64, # one of [ null "cpu" "rocm" "cuda" "metal" ]; -, acceleration ? null + acceleration ? null, }: let @@ -32,8 +31,7 @@ let # https://github.com/NixOS/nixpkgs/blob/master/pkgs/tools/misc/ollama/default.nix pname = "tabby"; - version = "0.11.1"; - + version = "0.19.0"; availableAccelerations = flatten [ (optional cudaSupport "cuda") @@ -41,32 +39,49 @@ let (optional metalSupport "metal") ]; - warnIfMultipleAccelerationMethods = configured: (let - len = builtins.length configured; - result = if len == 0 then "cpu" else (builtins.head configured); - in - lib.warnIf (len > 1) '' - building tabby with multiple acceleration methods enabled is not - supported; falling back to `${result}` - '' - result - ); + warnIfMultipleAccelerationMethods = + configured: + ( + let + len = builtins.length configured; + result = if len == 0 then "cpu" else (builtins.head configured); + in + lib.warnIf (len > 1) '' + building tabby with multiple acceleration methods enabled is not + supported; falling back to `${result}` + '' result + ); # If user did not not override the acceleration attribute, then try to use one of # - nixpkgs.config.cudaSupport # - nixpkgs.config.rocmSupport - # - metal if (stdenv.isDarwin && stdenv.isAarch64) + # - metal if (stdenv.hostPlatform.isDarwin && stdenv.hostPlatform.isAarch64) # !! warn if multiple acceleration methods are enabled and default to the first one in the list - featureDevice = if (builtins.isNull acceleration) then (warnIfMultipleAccelerationMethods availableAccelerations) else acceleration; - - warnIfNotLinux = api: (lib.warnIfNot stdenv.isLinux - "building tabby with `${api}` is only supported on linux; falling back to cpu" - stdenv.isLinux); - warnIfNotDarwinAarch64 = api: (lib.warnIfNot (stdenv.isDarwin && stdenv.isAarch64) - "building tabby with `${api}` is only supported on Darwin-aarch64; falling back to cpu" - (stdenv.isDarwin && stdenv.isAarch64)); - - validAccel = lib.assertOneOf "tabby.featureDevice" featureDevice [ "cpu" "rocm" "cuda" "metal" ]; + featureDevice = + if (builtins.isNull acceleration) then + (warnIfMultipleAccelerationMethods availableAccelerations) + else + acceleration; + + warnIfNotLinux = + api: + (lib.warnIfNot stdenv.hostPlatform.isLinux + "building tabby with `${api}` is only supported on linux; falling back to cpu" + stdenv.hostPlatform.isLinux + ); + warnIfNotDarwinAarch64 = + api: + (lib.warnIfNot (stdenv.hostPlatform.isDarwin && stdenv.hostPlatform.isAarch64) + "building tabby with `${api}` is only supported on Darwin-aarch64; falling back to cpu" + (stdenv.hostPlatform.isDarwin && stdenv.hostPlatform.isAarch64) + ); + + validAccel = lib.assertOneOf "tabby.featureDevice" featureDevice [ + "cpu" + "rocm" + "cuda" + "metal" + ]; # TODO(ghthor): there is a bug here where featureDevice could be cuda, but enableCuda is false # The would result in a startup failure of the service module. @@ -87,14 +102,11 @@ let }; # TODO(ghthor): some of this can be removed - darwinBuildInputs = [ llamaccpPackage ] - ++ optionals stdenv.isDarwin (with darwin.apple_sdk.frameworks; [ - Foundation - Accelerate - CoreVideo - CoreGraphics - ] - ++ optionals enableMetal [ Metal MetalKit ]); + darwinBuildInputs = + [ llamaccpPackage ] + ++ optionals stdenv.hostPlatform.isDarwin ([ + apple-sdk_15 + ]); cudaBuildInputs = [ llamaccpPackage ]; rocmBuildInputs = [ llamaccpPackage ]; @@ -107,55 +119,85 @@ rustPlatform.buildRustPackage { src = fetchFromGitHub { owner = "TabbyML"; repo = "tabby"; - rev = "v${version}"; - hash = "sha256-OgAE526aW3mVqf6fVmBmL5/B4gH9B54QLEITQk9Kgsg="; + rev = "refs/tags/v${version}"; + hash = "sha256-RK81gQ5IUzZ4HXJbKBr5bqayH0Xip6ZVAgdMwqP+kx8="; fetchSubmodules = true; }; cargoLock = { lockFile = ./Cargo.lock; outputHashes = { - "apalis-0.5.1" = "sha256-hGvVuSy32lSTR5DJdiyf8q1sXbIeuLSGrtyq6m2QlUQ="; - "tree-sitter-c-0.20.6" = "sha256-Etl4s29YSOxiqPo4Z49N6zIYqNpIsdk/Qd0jR8jdvW4="; - "tree-sitter-cpp-0.20.3" = "sha256-UrQ48CoUMSHmlHzOMu22c9N4hxJtHL2ZYRabYjf5byA="; - "tree-sitter-solidity-0.0.3" = "sha256-b+LthCf+g19sjKeNgXZmUV0RNi94O3u0WmXfgKRpaE0="; + "ollama-rs-0.1.9" = "sha256-d6sKUxc8VQbRkVqMOeNFqDdKesq5k32AQShK67y2ssg="; + "oneshot-0.1.6" = "sha256-PmYuHuNTqToMyMHPRFDUaHUvFkVftx9ZCOBwXj+4Hc4="; + "ownedbytes-0.7.0" = "sha256-p0+ohtW0VLmfDTZw/LfwX2gYfuYuoOBcE+JsguK7Wn8="; + "sqlx-0.7.4" = "sha256-tcISzoSfOZ0jjNgGpuPPxjMxmBUPw/5FVDoALZEAHKY="; + "tree-sitter-c-0.21.3" = "sha256-ucbHLS2xyGo1uyKZv/K1HNXuMo4GpTY327cgdVS9F3c="; + "tree-sitter-cpp-0.22.1" = "sha256-3akSuQltFMF6I32HwRU08+Hcl9ojxPGk2ZuOX3gAObw="; + "tree-sitter-solidity-1.2.6" = "sha256-S00hdzMoIccPYBEvE092/RIMnG8YEnDGk6GJhXlr4ng="; }; }; # https://github.com/TabbyML/tabby/blob/v0.7.0/.github/workflows/release.yml#L39 - cargoBuildFlags = [ - "--release" - "--package" "tabby" - ] ++ optionals enableRocm [ - "--features" "rocm" - ] ++ optionals enableCuda [ - "--features" "cuda" - ]; - - OPENSSL_NO_VENDOR = 1; - - nativeBuildInputs = [ - pkg-config - protobuf - git - ] ++ optionals enableCuda [ - autoAddDriverRunpath + cargoBuildFlags = + [ + # Don't need to build llama-cpp-server (included in default build) + "--no-default-features" + "--features" + "ee" + "--package" + "tabby" + ] + ++ optionals enableRocm [ + "--features" + "rocm" + ] + ++ optionals enableCuda [ + "--features" + "cuda" + ]; + + nativeInstallCheckInputs = [ + versionCheckHook ]; - - buildInputs = [ openssl ] - ++ optionals stdenv.isDarwin darwinBuildInputs - ++ optionals enableCuda cudaBuildInputs - ++ optionals enableRocm rocmBuildInputs - ; - - env.LLAMA_CPP_LIB = "${lib.getLib llamaccpPackage}/lib"; - patches = [ ./0001-nix-build-use-nix-native-llama-cpp-package.patch ]; + versionCheckProgramArg = [ "--version" ]; + doInstallCheck = true; + + nativeBuildInputs = + [ + git + pkg-config + protobuf + ] + ++ optionals enableCuda [ + autoAddDriverRunpath + ]; + + buildInputs = + [ openssl ] + ++ optionals stdenv.hostPlatform.isDarwin darwinBuildInputs + ++ optionals enableCuda cudaBuildInputs + ++ optionals enableRocm rocmBuildInputs; + + postInstall = '' + # NOTE: Project contains a subproject for building llama-server + # But, we already have a derivation for this + ln -s ${lib.getExe' llama-cpp "llama-server"} $out/bin/llama-server + ''; + + env = { + OPENSSL_NO_VENDOR = 1; + }; # Fails with: # file cannot create directory: /var/empty/local/lib64/cmake/Llama doCheck = false; - passthru.updateScript = nix-update-script { }; + passthru.updateScript = nix-update-script { + extraArgs = [ + "--version-regex" + "^v([0-9.]+)$" + ]; + }; meta = with lib; { homepage = "https://github.com/TabbyML/tabby"; @@ -164,6 +206,6 @@ rustPlatform.buildRustPackage { mainProgram = "tabby"; license = licenses.asl20; maintainers = [ maintainers.ghthor ]; - broken = stdenv.isDarwin && !stdenv.isAarch64; + broken = stdenv.hostPlatform.isDarwin && !stdenv.hostPlatform.isAarch64; }; } |