···
# needed for audio-to-text
···
# apply feature parameter names according to
# https://github.com/NixOS/rfcs/pull/169
23
+
, enable_avx2 ? true
24
+
, enable_avx512 ? false
25
+
, enable_f16c ? true
···
44
-
go-llama-ggml = fetchFromGitHub {
45
-
owner = "go-skynet";
46
-
repo = "go-llama.cpp";
47
-
rev = "2b57a8ae43e4699d3dc5d1496a1ccd42922993be";
48
-
hash = "sha256-D6SEg5pPcswGyKAmF4QTJP6/Y1vjRr7m7REguag+too=";
49
-
fetchSubmodules = true;
53
+
assert (lib.count lib.id [ with_openblas with_cublas with_clblas ]) <= 1;
54
+
if with_openblas then "openblas"
55
+
else if with_cublas then "cublas"
56
+
else if with_clblas then "clblas"
60
+
lib.optionals with_cublas
61
+
[ cudaPackages.cudatoolkit cudaPackages.cuda_cudart ]
62
+
++ lib.optionals with_clblas
63
+
[ clblast ocl-icd opencl-headers ]
64
+
++ lib.optionals with_openblas
67
+
go-llama-ggml = effectiveStdenv.mkDerivation {
68
+
name = "go-llama-ggml";
69
+
src = fetchFromGitHub {
70
+
owner = "go-skynet";
71
+
repo = "go-llama.cpp";
72
+
rev = "2b57a8ae43e4699d3dc5d1496a1ccd42922993be";
73
+
hash = "sha256-D6SEg5pPcswGyKAmF4QTJP6/Y1vjRr7m7REguag+too=";
74
+
fetchSubmodules = true;
78
+
"BUILD_TYPE=${BUILD_TYPE}"
80
+
buildInputs = typedBuiltInputs;
81
+
dontUseCmakeConfigure = true;
82
+
nativeBuildInputs = [ cmake ];
85
+
tar cf - --exclude=build --exclude=CMakeFiles --exclude="*.o" . \
52
-
# possible improvement: use Nix package llama-cpp
53
-
llama_cpp = fetchFromGitHub {
54
-
owner = "ggerganov";
56
-
rev = "d01b3c4c32357567f3531d4e6ceffc5d23e87583";
57
-
hash = "sha256-7eaQV+XTCXdrJlo7y21q5j/8ecVwuTMJScRTATcF6oM=";
58
-
fetchSubmodules = true;
90
+
llama-cpp-grpc = (llama-cpp.overrideAttrs (final: prev: {
91
+
name = "llama-cpp-grpc";
92
+
src = fetchFromGitHub {
93
+
owner = "ggerganov";
95
+
rev = "d01b3c4c32357567f3531d4e6ceffc5d23e87583";
96
+
hash = "sha256-7eaQV+XTCXdrJlo7y21q5j/8ecVwuTMJScRTATcF6oM=";
97
+
fetchSubmodules = true;
99
+
postPatch = prev.postPatch + ''
101
+
cp -r --no-preserve=mode ${src}/backend/cpp/llama grpc-server
102
+
cp llava/clip.* llava/llava.* grpc-server
103
+
printf "\nadd_subdirectory(grpc-server)" >> CMakeLists.txt
105
+
cp ${src}/backend/backend.proto grpc-server
106
+
sed -i grpc-server/CMakeLists.txt \
107
+
-e '/get_filename_component/ s;[.\/]*backend/;;' \
108
+
-e '$a\install(TARGETS ''${TARGET} RUNTIME)'
111
+
cmakeFlags = prev.cmakeFlags ++ [
112
+
(lib.cmakeBool "BUILD_SHARED_LIBS" false)
113
+
(lib.cmakeBool "LLAMA_AVX" enable_avx)
114
+
(lib.cmakeBool "LLAMA_AVX2" enable_avx2)
115
+
(lib.cmakeBool "LLAMA_AVX512" enable_avx512)
116
+
(lib.cmakeBool "LLAMA_FMA" enable_fma)
117
+
(lib.cmakeBool "LLAMA_F16C" enable_f16c)
119
+
buildInputs = prev.buildInputs ++ [
120
+
protobuf # provides also abseil_cpp as propagated build input
125
+
cudaSupport = with_cublas;
126
+
rocmSupport = false;
127
+
openclSupport = with_clblas;
128
+
blasSupport = with_openblas;
61
-
llama_cpp' = runCommand "llama_cpp_src" { } ''
62
-
cp -r --no-preserve=mode,ownership ${llama_cpp} $out
63
-
sed -i $out/CMakeLists.txt \
64
-
-e 's;pkg_check_modules(DepBLAS REQUIRED openblas);pkg_check_modules(DepBLAS REQUIRED openblas64);'
67
-
gpt4all = fetchFromGitHub {
70
-
rev = "27a8b020c36b0df8f8b82a252d261cda47cf44b8";
71
-
hash = "sha256-djq1eK6ncvhkO3MNDgasDBUY/7WWcmZt/GJsHAulLdI=";
72
-
fetchSubmodules = true;
131
+
gpt4all = stdenv.mkDerivation {
133
+
src = fetchFromGitHub {
134
+
owner = "nomic-ai";
136
+
rev = "27a8b020c36b0df8f8b82a252d261cda47cf44b8";
137
+
hash = "sha256-djq1eK6ncvhkO3MNDgasDBUY/7WWcmZt/GJsHAulLdI=";
138
+
fetchSubmodules = true;
140
+
makeFlags = [ "-C gpt4all-bindings/golang" ];
141
+
buildFlags = [ "libgpt4all.a" ];
142
+
dontUseCmakeConfigure = true;
143
+
nativeBuildInputs = [ cmake ];
146
+
tar cf - --exclude=CMakeFiles . \
75
-
go-piper = fetchFromGitHub {
78
-
rev = "9d0100873a7dbb0824dfea40e8cec70a1b110759";
79
-
hash = "sha256-Yv9LQkWwGpYdOS0FvtP0vZ0tRyBAx27sdmziBR4U4n8=";
80
-
fetchSubmodules = true;
151
+
go-piper = stdenv.mkDerivation {
153
+
src = fetchFromGitHub {
156
+
rev = "9d0100873a7dbb0824dfea40e8cec70a1b110759";
157
+
hash = "sha256-Yv9LQkWwGpYdOS0FvtP0vZ0tRyBAx27sdmziBR4U4n8=";
158
+
fetchSubmodules = true;
162
+
-e '/cd piper-phonemize/ s;cmake;cmake -DONNXRUNTIME_DIR=${onnxruntime.dev};' \
163
+
-e '/CXXFLAGS *= / s;$; -DSPDLOG_FMT_EXTERNAL=1;' \
164
+
-e '/cd piper\/build / s;cmake;cmake -DSPDLOG_DIR=${spdlog.src} -DFMT_DIR=${fmt};'
166
+
buildFlags = [ "libpiper_binding.a" ];
167
+
dontUseCmakeConfigure = true;
168
+
nativeBuildInputs = [ cmake ];
169
+
buildInputs = [ sonic spdlog onnxruntime ];
171
+
cp -r --no-preserve=mode $src $out
175
+
piper-phonemize/pi/lib \
176
+
piper-phonemize/pi/include \
177
+
piper-phonemize/pi/share \
83
-
go-rwkv = fetchFromGitHub {
85
-
repo = "go-rwkv.cpp";
86
-
rev = "661e7ae26d442f5cfebd2a0881b44e8c55949ec6";
87
-
hash = "sha256-byTNZQSnt7qpBMng3ANJmpISh3GJiz+F15UqfXaz6nQ=";
88
-
fetchSubmodules = true;
182
+
go-rwkv = stdenv.mkDerivation {
184
+
src = fetchFromGitHub {
186
+
repo = "go-rwkv.cpp";
187
+
rev = "661e7ae26d442f5cfebd2a0881b44e8c55949ec6";
188
+
hash = "sha256-byTNZQSnt7qpBMng3ANJmpISh3GJiz+F15UqfXaz6nQ=";
189
+
fetchSubmodules = true;
191
+
buildFlags = [ "librwkv.a" ];
192
+
dontUseCmakeConfigure = true;
193
+
nativeBuildInputs = [ cmake ];
195
+
cp -r --no-preserve=mode $src $out
91
-
whisper = fetchFromGitHub {
92
-
owner = "ggerganov";
93
-
repo = "whisper.cpp";
94
-
rev = "a56f435fd475afd7edf02bfbf9f8c77f527198c2";
95
-
hash = "sha256-ozTnxEuftAQQr5v/kwg5EKHuKF21d9ETIyvXcvr0Qos=";
96
-
fetchSubmodules = true;
200
+
# try to merge with openai-whisper-cpp in future
201
+
whisper-cpp = effectiveStdenv.mkDerivation {
202
+
name = "whisper-cpp";
203
+
src = fetchFromGitHub {
204
+
owner = "ggerganov";
205
+
repo = "whisper.cpp";
206
+
rev = "a56f435fd475afd7edf02bfbf9f8c77f527198c2";
207
+
hash = "sha256-g8ZhVB5sxpfrFzg/0seSrv0vFG0YOP56253n6/KWHfE=";
209
+
nativeBuildInputs = [ cmake pkg-config ];
210
+
buildInputs = typedBuiltInputs;
212
+
(lib.cmakeBool "WHISPER_CUBLAS" with_cublas)
213
+
(lib.cmakeBool "WHISPER_CLBLAST" with_clblas)
214
+
(lib.cmakeBool "WHISPER_OPENBLAS" with_openblas)
215
+
(lib.cmakeBool "WHISPER_NO_AVX" (!enable_avx))
216
+
(lib.cmakeBool "WHISPER_NO_AVX2" (!enable_avx2))
217
+
(lib.cmakeBool "WHISPER_NO_FMA" (!enable_fma))
218
+
(lib.cmakeBool "WHISPER_NO_F16C" (!enable_f16c))
219
+
(lib.cmakeBool "BUILD_SHARED_LIBS" false)
222
+
install -Dt $out/bin bin/*
99
-
go-bert = fetchFromGitHub {
100
-
owner = "go-skynet";
101
-
repo = "go-bert.cpp";
102
-
rev = "6abe312cded14042f6b7c3cd8edf082713334a4d";
103
-
hash = "sha256-lh9cvXc032Eq31kysxFOkRd0zPjsCznRl0tzg9P2ygo=";
104
-
fetchSubmodules = true;
226
+
go-bert = stdenv.mkDerivation {
228
+
src = fetchFromGitHub {
229
+
owner = "go-skynet";
230
+
repo = "go-bert.cpp";
231
+
rev = "6abe312cded14042f6b7c3cd8edf082713334a4d";
232
+
hash = "sha256-lh9cvXc032Eq31kysxFOkRd0zPjsCznRl0tzg9P2ygo=";
233
+
fetchSubmodules = true;
235
+
buildFlags = [ "libgobert.a" ];
236
+
dontUseCmakeConfigure = true;
237
+
nativeBuildInputs = [ cmake ];
238
+
env.NIX_CFLAGS_COMPILE = "-Wformat";
240
+
cp -r --no-preserve=mode $src $out
go-stable-diffusion = stdenv.mkDerivation {
108
-
pname = "go_stable_diffusion";
109
-
version = "unstable";
246
+
name = "go-stable-diffusion";
repo = "go-stable-diffusion";
···
buildInputs = [ opencv ];
env.NIX_CFLAGS_COMPILE = " -isystem ${opencv}/include/opencv4";
123
-
install -Dt $out libstablediffusion.a Makefile go.mod *.go stablediffusion.h
261
+
tar cf - --exclude=CMakeFiles --exclude="*.o" --exclude="*.so" --exclude="*.so.*" . \
127
-
go-tiny-dream = fetchFromGitHub {
129
-
repo = "go-tiny-dream";
130
-
rev = "772a9c0d9aaf768290e63cca3c904fe69faf677a";
131
-
hash = "sha256-r+wzFIjaI6cxAm/eXN3q8LRZZz+lE5EA4lCTk5+ZnIY=";
132
-
fetchSubmodules = true;
266
+
go-tiny-dream-ncnn = ncnn.overrideAttrs (self: {
267
+
name = "go-tiny-dream-ncnn";
268
+
inherit (go-tiny-dream) src;
269
+
sourceRoot = "source/ncnn";
270
+
cmakeFlags = self.cmakeFlags ++ [
271
+
(lib.cmakeBool "NCNN_SHARED_LIB" false)
272
+
(lib.cmakeBool "NCNN_OPENMP" false)
273
+
(lib.cmakeBool "NCNN_VULKAN" false)
274
+
(lib.cmakeBool "NCNN_AVX" enable_avx)
275
+
(lib.cmakeBool "NCNN_AVX2" enable_avx2)
276
+
(lib.cmakeBool "NCNN_AVX512" enable_avx512)
277
+
(lib.cmakeBool "NCNN_FMA" enable_fma)
278
+
(lib.cmakeBool "NCNN_F16C" enable_f16c)
135
-
go-tiny-dream' = runCommand "go_tiny_dream_src" { } ''
136
-
cp -r --no-preserve=mode,ownership ${go-tiny-dream} $out
137
-
sed -i $out/Makefile \
138
-
-e 's;lib/libncnn;lib64/libncnn;g'
282
+
go-tiny-dream = stdenv.mkDerivation {
283
+
name = "go-tiny-dream";
284
+
src = fetchFromGitHub {
286
+
repo = "go-tiny-dream";
287
+
rev = "772a9c0d9aaf768290e63cca3c904fe69faf677a";
288
+
hash = "sha256-r+wzFIjaI6cxAm/eXN3q8LRZZz+lE5EA4lCTk5+ZnIY=";
289
+
fetchSubmodules = true;
293
+
mkdir -p source/ncnn/build
294
+
cp -r --no-preserve=mode ${go-tiny-dream-ncnn} source/ncnn/build/install
296
+
buildFlags = [ "libtinydream.a" ];
299
+
tar cf - --exclude="*.o" . \
302
+
meta.broken = lib.versionOlder go-tiny-dream.stdenv.cc.version "13";
GO_TAGS = lib.optional with_tinydream "tinydream"
++ lib.optional with_tts "tts"
++ lib.optional with_stablediffusion "stablediffusion";
# It's necessary to consistently use backendStdenv when building with CUDA support,
# otherwise we get libstdc++ errors downstream.
149
-
buildGoModule.override { stdenv = cudaPackages.backendStdenv; }
313
+
cudaPackages.backendStdenv
153
-
self = buildEnv rec {
154
-
pname = "local-ai";
155
-
version = "2.10.1";
317
+
pname = "local-ai";
318
+
version = "2.10.1";
319
+
src = fetchFromGitHub {
320
+
owner = "go-skynet";
322
+
rev = "v${version}";
323
+
hash = "sha256-135s1Gw8mfOIx4kXlw2pYrD3ewwajUtnz3sPY/CtoLw=";
157
-
src = fetchFromGitHub {
158
-
owner = "go-skynet";
160
-
rev = "v${version}";
161
-
hash = "sha256-135s1Gw8mfOIx4kXlw2pYrD3ewwajUtnz3sPY/CtoLw=";
326
+
self = buildGoModule.override { stdenv = effectiveStdenv; } {
327
+
inherit pname version src;
vendorHash = "sha256-UCeG0TKS+VBW8D87VmxTHS2tCAf0ADEYTJayaSiua6s=";
167
-
# `cc1plus: error: '-Wformat-security' ignored without '-Wformat' [-Werror=format-security]`
168
-
# when building jtreg
169
-
env.NIX_CFLAGS_COMPILE = "-Wformat";
331
+
env.NIX_CFLAGS_COMPILE = lib.optionalString with_stablediffusion " -isystem ${opencv}/include/opencv4";
···
-e 's;git clone.*go-llama-ggml$;${cp} ${go-llama-ggml} sources/go-llama-ggml;' \
-e 's;git clone.*gpt4all$;${cp} ${gpt4all} sources/gpt4all;' \
179
-
-e 's;git clone.*go-piper$;${cp} ${go-piper} sources/go-piper;' \
341
+
-e 's;git clone.*go-piper$;${cp} ${if with_tts then go-piper else go-piper.src} sources/go-piper;' \
-e 's;git clone.*go-rwkv$;${cp} ${go-rwkv} sources/go-rwkv;' \
181
-
-e 's;git clone.*whisper\.cpp$;${cp} ${whisper} sources/whisper\.cpp;' \
343
+
-e 's;git clone.*whisper\.cpp$;${cp} ${whisper-cpp.src} sources/whisper\.cpp;' \
-e 's;git clone.*go-bert$;${cp} ${go-bert} sources/go-bert;' \
-e 's;git clone.*diffusion$;${cp} ${if with_stablediffusion then go-stable-diffusion else go-stable-diffusion.src} sources/go-stable-diffusion;' \
184
-
-e 's;git clone.*go-tiny-dream$;${cp} ${go-tiny-dream'} sources/go-tiny-dream;' \
346
+
-e 's;git clone.*go-tiny-dream$;${cp} ${if with_tinydream then go-tiny-dream else go-tiny-dream.src} sources/go-tiny-dream;' \
-e 's, && git checkout.*,,g' \
188
-
sed -i backend/cpp/llama/Makefile \
189
-
-e 's;git clone.*llama\.cpp$;${cp} ${llama_cpp'} llama\.cpp;' \
190
-
-e 's, && git checkout.*,,g' \
350
+
${cp} ${llama-cpp-grpc}/bin/*grpc-server backend/cpp/llama/grpc-server
351
+
echo "grpc-server:" > backend/cpp/llama/Makefile
355
+
buildInputs = typedBuiltInputs
356
+
++ lib.optional with_stablediffusion go-stable-diffusion.buildInputs
357
+
++ lib.optional with_tts go-piper.buildInputs;
359
+
nativeBuildInputs = [ makeWrapper ];
361
+
enableParallelBuilding = false;
···
206
-
assert (lib.count lib.id [ with_openblas with_cublas with_clblas ]) <= 1;
207
-
if with_openblas then "openblas"
208
-
else if with_cublas then "cublas"
209
-
else if with_clblas then "clblas"
371
+
# should be passed as makeFlags, but build system failes with strings
372
+
# containing spaces
373
+
env.GO_TAGS = builtins.concatStringsSep " " GO_TAGS;
213
-
"VERSION=v${version}"
214
-
"BUILD_TYPE=${buildType}"
215
-
"GO_TAGS=\"${builtins.concatStringsSep " " GO_TAGS}\""
217
-
++ lib.optional with_cublas "CUDA_LIBPATH=${cudaPackages.cuda_cudart}/lib";
221
-
make ${builtins.concatStringsSep " " buildFlags} build
376
+
"VERSION=v${version}"
377
+
"BUILD_TYPE=${BUILD_TYPE}"
379
+
++ lib.optional with_cublas "CUDA_LIBPATH=${cudaPackages.cuda_cudart}/lib"
380
+
++ lib.optional with_tts "PIPER_CGO_CXXFLAGS=-DSPDLOG_FMT_EXTERNAL=1";
386
+
make prepare-sources
387
+
# avoid rebuild of prebuilt libraries
388
+
touch sources/**/lib*.a
389
+
cp ${whisper-cpp}/lib/static/lib*.a sources/whisper.cpp
392
+
''${enableParallelBuilding:+-j''${NIX_BUILD_CORES}}
395
+
_accumFlagsArray makeFlags makeFlagsArray buildFlags buildFlagsArray
396
+
echoCmd 'build flags' "''${flagsArray[@]}"
397
+
make build "''${flagsArray[@]}"
install -Dt $out/bin ${pname}
229
-
protobuf # provides also abseil_cpp as propagated build input
233
-
++ lib.optionals with_stablediffusion
235
-
++ lib.optionals with_tts
236
-
[ sonic spdlog fmt onnxruntime ]
237
-
++ lib.optionals with_cublas
238
-
[ cudaPackages.cudatoolkit cudaPackages.cuda_cudart ]
239
-
++ lib.optionals with_openblas
241
-
++ lib.optionals with_clblas
242
-
[ clblast ocl-icd opencl-headers ]
408
+
runHook postInstall
# patching rpath with patchelf doens't work. The execuable
# raises an segmentation fault
···
--prefix PATH : "${ffmpeg}/bin"
259
-
nativeBuildInputs = [
264
-
++ lib.optional with_openblas pkg-config
265
-
++ lib.optional with_cublas cudaPackages.cuda_nvcc
425
+
passthru.local-packages = {
427
+
go-tiny-dream go-rwkv go-bert go-llama-ggml gpt4all go-piper
428
+
llama-cpp-grpc whisper-cpp go-tiny-dream-ncnn;
···
maintainers = with maintainers; [ onny ck3d ];
platforms = platforms.linux;
305
-
# TODO: provide onnxruntime in the right way
307
-
|| (with_tinydream && (lib.lessThan self.stdenv.cc.version "13"));