python3Packages.orjson: Disable failing tests on 32 bit
[NixPkgs.git] / pkgs / applications / misc / blender / default.nix
blob1d617718ff905eaeab653f038199316b408549f3
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
12 , makeWrapper
13 , pugixml, llvmPackages, SDL, Cocoa, CoreGraphics, ForceFeedback, OpenAL, OpenGL
14 , potrace
15 , openxr-loader
16 , embree, gmp, libharu
19 with lib;
20 let
21   python = python310Packages.python;
22   optix = fetchzip {
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";
26   };
29 stdenv.mkDerivation rec {
30   pname = "blender";
31   version = "3.3.1";
33   src = fetchurl {
34     url = "https://download.blender.org/source/${pname}-${version}.tar.xz";
35     hash = "sha256-KtpI8L+KDKgCuYfXV0UgEuH48krPTSNFOwnC1ZURjMo=";
36   };
38   patches = lib.optional stdenv.isDarwin ./darwin.patch;
40   nativeBuildInputs = [ cmake makeWrapper python310Packages.wrapPython llvmPackages.llvm.dev ]
41     ++ optionals cudaSupport [ addOpenGLRunpath ];
42   buildInputs =
43     [ boost ffmpeg gettext glew ilmbase
44       freetype libjpeg libpng libsamplerate libsndfile libtiff
45       opencolorio openexr openimagedenoise openimageio2 openjpeg python zlib zstd fftw jemalloc
46       alembic
47       (opensubdiv.override { inherit cudaSupport; })
48       tbb
49       embree
50       gmp
51       pugixml
52       potrace
53       libharu
54     ]
55     ++ (if (!stdenv.isDarwin) then [
56       libXi libX11 libXext libXrender
57       libGLU libGL openal
58       libXxf86vm
59       openxr-loader
60       # OpenVDB currently doesn't build on darwin
61       openvdb
62     ]
63     else [
64       llvmPackages.openmp SDL Cocoa CoreGraphics ForceFeedback OpenAL OpenGL
65     ])
66     ++ optional jackaudioSupport libjack2
67     ++ optional cudaSupport cudaPackages.cudatoolkit
68     ++ optional colladaSupport opencollada
69     ++ optional spaceNavSupport libspnav;
70   pythonPath = with python310Packages; [ numpy requests ];
72   postPatch = ''
73     # allow usage of dynamically linked embree
74     rm build_files/cmake/Modules/FindEmbree.cmake
75   '' +
76     (if stdenv.isDarwin then ''
77       : > build_files/cmake/platform/platform_apple_xcode.cmake
78       substituteInPlace source/creator/CMakeLists.txt \
79         --replace '${"$"}{LIBDIR}/python' \
80                   '${python}'
81       substituteInPlace build_files/cmake/platform/platform_apple.cmake \
82         --replace '${"$"}{LIBDIR}/python' \
83                   '${python}' \
84         --replace '${"$"}{LIBDIR}/opencollada' \
85                   '${opencollada}' \
86         --replace '${"$"}{PYTHON_LIBPATH}/site-packages/numpy' \
87                   '${python310Packages.numpy}/${python.sitePackages}/numpy'
88     '' else ''
89       substituteInPlace extern/clew/src/clew.c --replace '"libOpenCL.so"' '"${ocl-icd}/lib/libOpenCL.so"'
90     '') +
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"'
94     '' else "");
96   cmakeFlags =
97     [
98       "-DWITH_ALEMBIC=ON"
99       "-DWITH_MOD_OCEANSIM=ON"
100       "-DWITH_CODEC_FFMPEG=ON"
101       "-DWITH_CODEC_SNDFILE=ON"
102       "-DWITH_INSTALL_PORTABLE=OFF"
103       "-DWITH_FFTW3=ON"
104       "-DWITH_SDL=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"
116       "-DWITH_OPENVDB=ON"
117       "-DWITH_TBB=ON"
118       "-DWITH_IMAGE_OPENJPEG=ON"
119       "-DWITH_OPENCOLLADA=${if colladaSupport then "ON" else "OFF"}"
120     ]
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"
126     ]
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}"
134     ];
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";
142   blenderExecutable =
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
147   '' + ''
148     buildPythonPath "$pythonPath"
149     wrapProgram $blenderExecutable \
150       --prefix PATH : $program_PATH \
151       --prefix PYTHONPATH : "$program_PYTHONPATH" \
152       --add-flags '--python-use-system-env'
153   '';
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"
161     done
162   '';
164   meta = with lib; {
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 ];
173   };