2024-04-21 15:54:59 +00:00
{
Cocoa ,
CoreGraphics ,
ForceFeedback ,
OpenAL ,
OpenGL ,
SDL ,
addOpenGLRunpath ,
alembic ,
boost ,
callPackage ,
cmake ,
colladaSupport ? true ,
config ,
cudaPackages ,
cudaSupport ? config . cudaSupport ,
dbus ,
embree ,
fetchurl ,
fetchzip ,
ffmpeg ,
fftw ,
fftwFloat ,
freetype ,
gettext ,
glew ,
gmp ,
hipSupport ? false ,
jackaudioSupport ? false ,
jemalloc ,
lib ,
libGL ,
libGLU ,
libX11 ,
libXext ,
libXi ,
libXrender ,
libXxf86vm ,
libdecor ,
libepoxy ,
libffi ,
libharu ,
libjack2 ,
libjpeg ,
libpng ,
libsamplerate ,
libsndfile ,
libspnav ,
libtiff ,
libwebp ,
libxkbcommon ,
llvmPackages ,
makeWrapper ,
mesa ,
ocl-icd ,
openal ,
opencollada ,
opencolorio ,
openexr ,
openimagedenoise ,
openimageio ,
openjpeg ,
openpgl ,
opensubdiv ,
openvdb ,
openxr-loader ,
pkg-config ,
potrace ,
pugixml ,
python311Packages , # must use instead of python3.pkgs, see https://github.com/NixOS/nixpkgs/issues/211340
rocmPackages , # comes with a significantly larger closure size
runCommand ,
spaceNavSupport ? stdenv . isLinux ,
stdenv ,
tbb ,
wayland ,
wayland-protocols ,
waylandSupport ? stdenv . isLinux ,
zlib ,
zstd ,
2020-04-24 23:36:52 +00:00
} :
2021-01-09 10:05:03 +00:00
let
2024-04-21 15:54:59 +00:00
python3Packages = python311Packages ;
python3 = python3Packages . python ;
pyPkgsOpenusd = python3Packages . openusd . override { withOsl = false ; } ;
2024-01-02 11:29:13 +00:00
libdecor' = libdecor . overrideAttrs ( old : {
# Blender uses private APIs, need to patch to expose them
patches = ( old . patches or [ ] ) ++ [ ./libdecor.patch ] ;
} ) ;
2020-04-24 23:36:52 +00:00
2024-04-21 15:54:59 +00:00
optix = fetchzip {
# URL from https://gitlab.archlinux.org/archlinux/packaging/packages/blender/-/commit/333add667b43255dcb011215a2d2af48281e83cf#9b9baac1eb9b72790eef5540a1685306fc43fd6c_30_30
url = " h t t p s : / / d e v e l o p e r . d o w n l o a d . n v i d i a . c o m / r e d i s t / o p t i x / v 7 . 3 / O p t i X - 7 . 3 . 0 - I n c l u d e . z i p " ;
hash = " s h a 2 5 6 - a M r p 0 U f f 4 c 3 I C R n 4 S 6 z e d f 6 Q 4 M c 0 / d u B h K w K g Y g M X V U = " ;
} ;
2021-01-09 10:05:03 +00:00
in
2024-04-21 15:54:59 +00:00
stdenv . mkDerivation ( finalAttrs : {
2020-04-24 23:36:52 +00:00
pname = " b l e n d e r " ;
2024-04-21 15:54:59 +00:00
version = " 4 . 1 . 1 " ;
2020-04-24 23:36:52 +00:00
src = fetchurl {
2024-04-21 15:54:59 +00:00
url = " h t t p s : / / d o w n l o a d . b l e n d e r . o r g / s o u r c e / ${ finalAttrs . pname } - ${ finalAttrs . version } . t a r . x z " ;
hash = " s h a 2 5 6 - T 7 s 6 9 k 0 / h N 9 c c Q N 0 h F Q i b B i F w a w u 1 T c 9 D O o e g O g s C E g = " ;
2020-04-24 23:36:52 +00:00
} ;
2024-04-21 15:54:59 +00:00
patches = [ ./draco.patch ] ++ lib . optional stdenv . isDarwin ./darwin.patch ;
2020-04-24 23:36:52 +00:00
2024-04-21 15:54:59 +00:00
postPatch =
(
if stdenv . isDarwin then
''
: > build_files/cmake/platform/platform_apple_xcode.cmake
substituteInPlace source/creator/CMakeLists.txt \
- - replace ' $ { " $ " } { LIBDIR } /python ' \
' $ { python3 } '
substituteInPlace build_files/cmake/platform/platform_apple.cmake \
- - replace ' $ { " $ " } { LIBDIR } /python ' \
' $ { python3 } ' \
- - replace ' $ { " $ " } { LIBDIR } /opencollada ' \
' $ { opencollada } ' \
- - replace ' $ { " $ " } { PYTHON_LIBPATH } /site-packages/numpy ' \
' $ { python3Packages . numpy } / $ { python3 . sitePackages } /numpy '
''
else
''
substituteInPlace extern/clew/src/clew.c - - replace ' " l i b O p e n C L . s o " ' ' " ${ ocl-icd } / l i b / l i b O p e n C L . s o " '
''
)
+ ( lib . optionalString hipSupport ''
2023-10-19 13:55:26 +00:00
substituteInPlace extern/hipew/src/hipew.c - - replace ' " / o p t / r o c m / h i p / l i b / l i b a m d h i p 6 4 . s o " ' ' " ${ rocmPackages . clr } / l i b / l i b a m d h i p 6 4 . s o " '
substituteInPlace extern/hipew/src/hipew.c - - replace ' " o p t / r o c m / h i p / b i n " ' ' " ${ rocmPackages . clr } / b i n " '
2023-02-16 17:41:37 +00:00
'' ) ;
2020-04-24 23:36:52 +00:00
2024-04-21 15:54:59 +00:00
env . NIX_CFLAGS_COMPILE = " - I ${ python3 } / i n c l u d e / ${ python3 . libPrefix } " ;
2020-04-24 23:36:52 +00:00
cmakeFlags =
[
2024-04-21 15:54:59 +00:00
" - D P Y T H O N _ I N C L U D E _ D I R = ${ python3 } / i n c l u d e / ${ python3 . libPrefix } "
" - D P Y T H O N _ L I B P A T H = ${ python3 } / l i b "
" - D P Y T H O N _ L I B R A R Y = ${ python3 . libPrefix } "
" - D P Y T H O N _ N U M P Y _ I N C L U D E _ D I R S = ${ python3Packages . numpy } / ${ python3 . sitePackages } / n u m p y / c o r e / i n c l u d e "
" - D P Y T H O N _ N U M P Y _ P A T H = ${ python3Packages . numpy } / ${ python3 . sitePackages } "
" - D P Y T H O N _ V E R S I O N = ${ python3 . pythonVersion } "
2020-04-24 23:36:52 +00:00
" - D W I T H _ A L E M B I C = O N "
" - D W I T H _ C O D E C _ F F M P E G = O N "
" - D W I T H _ C O D E C _ S N D F I L E = O N "
" - D W I T H _ F F T W 3 = O N "
2024-04-21 15:54:59 +00:00
" - D W I T H _ I M A G E _ O P E N J P E G = O N "
" - D W I T H _ I N S T A L L _ P O R T A B L E = O F F "
" - D W I T H _ M O D _ O C E A N S I M = O N "
" - D W I T H _ O P E N C O L L A D A = ${ if colladaSupport then " O N " else " O F F " } "
2020-04-24 23:36:52 +00:00
" - D W I T H _ O P E N C O L O R I O = O N "
" - D W I T H _ O P E N S U B D I V = O N "
2024-04-21 15:54:59 +00:00
" - D W I T H _ O P E N V D B = O N "
2020-04-24 23:36:52 +00:00
" - D W I T H _ P Y T H O N _ I N S T A L L = O F F "
" - D W I T H _ P Y T H O N _ I N S T A L L _ N U M P Y = O F F "
2021-04-12 18:23:04 +00:00
" - D W I T H _ P Y T H O N _ I N S T A L L _ R E Q U E S T S = O F F "
2024-04-21 15:54:59 +00:00
" - D W I T H _ S D L = O F F "
2020-04-24 23:36:52 +00:00
" - D W I T H _ T B B = O N "
2024-04-21 15:54:59 +00:00
" - D W I T H _ U S D = O N "
# Blender supplies its own FindAlembic.cmake (incompatible with the Alembic-supplied config file)
" - D A L E M B I C _ I N C L U D E _ D I R = ${ lib . getDev alembic } / i n c l u d e "
" - D A L E M B I C _ L I B R A R Y = ${ lib . getLib alembic } / l i b / l i b A l e m b i c . s o "
2020-04-24 23:36:52 +00:00
]
2023-05-24 13:37:59 +00:00
++ lib . optionals waylandSupport [
" - D W I T H _ G H O S T _ W A Y L A N D = O N "
" - D W I T H _ G H O S T _ W A Y L A N D _ D B U S = O N "
" - D W I T H _ G H O S T _ W A Y L A N D _ D Y N L O A D = O F F "
" - D W I T H _ G H O S T _ W A Y L A N D _ L I B D E C O R = O N "
]
2024-04-21 15:54:59 +00:00
++ lib . optionals stdenv . hostPlatform . isAarch64 [ " - D W I T H _ C Y C L E S _ E M B R E E = O F F " ]
2023-02-02 18:25:31 +00:00
++ lib . optionals stdenv . isDarwin [
2024-04-21 15:54:59 +00:00
" - D L I B D I R = / d o e s - n o t - e x i s t "
2020-04-24 23:36:52 +00:00
" - D W I T H _ C Y C L E S _ O S L = O F F " # requires LLVM
" - D W I T H _ O P E N V D B = O F F " # OpenVDB currently doesn't build on darwin
]
2024-04-21 15:54:59 +00:00
++ lib . optional stdenv . cc . isClang " - D P Y T H O N _ L I N K F L A G S = " # Clang doesn't support "-export-dynamic"
2023-02-02 18:25:31 +00:00
++ lib . optional jackaudioSupport " - D W I T H _ J A C K = O N "
++ lib . optionals cudaSupport [
2024-04-21 15:54:59 +00:00
" - D O P T I X _ R O O T _ D I R = ${ optix } "
2021-01-09 10:05:03 +00:00
" - D W I T H _ C Y C L E S _ C U D A _ B I N A R I E S = O N "
" - D W I T H _ C Y C L E S _ D E V I C E _ O P T I X = O N "
] ;
2020-04-24 23:36:52 +00:00
2024-04-21 15:54:59 +00:00
nativeBuildInputs =
[
cmake
llvmPackages . llvm . dev
makeWrapper
python3Packages . wrapPython
]
++ lib . optionals cudaSupport [
addOpenGLRunpath
cudaPackages . cuda_nvcc
]
++ lib . optionals waylandSupport [ pkg-config ] ;
2020-04-24 23:36:52 +00:00
2024-04-21 15:54:59 +00:00
buildInputs =
[
alembic
boost
ffmpeg
fftw
fftwFloat
freetype
gettext
glew
gmp
jemalloc
libepoxy
libharu
libjpeg
libpng
libsamplerate
libsndfile
libtiff
libwebp
opencolorio
openexr
openimageio
openjpeg
openpgl
( opensubdiv . override { inherit cudaSupport ; } )
potrace
pugixml
pyPkgsOpenusd
python3
tbb
zlib
zstd
]
++ lib . optionals ( ! stdenv . isAarch64 ) [
embree
( openimagedenoise . override { inherit cudaSupport ; } )
]
++ (
if ( ! stdenv . isDarwin ) then
[
libGL
libGLU
libX11
libXext
libXi
libXrender
libXxf86vm
openal
openvdb # OpenVDB currently doesn't build on darwin
openxr-loader
]
else
[
Cocoa
CoreGraphics
ForceFeedback
OpenAL
OpenGL
SDL
llvmPackages . openmp
]
)
++ lib . optionals cudaSupport [ cudaPackages . cuda_cudart ]
++ lib . optionals waylandSupport [
dbus
libdecor'
libffi
libxkbcommon
wayland
wayland-protocols
]
++ lib . optional colladaSupport opencollada
++ lib . optional jackaudioSupport libjack2
++ lib . optional spaceNavSupport libspnav ;
pythonPath =
let
ps = python3Packages ;
in
[
ps . numpy
ps . requests
ps . zstandard
pyPkgsOpenusd
] ;
2020-04-24 23:36:52 +00:00
blenderExecutable =
2024-04-21 15:54:59 +00:00
placeholder " o u t "
+ ( if stdenv . isDarwin then " / A p p l i c a t i o n s / B l e n d e r . a p p / C o n t e n t s / M a c O S / B l e n d e r " else " / b i n / b l e n d e r " ) ;
postInstall =
lib . optionalString stdenv . isDarwin ''
mkdir $ out/Applications
mv $ out/Blender.app $ out/Applications
''
+ ''
mv $ out/share/blender / $ { lib . versions . majorMinor finalAttrs . version } /python { , - ext }
buildPythonPath " $ p y t h o n P a t h "
wrapProgram $ blenderExecutable \
- - prefix PATH : $ program_PATH \
- - prefix PYTHONPATH : " $ p r o g r a m _ P Y T H O N P A T H " \
- - add-flags ' - - python-use-system-env'
'' ;
2020-04-24 23:36:52 +00:00
# Set RUNPATH so that libcuda and libnvrtc in /run/opengl-driver(-32)/lib can be
# found. See the explanation in libglvnd.
2023-02-02 18:25:31 +00:00
postFixup = lib . optionalString cudaSupport ''
2020-04-24 23:36:52 +00:00
for program in $ out/bin/blender $ out/bin/.blender-wrapped ; do
isELF " $ p r o g r a m " || continue
addOpenGLRunpath " $ p r o g r a m "
done
'' ;
2023-10-09 19:29:22 +00:00
passthru = {
2024-04-21 15:54:59 +00:00
python = python3 ;
pythonPackages = python3Packages ;
2023-11-16 04:20:00 +00:00
2024-04-21 15:54:59 +00:00
withPackages =
f :
( callPackage ./wrapper.nix { } ) . override {
blender = finalAttrs . finalPackage ;
extraModules = ( f python3Packages ) ;
} ;
2023-10-09 19:29:22 +00:00
tests = {
2024-04-21 15:54:59 +00:00
render = runCommand " ${ finalAttrs . pname } - t e s t " { } ''
2023-10-09 19:29:22 +00:00
set - euo pipefail
export LIBGL_DRIVERS_PATH = $ { mesa . drivers } /lib/dri
export __EGL_VENDOR_LIBRARY_FILENAMES = $ { mesa . drivers } /share/glvnd/egl_vendor.d/50_mesa.json
cat < < ' PYTHON' > scene-config . py
import bpy
bpy . context . scene . eevee . taa_render_samples = 32
bpy . context . scene . cycles . samples = 32
if $ { if stdenv . isAarch64 then " T r u e " else " F a l s e " }:
bpy . context . scene . cycles . use_denoising = False
bpy . context . scene . render . resolution_x = 100
bpy . context . scene . render . resolution_y = 100
bpy . context . scene . render . threads_mode = ' FIXED'
bpy . context . scene . render . threads = 1
PYTHON
mkdir $ out
for engine in BLENDER_EEVEE CYCLES ; do
echo " R e n d e r i n g w i t h $ e n g i n e . . . "
# Beware that argument order matters
$ { finalAttrs . finalPackage } /bin/blender \
- - background \
- noaudio \
- - factory-startup \
- - python-exit-code 1 \
- - python scene-config . py \
- - engine " $ e n g i n e " \
- - render-output " $ o u t / $ e n g i n e " \
- - render-frame 1
done
'' ;
} ;
} ;
2023-05-24 13:37:59 +00:00
2024-04-21 15:54:59 +00:00
meta = {
2020-04-24 23:36:52 +00:00
description = " 3 D C r e a t i o n / A n i m a t i o n / P u b l i s h i n g S y s t e m " ;
homepage = " h t t p s : / / w w w . b l e n d e r . o r g " ;
# They comment two licenses: GPLv2 and Blender License, but they
# say: "We've decided to cancel the BL offering for an indefinite period."
2021-01-09 10:05:03 +00:00
# OptiX, enabled with cudaSupport, is non-free.
2024-04-21 15:54:59 +00:00
license = with lib . licenses ; [ gpl2Plus ] ++ lib . optional cudaSupport unfree ;
platforms = [
" a a r c h 6 4 - l i n u x "
" x 8 6 _ 6 4 - d a r w i n "
" x 8 6 _ 6 4 - l i n u x "
] ;
2023-05-24 13:37:59 +00:00
broken = stdenv . isDarwin ;
2024-04-21 15:54:59 +00:00
maintainers = with lib . maintainers ; [
goibhniu
veprbl
] ;
2023-08-04 22:07:22 +00:00
mainProgram = " b l e n d e r " ;
2020-04-24 23:36:52 +00:00
} ;
2023-10-09 19:29:22 +00:00
} )