1 { config, stdenv, lib, fetchgit, fetchzip, boost, cmake, ffmpeg, gettext, glew
2 , ilmbase, libXi, libX11, libXext, libXrender
3 , libjpeg, libpng, libsamplerate, libsndfile
4 , libtiff, libGLU, libGL, openal, opencolorio, openexr, openimagedenoise, openimageio2, openjpeg, python39Packages
5 , openvdb, libXxf86vm, tbb, alembic
6 , zlib, fftw, opensubdiv, freetype, jemalloc, ocl-icd, addOpenGLRunpath
7 , jackaudioSupport ? false, libjack2
8 , cudaSupport ? config.cudaSupport or false, cudatoolkit
9 , colladaSupport ? true, opencollada
10 , spaceNavSupport ? stdenv.isLinux, libspnav
12 , pugixml, llvmPackages, SDL, Cocoa, CoreGraphics, ForceFeedback, OpenAL, OpenGL
20 python = python39Packages.python;
22 url = "https://developer.download.nvidia.com/redist/optix/v7.0/OptiX-7.0.0-include.zip";
23 sha256 = "1b3ccd3197anya2bj3psxdrvrpfgiwva5zfv2xmyrl73nb2dvfr7";
27 stdenv.mkDerivation rec {
32 url = "https://git.blender.org/blender.git";
33 rev = "ec241eb0d020e20924651490a5b74473e347091d";
34 sha256 = "sha256-cQCEn0HggtAspnIy73S9R15HLSrh5wpPrNubEdivLXw=";
37 patches = lib.optional stdenv.isDarwin ./darwin.patch;
40 [ cmake makeWrapper python39Packages.wrapPython ]
41 ++ optional cudaSupport addOpenGLRunpath;
43 [ boost ffmpeg gettext glew ilmbase
44 freetype libjpeg libpng libsamplerate libsndfile libtiff
45 opencolorio openexr openimagedenoise openimageio2 openjpeg python zlib fftw jemalloc
47 (opensubdiv.override { inherit cudaSupport; })
54 ++ (if (!stdenv.isDarwin) then [
55 libXi libX11 libXext libXrender
59 # OpenVDB currently doesn't build on darwin
63 llvmPackages.openmp SDL Cocoa CoreGraphics ForceFeedback OpenAL OpenGL
65 ++ optional jackaudioSupport libjack2
66 ++ optional cudaSupport cudatoolkit
67 ++ optional colladaSupport opencollada
68 ++ optional spaceNavSupport libspnav;
69 propagatedBuildInputs = with python39Packages; [ numpy requests ];
72 # allow usage of dynamically linked embree
73 rm build_files/cmake/Modules/FindEmbree.cmake
75 (if stdenv.isDarwin then ''
76 : > build_files/cmake/platform/platform_apple_xcode.cmake
77 substituteInPlace source/creator/CMakeLists.txt \
78 --replace '${"$"}{LIBDIR}/python' \
80 --replace '${"$"}{LIBDIR}/openmp' \
81 '${llvmPackages.openmp}'
82 substituteInPlace build_files/cmake/platform/platform_apple.cmake \
83 --replace 'set(PYTHON_VERSION 3.7)' \
84 'set(PYTHON_VERSION ${python.pythonVersion})' \
85 --replace '${"$"}{PYTHON_VERSION}m' \
86 '${"$"}{PYTHON_VERSION}' \
87 --replace '${"$"}{LIBDIR}/python' \
89 --replace '${"$"}{LIBDIR}/opencollada' \
91 --replace '${"$"}{PYTHON_LIBPATH}/site-packages/numpy' \
92 '${python39Packages.numpy}/${python.sitePackages}/numpy' \
93 --replace '${"$"}{PYTHON_LIBPATH}/site-packages/requests' \
94 '${python39Packages.requests}/${python.sitePackages}/requests'
96 substituteInPlace extern/clew/src/clew.c --replace '"libOpenCL.so"' '"${ocl-icd}/lib/libOpenCL.so"'
102 "-DWITH_MOD_OCEANSIM=ON"
103 "-DWITH_CODEC_FFMPEG=ON"
104 "-DWITH_CODEC_SNDFILE=ON"
105 "-DWITH_INSTALL_PORTABLE=OFF"
108 "-DWITH_OPENCOLORIO=ON"
109 "-DWITH_OPENSUBDIV=ON"
110 "-DPYTHON_LIBRARY=${python.libPrefix}"
111 "-DPYTHON_LIBPATH=${python}/lib"
112 "-DPYTHON_INCLUDE_DIR=${python}/include/${python.libPrefix}"
113 "-DPYTHON_VERSION=${python.pythonVersion}"
114 "-DWITH_PYTHON_INSTALL=OFF"
115 "-DWITH_PYTHON_INSTALL_NUMPY=OFF"
116 "-DPYTHON_NUMPY_INCLUDE_DIRS=${python39Packages.numpy}/${python.sitePackages}/numpy/core/include"
117 "-DPYTHON_NUMPY_PATH=${python39Packages.numpy}/${python.sitePackages}"
118 "-DWITH_PYTHON_INSTALL_REQUESTS=OFF"
121 "-DWITH_IMAGE_OPENJPEG=ON"
122 "-DWITH_OPENCOLLADA=${if colladaSupport then "ON" else "OFF"}"
124 ++ optionals stdenv.isDarwin [
125 "-DWITH_CYCLES_OSL=OFF" # requires LLVM
126 "-DWITH_OPENVDB=OFF" # OpenVDB currently doesn't build on darwin
128 "-DLIBDIR=/does-not-exist"
130 # Clang doesn't support "-export-dynamic"
131 ++ optional stdenv.cc.isClang "-DPYTHON_LINKFLAGS="
132 ++ optional jackaudioSupport "-DWITH_JACK=ON"
133 ++ optional cudaSupport [
134 "-DWITH_CYCLES_CUDA_BINARIES=ON"
135 "-DWITH_CYCLES_DEVICE_OPTIX=ON"
136 "-DOPTIX_ROOT_DIR=${optix}"
139 NIX_CFLAGS_COMPILE = "-I${ilmbase.dev}/include/OpenEXR -I${python}/include/${python.libPrefix}";
141 # Since some dependencies are built with gcc 6, we need gcc 6's
142 # libstdc++ in our RPATH. Sigh.
143 NIX_LDFLAGS = optionalString cudaSupport "-rpath ${stdenv.cc.cc.lib}/lib";
146 placeholder "out" + (if stdenv.isDarwin then "/Blender.app/Contents/MacOS/Blender" else "/bin/blender");
148 buildPythonPath "$propagatedBuildInputs"
149 wrapProgram $blenderExecutable \
150 --prefix PATH : $program_PATH \
151 --prefix PYTHONPATH : "$program_PYTHONPATH" \
152 --add-flags '--python-use-system-env'
155 # Set RUNPATH so that libcuda and libnvrtc in /run/opengl-driver(-32)/lib can be
156 # found. See the explanation in libglvnd.
157 postFixup = optionalString cudaSupport ''
158 for program in $out/bin/blender $out/bin/.blender-wrapped; do
159 isELF "$program" || continue
160 addOpenGLRunpath "$program"
165 description = "3D Creation/Animation/Publishing System";
166 homepage = "https://www.blender.org";
167 # They comment two licenses: GPLv2 and Blender License, but they
168 # say: "We've decided to cancel the BL offering for an indefinite period."
169 # OptiX, enabled with cudaSupport, is non-free.
170 license = with licenses; [ gpl2Plus ] ++ optional cudaSupport unfree;
171 platforms = [ "x86_64-linux" "x86_64-darwin" ];
172 maintainers = with maintainers; [ goibhniu veprbl ];