1 { config, stdenv, lib, fetchurl, 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, python3Packages
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 ? false, libspnav
12 , pugixml, llvmPackages, SDL, Cocoa, CoreGraphics, ForceFeedback, OpenAL, OpenGL
20 python = python3Packages.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://download.blender.org/source/${pname}-${version}.tar.xz";
33 sha256 = "15a5vffn18a920286x0avbc2rap56k6y531wgibq68r90g2cz4g7";
36 patches = lib.optional stdenv.isDarwin ./darwin.patch;
38 nativeBuildInputs = [ cmake makeWrapper ] ++ optional cudaSupport addOpenGLRunpath;
40 [ boost ffmpeg gettext glew ilmbase
41 freetype libjpeg libpng libsamplerate libsndfile libtiff
42 opencolorio openexr openimagedenoise openimageio2 openjpeg python zlib fftw jemalloc
44 (opensubdiv.override { inherit cudaSupport; })
51 ++ (if (!stdenv.isDarwin) then [
52 libXi libX11 libXext libXrender
56 # OpenVDB currently doesn't build on darwin
60 llvmPackages.openmp SDL Cocoa CoreGraphics ForceFeedback OpenAL OpenGL
62 ++ optional jackaudioSupport libjack2
63 ++ optional cudaSupport cudatoolkit
64 ++ optional colladaSupport opencollada
65 ++ optional spaceNavSupport libspnav;
68 # allow usage of dynamically linked embree
69 rm build_files/cmake/Modules/FindEmbree.cmake
71 (if stdenv.isDarwin then ''
72 : > build_files/cmake/platform/platform_apple_xcode.cmake
73 substituteInPlace source/creator/CMakeLists.txt \
74 --replace '${"$"}{LIBDIR}/python' \
76 --replace '${"$"}{LIBDIR}/openmp' \
77 '${llvmPackages.openmp}'
78 substituteInPlace build_files/cmake/platform/platform_apple.cmake \
79 --replace 'set(PYTHON_VERSION 3.7)' \
80 'set(PYTHON_VERSION ${python.pythonVersion})' \
81 --replace '${"$"}{PYTHON_VERSION}m' \
82 '${"$"}{PYTHON_VERSION}' \
83 --replace '${"$"}{LIBDIR}/python' \
85 --replace '${"$"}{LIBDIR}/opencollada' \
87 --replace '${"$"}{PYTHON_LIBPATH}/site-packages/numpy' \
88 '${python3Packages.numpy}/${python.sitePackages}/numpy' \
89 --replace '${"$"}{PYTHON_LIBPATH}/site-packages/requests' \
90 '${python3Packages.requests}/${python.sitePackages}/requests'
92 substituteInPlace extern/clew/src/clew.c --replace '"libOpenCL.so"' '"${ocl-icd}/lib/libOpenCL.so"'
98 "-DWITH_MOD_OCEANSIM=ON"
99 "-DWITH_CODEC_FFMPEG=ON"
100 "-DWITH_CODEC_SNDFILE=ON"
101 "-DWITH_INSTALL_PORTABLE=OFF"
104 "-DWITH_OPENCOLORIO=ON"
105 "-DWITH_OPENSUBDIV=ON"
106 "-DPYTHON_LIBRARY=${python.libPrefix}"
107 "-DPYTHON_LIBPATH=${python}/lib"
108 "-DPYTHON_INCLUDE_DIR=${python}/include/${python.libPrefix}"
109 "-DPYTHON_VERSION=${python.pythonVersion}"
110 "-DWITH_PYTHON_INSTALL=OFF"
111 "-DWITH_PYTHON_INSTALL_NUMPY=OFF"
112 "-DWITH_PYTHON_INSTALL_REQUESTS=OFF"
113 "-DPYTHON_NUMPY_PATH=${python3Packages.numpy}/${python.sitePackages}"
114 "-DPYTHON_REQUESTS_PATH=${python3Packages.numpy}/${python.sitePackages}"
115 "-DPYTHON_NUMPY_INCLUDE_DIRS=${python3Packages.numpy}/${python.sitePackages}/numpy/core/include"
116 "-DPYTHON_REQUESTS_INCLUDE_DIRS=${python3Packages.requests}/${python.sitePackages}/requests/core/include"
119 "-DWITH_IMAGE_OPENJPEG=ON"
120 "-DWITH_OPENCOLLADA=${if colladaSupport then "ON" else "OFF"}"
122 ++ optionals stdenv.isDarwin [
123 "-DWITH_CYCLES_OSL=OFF" # requires LLVM
124 "-DWITH_OPENVDB=OFF" # OpenVDB currently doesn't build on darwin
126 "-DLIBDIR=/does-not-exist"
128 # Clang doesn't support "-export-dynamic"
129 ++ optional stdenv.cc.isClang "-DPYTHON_LINKFLAGS="
130 ++ optional jackaudioSupport "-DWITH_JACK=ON"
131 ++ optional cudaSupport [
132 "-DWITH_CYCLES_CUDA_BINARIES=ON"
133 "-DWITH_CYCLES_DEVICE_OPTIX=ON"
134 "-DOPTIX_ROOT_DIR=${optix}"
137 NIX_CFLAGS_COMPILE = "-I${ilmbase.dev}/include/OpenEXR -I${python}/include/${python.libPrefix}";
139 # Since some dependencies are built with gcc 6, we need gcc 6's
140 # libstdc++ in our RPATH. Sigh.
141 NIX_LDFLAGS = optionalString cudaSupport "-rpath ${stdenv.cc.cc.lib}/lib";
144 placeholder "out" + (if stdenv.isDarwin then "/Blender.app/Contents/MacOS/Blender" else "/bin/blender");
145 # --python-expr is used to workaround https://developer.blender.org/T74304
147 wrapProgram $blenderExecutable \
148 --prefix PYTHONPATH : ${python3Packages.numpy}/${python.sitePackages} \
149 --prefix PYTHONPATH : ${python3Packages.requests}/${python.sitePackages} \
150 --add-flags '--python-use-system-env'
153 # Set RUNPATH so that libcuda and libnvrtc in /run/opengl-driver(-32)/lib can be
154 # found. See the explanation in libglvnd.
155 postFixup = optionalString cudaSupport ''
156 for program in $out/bin/blender $out/bin/.blender-wrapped; do
157 isELF "$program" || continue
158 addOpenGLRunpath "$program"
163 description = "3D Creation/Animation/Publishing System";
164 homepage = "https://www.blender.org";
165 # They comment two licenses: GPLv2 and Blender License, but they
166 # say: "We've decided to cancel the BL offering for an indefinite period."
167 # OptiX, enabled with cudaSupport, is non-free.
168 license = with licenses; [ gpl2Plus ] ++ optional cudaSupport unfree;
169 platforms = [ "x86_64-linux" "x86_64-darwin" ];
170 maintainers = with maintainers; [ goibhniu veprbl ];