2021-01-09 10:05:03 +00:00
|
|
|
{ config, stdenv, lib, fetchurl, fetchzip, boost, cmake, ffmpeg, gettext, glew
|
2020-04-24 23:36:52 +00:00
|
|
|
, ilmbase, libXi, libX11, libXext, libXrender
|
|
|
|
, libjpeg, libpng, libsamplerate, libsndfile
|
2023-01-11 07:51:40 +00:00
|
|
|
, libtiff, libwebp, libGLU, libGL, openal, opencolorio, openexr, openimagedenoise, openimageio, openjpeg, python310Packages
|
2020-04-24 23:36:52 +00:00
|
|
|
, openvdb, libXxf86vm, tbb, alembic
|
2022-03-30 09:31:56 +00:00
|
|
|
, zlib, zstd, fftw, opensubdiv, freetype, jemalloc, ocl-icd, addOpenGLRunpath
|
2020-04-24 23:36:52 +00:00
|
|
|
, jackaudioSupport ? false, libjack2
|
2022-04-15 01:41:22 +00:00
|
|
|
, cudaSupport ? config.cudaSupport or false, cudaPackages ? {}
|
2022-08-21 13:32:41 +00:00
|
|
|
, hipSupport ? false, hip # comes with a significantly larger closure size
|
2020-04-24 23:36:52 +00:00
|
|
|
, colladaSupport ? true, opencollada
|
2021-04-05 15:23:46 +00:00
|
|
|
, spaceNavSupport ? stdenv.isLinux, libspnav
|
2020-04-24 23:36:52 +00:00
|
|
|
, makeWrapper
|
2020-11-30 08:33:03 +00:00
|
|
|
, pugixml, llvmPackages, SDL, Cocoa, CoreGraphics, ForceFeedback, OpenAL, OpenGL
|
2021-04-05 15:23:46 +00:00
|
|
|
, potrace
|
|
|
|
, openxr-loader
|
2021-06-28 23:13:55 +00:00
|
|
|
, embree, gmp, libharu
|
2020-04-24 23:36:52 +00:00
|
|
|
}:
|
|
|
|
|
2021-01-09 10:05:03 +00:00
|
|
|
let
|
2022-03-30 09:31:56 +00:00
|
|
|
python = python310Packages.python;
|
2021-01-09 10:05:03 +00:00
|
|
|
optix = fetchzip {
|
2022-03-30 09:31:56 +00:00
|
|
|
# url taken from the archlinux blender PKGBUILD
|
|
|
|
url = "https://developer.download.nvidia.com/redist/optix/v7.3/OptiX-7.3.0-Include.zip";
|
|
|
|
sha256 = "0max1j4822mchj0xpz9lqzh91zkmvsn4py0r174cvqfz8z8ykjk8";
|
2021-01-09 10:05:03 +00:00
|
|
|
};
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2021-01-09 10:05:03 +00:00
|
|
|
in
|
2020-04-24 23:36:52 +00:00
|
|
|
stdenv.mkDerivation rec {
|
|
|
|
pname = "blender";
|
2022-10-30 15:09:59 +00:00
|
|
|
version = "3.3.1";
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
src = fetchurl {
|
|
|
|
url = "https://download.blender.org/source/${pname}-${version}.tar.xz";
|
2022-10-30 15:09:59 +00:00
|
|
|
hash = "sha256-KtpI8L+KDKgCuYfXV0UgEuH48krPTSNFOwnC1ZURjMo=";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
patches = lib.optional stdenv.isDarwin ./darwin.patch;
|
|
|
|
|
2022-03-30 09:31:56 +00:00
|
|
|
nativeBuildInputs = [ cmake makeWrapper python310Packages.wrapPython llvmPackages.llvm.dev ]
|
2023-02-02 18:25:31 +00:00
|
|
|
++ lib.optionals cudaSupport [ addOpenGLRunpath ];
|
2020-04-24 23:36:52 +00:00
|
|
|
buildInputs =
|
2020-11-30 08:33:03 +00:00
|
|
|
[ boost ffmpeg gettext glew ilmbase
|
2023-01-11 07:51:40 +00:00
|
|
|
freetype libjpeg libpng libsamplerate libsndfile libtiff libwebp
|
|
|
|
opencolorio openexr openimagedenoise openimageio openjpeg python zlib zstd fftw jemalloc
|
2020-04-24 23:36:52 +00:00
|
|
|
alembic
|
|
|
|
(opensubdiv.override { inherit cudaSupport; })
|
|
|
|
tbb
|
2020-09-25 04:45:31 +00:00
|
|
|
embree
|
2020-11-30 08:33:03 +00:00
|
|
|
gmp
|
2021-03-23 19:22:30 +00:00
|
|
|
pugixml
|
2021-04-05 15:23:46 +00:00
|
|
|
potrace
|
2021-06-28 23:13:55 +00:00
|
|
|
libharu
|
2020-04-24 23:36:52 +00:00
|
|
|
]
|
|
|
|
++ (if (!stdenv.isDarwin) then [
|
|
|
|
libXi libX11 libXext libXrender
|
|
|
|
libGLU libGL openal
|
|
|
|
libXxf86vm
|
2021-04-05 15:23:46 +00:00
|
|
|
openxr-loader
|
2020-04-24 23:36:52 +00:00
|
|
|
# OpenVDB currently doesn't build on darwin
|
|
|
|
openvdb
|
|
|
|
]
|
|
|
|
else [
|
2021-03-23 19:22:30 +00:00
|
|
|
llvmPackages.openmp SDL Cocoa CoreGraphics ForceFeedback OpenAL OpenGL
|
2020-04-24 23:36:52 +00:00
|
|
|
])
|
2023-02-02 18:25:31 +00:00
|
|
|
++ lib.optional jackaudioSupport libjack2
|
|
|
|
++ lib.optional cudaSupport cudaPackages.cudatoolkit
|
|
|
|
++ lib.optional colladaSupport opencollada
|
|
|
|
++ lib.optional spaceNavSupport libspnav;
|
2022-03-30 09:31:56 +00:00
|
|
|
pythonPath = with python310Packages; [ numpy requests ];
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2020-09-25 04:45:31 +00:00
|
|
|
postPatch = ''
|
|
|
|
# allow usage of dynamically linked embree
|
|
|
|
rm build_files/cmake/Modules/FindEmbree.cmake
|
|
|
|
'' +
|
|
|
|
(if stdenv.isDarwin then ''
|
2020-04-24 23:36:52 +00:00
|
|
|
: > build_files/cmake/platform/platform_apple_xcode.cmake
|
|
|
|
substituteInPlace source/creator/CMakeLists.txt \
|
|
|
|
--replace '${"$"}{LIBDIR}/python' \
|
2022-07-14 12:49:19 +00:00
|
|
|
'${python}'
|
2020-04-24 23:36:52 +00:00
|
|
|
substituteInPlace build_files/cmake/platform/platform_apple.cmake \
|
|
|
|
--replace '${"$"}{LIBDIR}/python' \
|
|
|
|
'${python}' \
|
|
|
|
--replace '${"$"}{LIBDIR}/opencollada' \
|
|
|
|
'${opencollada}' \
|
|
|
|
--replace '${"$"}{PYTHON_LIBPATH}/site-packages/numpy' \
|
2022-03-30 09:31:56 +00:00
|
|
|
'${python310Packages.numpy}/${python.sitePackages}/numpy'
|
2020-04-24 23:36:52 +00:00
|
|
|
'' else ''
|
|
|
|
substituteInPlace extern/clew/src/clew.c --replace '"libOpenCL.so"' '"${ocl-icd}/lib/libOpenCL.so"'
|
2022-08-21 13:32:41 +00:00
|
|
|
'') +
|
2023-02-16 17:41:37 +00:00
|
|
|
(lib.optionalString hipSupport ''
|
2022-08-21 13:32:41 +00:00
|
|
|
substituteInPlace extern/hipew/src/hipew.c --replace '"/opt/rocm/hip/lib/libamdhip64.so"' '"${hip}/lib/libamdhip64.so"'
|
|
|
|
substituteInPlace extern/hipew/src/hipew.c --replace '"opt/rocm/hip/bin"' '"${hip}/bin"'
|
2023-02-16 17:41:37 +00:00
|
|
|
'');
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
cmakeFlags =
|
|
|
|
[
|
|
|
|
"-DWITH_ALEMBIC=ON"
|
|
|
|
"-DWITH_MOD_OCEANSIM=ON"
|
|
|
|
"-DWITH_CODEC_FFMPEG=ON"
|
|
|
|
"-DWITH_CODEC_SNDFILE=ON"
|
|
|
|
"-DWITH_INSTALL_PORTABLE=OFF"
|
|
|
|
"-DWITH_FFTW3=ON"
|
|
|
|
"-DWITH_SDL=OFF"
|
|
|
|
"-DWITH_OPENCOLORIO=ON"
|
|
|
|
"-DWITH_OPENSUBDIV=ON"
|
2020-06-18 07:06:33 +00:00
|
|
|
"-DPYTHON_LIBRARY=${python.libPrefix}"
|
2020-04-24 23:36:52 +00:00
|
|
|
"-DPYTHON_LIBPATH=${python}/lib"
|
2020-06-18 07:06:33 +00:00
|
|
|
"-DPYTHON_INCLUDE_DIR=${python}/include/${python.libPrefix}"
|
2020-04-24 23:36:52 +00:00
|
|
|
"-DPYTHON_VERSION=${python.pythonVersion}"
|
|
|
|
"-DWITH_PYTHON_INSTALL=OFF"
|
|
|
|
"-DWITH_PYTHON_INSTALL_NUMPY=OFF"
|
2022-03-30 09:31:56 +00:00
|
|
|
"-DPYTHON_NUMPY_PATH=${python310Packages.numpy}/${python.sitePackages}"
|
|
|
|
"-DPYTHON_NUMPY_INCLUDE_DIRS=${python310Packages.numpy}/${python.sitePackages}/numpy/core/include"
|
2021-04-12 18:23:04 +00:00
|
|
|
"-DWITH_PYTHON_INSTALL_REQUESTS=OFF"
|
2020-04-24 23:36:52 +00:00
|
|
|
"-DWITH_OPENVDB=ON"
|
|
|
|
"-DWITH_TBB=ON"
|
|
|
|
"-DWITH_IMAGE_OPENJPEG=ON"
|
|
|
|
"-DWITH_OPENCOLLADA=${if colladaSupport then "ON" else "OFF"}"
|
|
|
|
]
|
2023-02-02 18:25:31 +00:00
|
|
|
++ lib.optionals stdenv.isDarwin [
|
2020-04-24 23:36:52 +00:00
|
|
|
"-DWITH_CYCLES_OSL=OFF" # requires LLVM
|
|
|
|
"-DWITH_OPENVDB=OFF" # OpenVDB currently doesn't build on darwin
|
|
|
|
|
|
|
|
"-DLIBDIR=/does-not-exist"
|
|
|
|
]
|
|
|
|
# Clang doesn't support "-export-dynamic"
|
2023-02-02 18:25:31 +00:00
|
|
|
++ lib.optional stdenv.cc.isClang "-DPYTHON_LINKFLAGS="
|
|
|
|
++ lib.optional jackaudioSupport "-DWITH_JACK=ON"
|
|
|
|
++ lib.optionals cudaSupport [
|
2021-01-09 10:05:03 +00:00
|
|
|
"-DWITH_CYCLES_CUDA_BINARIES=ON"
|
|
|
|
"-DWITH_CYCLES_DEVICE_OPTIX=ON"
|
|
|
|
"-DOPTIX_ROOT_DIR=${optix}"
|
|
|
|
];
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2023-03-04 12:14:45 +00:00
|
|
|
env.NIX_CFLAGS_COMPILE = "-I${ilmbase.dev}/include/OpenEXR -I${python}/include/${python.libPrefix}";
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
# Since some dependencies are built with gcc 6, we need gcc 6's
|
|
|
|
# libstdc++ in our RPATH. Sigh.
|
2023-02-02 18:25:31 +00:00
|
|
|
NIX_LDFLAGS = lib.optionalString cudaSupport "-rpath ${stdenv.cc.cc.lib}/lib";
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
blenderExecutable =
|
2021-10-04 12:37:57 +00:00
|
|
|
placeholder "out" + (if stdenv.isDarwin then "/Applications/Blender.app/Contents/MacOS/Blender" else "/bin/blender");
|
|
|
|
postInstall = lib.optionalString stdenv.isDarwin ''
|
|
|
|
mkdir $out/Applications
|
|
|
|
mv $out/Blender.app $out/Applications
|
|
|
|
'' + ''
|
2021-04-12 18:23:04 +00:00
|
|
|
buildPythonPath "$pythonPath"
|
2020-04-24 23:36:52 +00:00
|
|
|
wrapProgram $blenderExecutable \
|
2021-04-12 18:23:04 +00:00
|
|
|
--prefix PATH : $program_PATH \
|
|
|
|
--prefix PYTHONPATH : "$program_PYTHONPATH" \
|
2020-04-24 23:36:52 +00:00
|
|
|
--add-flags '--python-use-system-env'
|
|
|
|
'';
|
|
|
|
|
|
|
|
# Set RUNPATH so that libcuda and libnvrtc in /run/opengl-driver(-32)/lib can be
|
|
|
|
# found. See the explanation in libglvnd.
|
2023-02-02 18:25:31 +00:00
|
|
|
postFixup = lib.optionalString cudaSupport ''
|
2020-04-24 23:36:52 +00:00
|
|
|
for program in $out/bin/blender $out/bin/.blender-wrapped; do
|
|
|
|
isELF "$program" || continue
|
|
|
|
addOpenGLRunpath "$program"
|
|
|
|
done
|
|
|
|
'';
|
|
|
|
|
2021-01-15 22:18:51 +00:00
|
|
|
meta = with lib; {
|
2020-04-24 23:36:52 +00:00
|
|
|
description = "3D Creation/Animation/Publishing System";
|
|
|
|
homepage = "https://www.blender.org";
|
|
|
|
# They comment two licenses: GPLv2 and Blender License, but they
|
|
|
|
# say: "We've decided to cancel the BL offering for an indefinite period."
|
2021-01-09 10:05:03 +00:00
|
|
|
# OptiX, enabled with cudaSupport, is non-free.
|
|
|
|
license = with licenses; [ gpl2Plus ] ++ optional cudaSupport unfree;
|
2020-04-24 23:36:52 +00:00
|
|
|
platforms = [ "x86_64-linux" "x86_64-darwin" ];
|
2020-06-18 07:06:33 +00:00
|
|
|
maintainers = with maintainers; [ goibhniu veprbl ];
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
}
|