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 ? stdenv.isLinux, 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;
39 [ cmake makeWrapper python3Packages.wrapPython ]
40 ++ optional cudaSupport addOpenGLRunpath;
42 [ boost ffmpeg gettext glew ilmbase
43 freetype libjpeg libpng libsamplerate libsndfile libtiff
44 opencolorio openexr openimagedenoise openimageio2 openjpeg python zlib fftw jemalloc
46 (opensubdiv.override { inherit cudaSupport; })
53 ++ (if (!stdenv.isDarwin) then [
54 libXi libX11 libXext libXrender
58 # OpenVDB currently doesn't build on darwin
62 llvmPackages.openmp SDL Cocoa CoreGraphics ForceFeedback OpenAL OpenGL
64 ++ optional jackaudioSupport libjack2
65 ++ optional cudaSupport cudatoolkit
66 ++ optional colladaSupport opencollada
67 ++ optional spaceNavSupport libspnav;
68 propagatedBuildInputs = with python3Packages; [ numpy requests ];
71 # allow usage of dynamically linked embree
72 rm build_files/cmake/Modules/FindEmbree.cmake
74 (if stdenv.isDarwin then ''
75 : > build_files/cmake/platform/platform_apple_xcode.cmake
76 substituteInPlace source/creator/CMakeLists.txt \
77 --replace '${"$"}{LIBDIR}/python' \
79 --replace '${"$"}{LIBDIR}/openmp' \
80 '${llvmPackages.openmp}'
81 substituteInPlace build_files/cmake/platform/platform_apple.cmake \
82 --replace 'set(PYTHON_VERSION 3.7)' \
83 'set(PYTHON_VERSION ${python.pythonVersion})' \
84 --replace '${"$"}{PYTHON_VERSION}m' \
85 '${"$"}{PYTHON_VERSION}' \
86 --replace '${"$"}{LIBDIR}/python' \
88 --replace '${"$"}{LIBDIR}/opencollada' \
90 --replace '${"$"}{PYTHON_LIBPATH}/site-packages/numpy' \
91 '${python3Packages.numpy}/${python.sitePackages}/numpy' \
92 --replace '${"$"}{PYTHON_LIBPATH}/site-packages/requests' \
93 '${python3Packages.requests}/${python.sitePackages}/requests'
95 substituteInPlace extern/clew/src/clew.c --replace '"libOpenCL.so"' '"${ocl-icd}/lib/libOpenCL.so"'
101 "-DWITH_MOD_OCEANSIM=ON"
102 "-DWITH_CODEC_FFMPEG=ON"
103 "-DWITH_CODEC_SNDFILE=ON"
104 "-DWITH_INSTALL_PORTABLE=OFF"
107 "-DWITH_OPENCOLORIO=ON"
108 "-DWITH_OPENSUBDIV=ON"
109 "-DPYTHON_LIBRARY=${python.libPrefix}"
110 "-DPYTHON_LIBPATH=${python}/lib"
111 "-DPYTHON_INCLUDE_DIR=${python}/include/${python.libPrefix}"
112 "-DPYTHON_VERSION=${python.pythonVersion}"
113 "-DWITH_PYTHON_INSTALL=OFF"
114 "-DWITH_PYTHON_INSTALL_NUMPY=OFF"
115 "-DPYTHON_NUMPY_INCLUDE_DIRS=${python3Packages.numpy}/${python.sitePackages}/numpy/core/include"
116 "-DPYTHON_NUMPY_PATH=${python3Packages.numpy}/${python.sitePackages}"
117 "-DWITH_PYTHON_INSTALL_REQUESTS=OFF"
120 "-DWITH_IMAGE_OPENJPEG=ON"
121 "-DWITH_OPENCOLLADA=${if colladaSupport then "ON" else "OFF"}"
123 ++ optionals stdenv.isDarwin [
124 "-DWITH_CYCLES_OSL=OFF" # requires LLVM
125 "-DWITH_OPENVDB=OFF" # OpenVDB currently doesn't build on darwin
127 "-DLIBDIR=/does-not-exist"
129 # Clang doesn't support "-export-dynamic"
130 ++ optional stdenv.cc.isClang "-DPYTHON_LINKFLAGS="
131 ++ optional jackaudioSupport "-DWITH_JACK=ON"
132 ++ optional cudaSupport [
133 "-DWITH_CYCLES_CUDA_BINARIES=ON"
134 "-DWITH_CYCLES_DEVICE_OPTIX=ON"
135 "-DOPTIX_ROOT_DIR=${optix}"
138 NIX_CFLAGS_COMPILE = "-I${ilmbase.dev}/include/OpenEXR -I${python}/include/${python.libPrefix}";
140 # Since some dependencies are built with gcc 6, we need gcc 6's
141 # libstdc++ in our RPATH. Sigh.
142 NIX_LDFLAGS = optionalString cudaSupport "-rpath ${stdenv.cc.cc.lib}/lib";
145 placeholder "out" + (if stdenv.isDarwin then "/Blender.app/Contents/MacOS/Blender" else "/bin/blender");
147 buildPythonPath "$propagatedBuildInputs"
148 wrapProgram $blenderExecutable \
149 --prefix PATH : $program_PATH \
150 --prefix PYTHONPATH : "$program_PYTHONPATH" \
151 --add-flags '--python-use-system-env'
154 # Set RUNPATH so that libcuda and libnvrtc in /run/opengl-driver(-32)/lib can be
155 # found. See the explanation in libglvnd.
156 postFixup = optionalString cudaSupport ''
157 for program in $out/bin/blender $out/bin/.blender-wrapped; do
158 isELF "$program" || continue
159 addOpenGLRunpath "$program"
164 description = "3D Creation/Animation/Publishing System";
165 homepage = "https://www.blender.org";
166 # They comment two licenses: GPLv2 and Blender License, but they
167 # say: "We've decided to cancel the BL offering for an indefinite period."
168 # OptiX, enabled with cudaSupport, is non-free.
169 license = with licenses; [ gpl2Plus ] ++ optional cudaSupport unfree;
170 platforms = [ "x86_64-linux" "x86_64-darwin" ];
171 maintainers = with maintainers; [ goibhniu veprbl ];