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, python310Packages
5 , openvdb, libXxf86vm, tbb, alembic
6 , zlib, zstd, fftw, opensubdiv, freetype, jemalloc, ocl-icd, addOpenGLRunpath
7 , jackaudioSupport ? false, libjack2
8 , cudaSupport ? config.cudaSupport or false, cudaPackages ? {}
9 , hipSupport ? false, hip # comes with a significantly larger closure size
10 , colladaSupport ? true, opencollada
11 , spaceNavSupport ? stdenv.isLinux, libspnav
13 , pugixml, llvmPackages, SDL, Cocoa, CoreGraphics, ForceFeedback, OpenAL, OpenGL
16 , embree, gmp, libharu
21 python = python310Packages.python;
23 # url taken from the archlinux blender PKGBUILD
24 url = "https://developer.download.nvidia.com/redist/optix/v7.3/OptiX-7.3.0-Include.zip";
25 sha256 = "0max1j4822mchj0xpz9lqzh91zkmvsn4py0r174cvqfz8z8ykjk8";
29 stdenv.mkDerivation rec {
34 url = "https://download.blender.org/source/${pname}-${version}.tar.xz";
35 hash = "sha256-KtpI8L+KDKgCuYfXV0UgEuH48krPTSNFOwnC1ZURjMo=";
38 patches = lib.optional stdenv.isDarwin ./darwin.patch;
40 nativeBuildInputs = [ cmake makeWrapper python310Packages.wrapPython llvmPackages.llvm.dev ]
41 ++ optionals cudaSupport [ addOpenGLRunpath ];
43 [ boost ffmpeg gettext glew ilmbase
44 freetype libjpeg libpng libsamplerate libsndfile libtiff
45 opencolorio openexr openimagedenoise openimageio2 openjpeg python zlib zstd fftw jemalloc
47 (opensubdiv.override { inherit cudaSupport; })
55 ++ (if (!stdenv.isDarwin) then [
56 libXi libX11 libXext libXrender
60 # OpenVDB currently doesn't build on darwin
64 llvmPackages.openmp SDL Cocoa CoreGraphics ForceFeedback OpenAL OpenGL
66 ++ optional jackaudioSupport libjack2
67 ++ optional cudaSupport cudaPackages.cudatoolkit
68 ++ optional colladaSupport opencollada
69 ++ optional spaceNavSupport libspnav;
70 pythonPath = with python310Packages; [ numpy requests ];
73 # allow usage of dynamically linked embree
74 rm build_files/cmake/Modules/FindEmbree.cmake
76 (if stdenv.isDarwin then ''
77 : > build_files/cmake/platform/platform_apple_xcode.cmake
78 substituteInPlace source/creator/CMakeLists.txt \
79 --replace '${"$"}{LIBDIR}/python' \
81 substituteInPlace build_files/cmake/platform/platform_apple.cmake \
82 --replace '${"$"}{LIBDIR}/python' \
84 --replace '${"$"}{LIBDIR}/opencollada' \
86 --replace '${"$"}{PYTHON_LIBPATH}/site-packages/numpy' \
87 '${python310Packages.numpy}/${python.sitePackages}/numpy'
89 substituteInPlace extern/clew/src/clew.c --replace '"libOpenCL.so"' '"${ocl-icd}/lib/libOpenCL.so"'
91 (if hipSupport then ''
92 substituteInPlace extern/hipew/src/hipew.c --replace '"/opt/rocm/hip/lib/libamdhip64.so"' '"${hip}/lib/libamdhip64.so"'
93 substituteInPlace extern/hipew/src/hipew.c --replace '"opt/rocm/hip/bin"' '"${hip}/bin"'
99 "-DWITH_MOD_OCEANSIM=ON"
100 "-DWITH_CODEC_FFMPEG=ON"
101 "-DWITH_CODEC_SNDFILE=ON"
102 "-DWITH_INSTALL_PORTABLE=OFF"
105 "-DWITH_OPENCOLORIO=ON"
106 "-DWITH_OPENSUBDIV=ON"
107 "-DPYTHON_LIBRARY=${python.libPrefix}"
108 "-DPYTHON_LIBPATH=${python}/lib"
109 "-DPYTHON_INCLUDE_DIR=${python}/include/${python.libPrefix}"
110 "-DPYTHON_VERSION=${python.pythonVersion}"
111 "-DWITH_PYTHON_INSTALL=OFF"
112 "-DWITH_PYTHON_INSTALL_NUMPY=OFF"
113 "-DPYTHON_NUMPY_PATH=${python310Packages.numpy}/${python.sitePackages}"
114 "-DPYTHON_NUMPY_INCLUDE_DIRS=${python310Packages.numpy}/${python.sitePackages}/numpy/core/include"
115 "-DWITH_PYTHON_INSTALL_REQUESTS=OFF"
118 "-DWITH_IMAGE_OPENJPEG=ON"
119 "-DWITH_OPENCOLLADA=${if colladaSupport then "ON" else "OFF"}"
121 ++ optionals stdenv.isDarwin [
122 "-DWITH_CYCLES_OSL=OFF" # requires LLVM
123 "-DWITH_OPENVDB=OFF" # OpenVDB currently doesn't build on darwin
125 "-DLIBDIR=/does-not-exist"
127 # Clang doesn't support "-export-dynamic"
128 ++ optional stdenv.cc.isClang "-DPYTHON_LINKFLAGS="
129 ++ optional jackaudioSupport "-DWITH_JACK=ON"
130 ++ optionals cudaSupport [
131 "-DWITH_CYCLES_CUDA_BINARIES=ON"
132 "-DWITH_CYCLES_DEVICE_OPTIX=ON"
133 "-DOPTIX_ROOT_DIR=${optix}"
136 NIX_CFLAGS_COMPILE = "-I${ilmbase.dev}/include/OpenEXR -I${python}/include/${python.libPrefix}";
138 # Since some dependencies are built with gcc 6, we need gcc 6's
139 # libstdc++ in our RPATH. Sigh.
140 NIX_LDFLAGS = optionalString cudaSupport "-rpath ${stdenv.cc.cc.lib}/lib";
143 placeholder "out" + (if stdenv.isDarwin then "/Applications/Blender.app/Contents/MacOS/Blender" else "/bin/blender");
144 postInstall = lib.optionalString stdenv.isDarwin ''
145 mkdir $out/Applications
146 mv $out/Blender.app $out/Applications
148 buildPythonPath "$pythonPath"
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 ];