11{
22 lib ,
3+ glibc ,
34 config ,
45 stdenv ,
56 mkShell ,
3031 useRocm ? config . rocmSupport ,
3132 useVulkan ? false ,
3233 llamaVersion ? "0.0.0" , # Arbitrary version, substituted by the flake
34+
35+ # It's necessary to consistently use backendStdenv when building with CUDA support,
36+ # otherwise we get libstdc++ errors downstream.
37+ effectiveStdenv ? if useCuda then cudaPackages . backendStdenv else stdenv ,
38+ enableStatic ? effectiveStdenv . hostPlatform . isStatic
3339} @inputs :
3440
3541let
4046 strings
4147 versionOlder
4248 ;
43-
44- # It's necessary to consistently use backendStdenv when building with CUDA support,
45- # otherwise we get libstdc++ errors downstream.
49+
4650 stdenv = throw "Use effectiveStdenv instead" ;
47- effectiveStdenv = if useCuda then cudaPackages . backendStdenv else inputs . stdenv ;
4851
4952 suffices =
5053 lib . optionals useBlas [ "BLAS" ]
@@ -167,6 +170,9 @@ effectiveStdenv.mkDerivation (
167170 # TODO: Replace with autoAddDriverRunpath
168171 # once https://github.com/NixOS/nixpkgs/pull/275241 has been merged
169172 cudaPackages . autoAddOpenGLRunpathHook
173+ ]
174+ ++ optionals ( effectiveStdenv . hostPlatform . isGnu && enableStatic ) [
175+ glibc . static
170176 ] ;
171177
172178 buildInputs =
@@ -181,7 +187,7 @@ effectiveStdenv.mkDerivation (
181187 [
182188 ( cmakeBool "LLAMA_NATIVE" false )
183189 ( cmakeBool "LLAMA_BUILD_SERVER" true )
184- ( cmakeBool "BUILD_SHARED_LIBS" true )
190+ ( cmakeBool "BUILD_SHARED_LIBS" ( ! enableStatic ) )
185191 ( cmakeBool "CMAKE_SKIP_BUILD_RPATH" true )
186192 ( cmakeBool "LLAMA_BLAS" useBlas )
187193 ( cmakeBool "LLAMA_CLBLAST" useOpenCL )
@@ -190,6 +196,7 @@ effectiveStdenv.mkDerivation (
190196 ( cmakeBool "LLAMA_METAL" useMetalKit )
191197 ( cmakeBool "LLAMA_MPI" useMpi )
192198 ( cmakeBool "LLAMA_VULKAN" useVulkan )
199+ ( cmakeBool "LLAMA_STATIC" enableStatic )
193200 ]
194201 ++ optionals useCuda [
195202 (
0 commit comments