nixpkgs/pkgs/by-name/ta/tabby/package.nix

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

165 lines
4.8 KiB
Nix
Raw Normal View History

{ config
, lib
, rustPlatform
2024-02-27 05:49:41 +00:00
, fetchFromGitHub
, stdenv
2024-02-27 05:49:41 +00:00
, git
, openssl
, pkg-config
, protobuf
, llama-cpp
2024-03-30 18:27:41 +00:00
, autoAddDriverRunpath
, cudaSupport ? config.cudaSupport
, cudaPackages ? { }
, rocmSupport ? config.rocmSupport
, darwin
, metalSupport ? stdenv.isDarwin && stdenv.isAarch64
# one of [ null "cpu" "rocm" "cuda" "metal" ];
, acceleration ? null
2024-02-27 05:49:41 +00:00
}:
let
inherit (lib) optional optionals flatten;
# References:
# https://github.com/NixOS/nixpkgs/blob/master/pkgs/by-name/ll/llama-cpp/package.nix
# https://github.com/NixOS/nixpkgs/blob/master/pkgs/tools/misc/ollama/default.nix
2024-02-27 05:49:41 +00:00
pname = "tabby";
version = "0.8.3";
availableAccelerations = flatten [
(optional cudaSupport "cuda")
(optional rocmSupport "rocm")
(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
);
# 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)
# !! 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" ];
# 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.
enableRocm = validAccel && (featureDevice == "rocm") && (warnIfNotLinux "rocm");
enableCuda = validAccel && (featureDevice == "cuda") && (warnIfNotLinux "cuda");
enableMetal = validAccel && (featureDevice == "metal") && (warnIfNotDarwinAarch64 "metal");
# We have to use override here because tabby doesn't actually tell llama-cpp
# to use a specific device type as it is relying on llama-cpp only being
# built to use one type of device.
#
# See: https://github.com/TabbyML/tabby/blob/v0.8.3/crates/llama-cpp-bindings/include/engine.h#L20
#
llamaccpPackage = llama-cpp.override {
rocmSupport = enableRocm;
cudaSupport = enableCuda;
metalSupport = enableMetal;
};
# 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 ]);
cudaBuildInputs = [ llamaccpPackage ];
rocmBuildInputs = [ llamaccpPackage ];
in
rustPlatform.buildRustPackage {
inherit pname version;
inherit featureDevice;
2024-02-27 05:49:41 +00:00
src = fetchFromGitHub {
owner = "TabbyML";
repo = "tabby";
rev = "v${version}";
hash = "sha256-+5Q5XKfh7+g24y2hBqJC/jNEoRytDdcRdn838xc7c8w=";
2024-02-27 05:49:41 +00:00
fetchSubmodules = true;
};
cargoLock = {
lockFile = ./Cargo.lock;
outputHashes = {
"tree-sitter-c-0.20.6" = "sha256-Etl4s29YSOxiqPo4Z49N6zIYqNpIsdk/Qd0jR8jdvW4=";
"tree-sitter-cpp-0.20.3" = "sha256-UrQ48CoUMSHmlHzOMu22c9N4hxJtHL2ZYRabYjf5byA=";
};
};
2024-02-27 05:49:41 +00:00
2024-02-27 06:12:46 +00:00
# https://github.com/TabbyML/tabby/blob/v0.7.0/.github/workflows/release.yml#L39
2024-02-27 05:49:41 +00:00
cargoBuildFlags = [
"--release"
"--package" "tabby"
] ++ optionals enableRocm [
"--features" "rocm"
] ++ optionals enableCuda [
2024-02-27 05:49:41 +00:00
"--features" "cuda"
];
OPENSSL_NO_VENDOR = 1;
nativeBuildInputs = [
pkg-config
protobuf
git
] ++ optionals enableCuda [
2024-03-30 18:27:41 +00:00
autoAddDriverRunpath
2024-02-27 05:49:41 +00:00
];
buildInputs = [ openssl ]
++ optionals stdenv.isDarwin darwinBuildInputs
++ optionals enableCuda cudaBuildInputs
++ optionals enableRocm rocmBuildInputs
2024-02-27 05:49:41 +00:00
;
llvmPackages_{12,13,14,15,16,17,git}.{libcxx,libcxxabi}: merge libcxxabi into libcxx (#292043) - merge libcxxabi into libcxx for LLVM 12, 13, 14, 15, 16, 17, and git. - remove the link time workaround `-lc++ -lc++abi` from 58 packages as it is no longer required. - fixes https://github.com/NixOS/nixpkgs/issues/166205 - provides alternative fixes for. https://github.com/NixOS/nixpkgs/issues/269548 https://github.com/NixOS/nix/issues/9640 - pkgsCross.x86_64-freebsd builds work again This change can be represented in 3 stages 1. merge libcxxabi into libcxx -- files: pkgs/development/compilers/llvm/[12, git]/{libcxx, libcxxabi} 2. update stdenv to account for merge -- files: stdenv.{adapters, cc.wrapper, darwin} 3. remove all references to libcxxabi outside of llvm (about 58 packages modified) ### merging libcxxabi into libcxx - take the union of the libcxxabi and libcxx cmake flags - eliminate the libcxx-headers-only package - it was only needed to break libcxx <-> libcxxabi circular dependency - libcxx.cxxabi is removed. external cxxabi (freebsd) will symlink headers / libs into libcxx. - darwin will re-export the libcxxabi symbols into libcxx so linking `-lc++` is sufficient. - linux/freebsd `libc++.so` is a linker script `LINK(libc++.so.1, -lc++abi)` making `-lc++` sufficient. - libcxx/default.nix [12, 17] are identical except for patches and `LIBCXX_ADDITIONAL_LIBRARIES` (only used in 16+) - git/libcxx/defaul.nix does not link with -nostdlib when useLLVM is true so flag is removed. this is not much different than before as libcxxabi used -nostdlib where libcxx did not, so libc was linked in anyway. ### stdenv changes - darwin bootstrap, remove references to libcxxabi and cxxabi - cc-wrapper: remove c++ link workaround when libcxx.cxxabi doesn't exist (still exists for LLVM pre 12) - adapter: update overrideLibcxx to account for a pkgs.stdenv that only has libcxx ### 58 package updates - remove `NIX_LDFLAGS = "-l${stdenv.cc.libcxx.cxxabi.libName}` as no longer needed - swift, nodejs_v8 remove libcxxabi references in the clang override https://github.com/NixOS/nixpkgs/pull/292043
2024-03-11 10:53:37 +00:00
env.LLAMA_CPP_LIB = "${lib.getLib llamaccpPackage}/lib";
patches = [ ./0001-nix-build-use-nix-native-llama-cpp-package.patch ];
2024-02-27 05:49:41 +00:00
# Fails with:
# file cannot create directory: /var/empty/local/lib64/cmake/Llama
doCheck = false;
meta = with lib; {
homepage = "https://github.com/TabbyML/tabby";
changelog = "https://github.com/TabbyML/tabby/releases/tag/v${version}";
description = "Self-hosted AI coding assistant";
mainProgram = "tabby";
license = licenses.asl20;
maintainers = [ maintainers.ghthor ];
broken = stdenv.isDarwin && !stdenv.isAarch64;
2024-02-27 05:49:41 +00:00
};
}