2024-02-26 05:31:04 +00:00
{
Cocoa ,
CoreGraphics ,
ForceFeedback ,
OpenAL ,
OpenGL ,
SDL ,
2023-12-18 18:34:35 +00:00
addDriverRunpath ,
2024-02-26 05:31:04 +00:00
alembic ,
2024-06-26 00:29:42 +00:00
blender ,
2024-02-26 05:31:04 +00:00
boost ,
2024-04-28 21:48:53 +00:00
brotli ,
2024-02-26 05:31:04 +00:00
callPackage ,
cmake ,
colladaSupport ? true ,
config ,
2024-03-04 00:41:47 +00:00
cudaPackages ,
2024-02-26 05:31:04 +00:00
cudaSupport ? config . cudaSupport ,
dbus ,
embree ,
2024-07-12 10:59:59 +00:00
fetchgit ,
2024-02-26 05:31:04 +00:00
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 ,
openal ,
opencollada ,
opencolorio ,
openexr ,
openimagedenoise ,
openimageio ,
openjpeg ,
openpgl ,
opensubdiv ,
openvdb ,
openxr-loader ,
pkg-config ,
potrace ,
pugixml ,
2024-07-07 20:27:21 +00:00
python3Packages , # must use instead of python3.pkgs, see https://github.com/NixOS/nixpkgs/issues/211340
2024-02-26 05:31:04 +00:00
rocmPackages , # comes with a significantly larger closure size
runCommand ,
spaceNavSupport ? stdenv . isLinux ,
2024-04-28 21:48:53 +00:00
sse2neon ,
2024-02-26 05:31:04 +00:00
stdenv ,
tbb ,
wayland ,
wayland-protocols ,
2024-09-06 13:37:37 +00:00
wayland-scanner ,
2024-02-26 05:31:04 +00:00
waylandSupport ? stdenv . isLinux ,
zlib ,
zstd ,
2013-03-28 00:00:22 +00:00
} :
2010-05-08 21:25:56 +00:00
2020-12-14 08:41:47 +00:00
let
2024-09-13 16:23:37 +00:00
embreeSupport = ( ! stdenv . isAarch64 && stdenv . isLinux ) || stdenv . isDarwin ;
openImageDenoiseSupport = ( ! stdenv . isAarch64 && stdenv . isLinux ) || stdenv . isDarwin ;
openUsdSupport = ! stdenv . isDarwin ;
2024-03-05 13:42:30 +00:00
python3 = python3Packages . python ;
2024-02-28 23:59:50 +00:00
pyPkgsOpenusd = python3Packages . openusd . override { withOsl = false ; } ;
2024-02-26 05:31:04 +00:00
2023-11-18 01:45:35 +00:00
libdecor' = libdecor . overrideAttrs ( old : {
# Blender uses private APIs, need to patch to expose them
patches = ( old . patches or [ ] ) ++ [ ./libdecor.patch ] ;
} ) ;
2014-07-15 21:30:55 +00:00
2024-02-26 05:31:04 +00:00
optix = fetchzip {
2024-03-04 00:44:16 +00:00
# URL from https://gitlab.archlinux.org/archlinux/packaging/packages/blender/-/commit/333add667b43255dcb011215a2d2af48281e83cf#9b9baac1eb9b72790eef5540a1685306fc43fd6c_30_30
2024-02-26 05:31:04 +00:00
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 " ;
2024-03-04 00:44:16 +00:00
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 = " ;
2024-02-26 05:31:04 +00:00
} ;
2020-12-30 17:01:16 +00:00
in
2024-02-26 05:31:04 +00:00
2024-02-26 05:34:26 +00:00
stdenv . mkDerivation ( finalAttrs : {
2019-08-02 12:57:36 +00:00
pname = " b l e n d e r " ;
2024-08-22 15:38:34 +00:00
version = " 4 . 2 . 1 " ;
2007-12-01 18:05:26 +00:00
2024-07-12 10:59:59 +00:00
srcs = [
( fetchzip {
name = " s o u r c e " ;
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 / b l e n d e r - ${ finalAttrs . version } . t a r . x z " ;
2024-08-22 15:38:34 +00:00
hash = " s h a 2 5 6 - + Y 4 J b z e K + 3 0 f O 8 W d E m v j O e Q j m 0 9 4 o f s U h R F X s 9 m k c x I = " ;
2024-07-12 10:59:59 +00:00
} )
( fetchgit {
name = " a s s e t s " ;
url = " h t t p s : / / p r o j e c t s . b l e n d e r . o r g / b l e n d e r / b l e n d e r - a s s e t s . g i t " ;
rev = " 6 8 6 4 f 1 8 3 2 e 7 1 a 3 1 e 1 e 0 4 f 7 2 b b 7 a 5 a 1 f 5 3 f 0 c d 0 1 c " ;
fetchLFS = true ;
hash = " s h a 2 5 6 - v e p K 0 i n P M u l e A J B S i p w o I 9 9 n M B B i F a K / e S M H D e t E t j Y = " ;
2024-07-07 20:27:21 +00:00
} )
2024-07-12 10:59:59 +00:00
] ;
postUnpack = ''
chmod - R u + w *
rm - r assets/working
mv assets - - target-directory source/release/datafiles /
'' ;
sourceRoot = " s o u r c e " ;
patches = [ ./draco.patch ] ++ lib . optional stdenv . isDarwin ./darwin.patch ;
2020-01-08 01:42:02 +00:00
2024-02-26 05:31:04 +00:00
postPatch =
2024-07-12 10:59:59 +00:00
( lib . optionalString stdenv . isDarwin ''
: > build_files/cmake/platform/platform_apple_xcode.cmake
substituteInPlace source/creator/CMakeLists.txt \
- - replace-fail ' $ { " $ " } { LIBDIR } /python ' \
' $ { python3 } ' \
- - replace-fail ' $ { " $ " } { LIBDIR } /materialx / ' ' $ { python3Packages . materialx } / '
substituteInPlace build_files/cmake/platform/platform_apple.cmake \
- - replace-fail ' $ { " $ " } { LIBDIR } /brotli/lib/libbrotlicommon-static.a ' \
' $ { lib . getLib brotli } /lib/libbrotlicommon.dylib ' \
- - replace-fail ' $ { " $ " } { LIBDIR } /brotli/lib/libbrotlidec-static.a ' \
' $ { lib . getLib brotli } /lib/libbrotlidec.dylib '
'' )
2024-02-26 05:31:04 +00:00
+ ( lib . optionalString hipSupport ''
2023-10-05 21:58:02 +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-06 20:49:02 +00:00
'' ) ;
2014-07-15 20:52:23 +00:00
2024-03-05 13:42:30 +00:00
env . NIX_CFLAGS_COMPILE = " - I ${ python3 } / i n c l u d e / ${ python3 . libPrefix } " ;
2024-02-26 05:31:04 +00:00
2014-05-19 19:29:56 +00:00
cmakeFlags =
2020-02-15 11:39:27 +00:00
[
2024-09-06 13:53:23 +00:00
" - D M a t e r i a l X _ D I R = ${ python3Packages . materialx } / l i b / c m a k e / M a t e r i a l X "
2024-03-05 13:42:30 +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-02-23 11:10:53 +00:00
" - D W I T H _ A L E M B I C = O N "
2024-09-06 13:57:05 +00:00
" - D W I T H _ B U I L D I N F O = O F F "
2014-05-19 19:29:56 +00:00
" - 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 "
2024-09-06 13:57:05 +00:00
" - D W I T H _ C P U _ C H E C K = O F F "
" - D W I T H _ C Y C L E S _ D E V I C E _ O P T I X = ${ if cudaSupport then " O N " else " O F F " } "
" - D W I T H _ C Y C L E S _ O S L = O F F "
2015-01-09 15:57:38 +00:00
" - D W I T H _ F F T W 3 = O N "
2024-02-26 05:31:04 +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 "
2024-09-06 13:57:05 +00:00
" - D W I T H _ J A C K = ${ if jackaudioSupport then " O N " else " O F F " } "
" - D W I T H _ L I B S _ P R E C O M P I L E D = O F F "
2024-02-26 05:31:04 +00:00
" - 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 " } "
2015-01-09 15:57:38 +00:00
" - D W I T H _ O P E N C O L O R I O = O N "
2015-10-12 13:51:04 +00:00
" - D W I T H _ O P E N S U B D I V = O N "
2024-02-26 05:31:04 +00:00
" - D W I T H _ O P E N V D B = O N "
2024-09-06 13:57:05 +00:00
" - D W I T H _ P U L S E A U D I O = O F F "
2016-08-22 13:39:33 +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 02:12:40 +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-02-26 05:31:04 +00:00
" - D W I T H _ S D L = O F F "
2024-09-06 13:57:05 +00:00
" - D W I T H _ S T R I C T _ B U I L D _ O P T I O N S = O N "
2019-11-03 11:34:05 +00:00
" - D W I T H _ T B B = O N "
2024-02-28 23:59:50 +00:00
" - D W I T H _ U S D = O N "
2024-02-26 05:31:04 +00:00
# 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 "
2024-04-28 21:48:53 +00:00
" - 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 ${ stdenv . hostPlatform . extensions . sharedLibrary } "
2020-01-08 01:42:02 +00:00
]
2023-05-13 21:31:22 +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-09-13 16:23:37 +00:00
++ lib . optionals ( ! embreeSupport ) [
2024-07-07 20:28:43 +00:00
" - D W I T H _ C Y C L E S _ E M B R E E = O F F "
]
2023-01-24 16:29:20 +00:00
++ lib . optionals stdenv . isDarwin [
2024-02-26 05:31:04 +00:00
" - D L I B D I R = / d o e s - n o t - e x i s t "
2024-04-28 21:48:53 +00:00
" - D S S E 2 N E O N _ I N C L U D E _ D I R = ${ sse2neon } / l i b "
" - D W I T H _ U S D = O F F " # currently fails on darwin
2014-07-15 21:30:55 +00:00
]
2024-02-26 05:31:04 +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-01-24 16:29:20 +00:00
++ lib . optionals cudaSupport [
2024-02-26 05:31:04 +00:00
" - D O P T I X _ R O O T _ D I R = ${ optix } "
2020-12-15 18:10:38 +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 "
2020-12-14 08:41:47 +00:00
] ;
2008-05-14 13:39:20 +00:00
2024-07-11 14:02:00 +00:00
preConfigure = ''
(
expected_python_version = $ ( grep - E - - only-matching ' set \ ( _PYTHON_VERSION_SUPPORTED [ 0 -9 . ] + \ ) ' build_files/cmake/Modules/FindPythonLibsUnix.cmake | grep - E - - only-matching ' [ 0 -9 . ] + ' )
actual_python_version = $ ( python - c ' import sys ; print ( " . " . join ( map ( str , sys . version_info [ 0 : 2 ] ) ) ) ' )
if ! [ [ " $ a c t u a l _ p y t h o n _ v e r s i o n " = " $ e x p e c t e d _ p y t h o n _ v e r s i o n " ] ] ; then
echo " w r o n g P y t h o n v e r s i o n , e x p e c t e d ' $ e x p e c t e d _ p y t h o n _ v e r s i o n ' , g o t ' $ a c t u a l _ p y t h o n _ v e r s i o n ' " > & 2
exit 1
fi
)
'' ;
2024-02-26 05:31:04 +00:00
nativeBuildInputs =
[
cmake
llvmPackages . llvm . dev
makeWrapper
2024-03-05 13:42:30 +00:00
python3Packages . wrapPython
2024-02-26 05:31:04 +00:00
]
++ lib . optionals cudaSupport [
2023-12-18 18:34:35 +00:00
addDriverRunpath
2024-02-26 05:31:04 +00:00
cudaPackages . cuda_nvcc
]
2024-09-06 13:37:37 +00:00
++ lib . optionals waylandSupport [
pkg-config
wayland-scanner
] ;
2024-02-26 05:31:04 +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 ; } )
2024-04-28 21:48:53 +00:00
openvdb
2024-02-26 05:31:04 +00:00
potrace
pugixml
2024-03-05 13:42:30 +00:00
python3
2024-07-10 03:40:55 +00:00
python3Packages . materialx
2024-02-26 05:31:04 +00:00
tbb
zlib
zstd
]
2024-09-13 16:23:37 +00:00
++ lib . optional embreeSupport embree
++ lib . optional openImageDenoiseSupport ( openimagedenoise . override { inherit cudaSupport ; } )
2024-02-26 05:31:04 +00:00
++ (
if ( ! stdenv . isDarwin ) then
[
libGL
libGLU
libX11
libXext
libXi
libXrender
libXxf86vm
openal
openxr-loader
2024-04-28 21:48:53 +00:00
pyPkgsOpenusd
2024-02-26 05:31:04 +00:00
]
else
[
Cocoa
CoreGraphics
ForceFeedback
OpenAL
OpenGL
SDL
2024-04-28 21:48:53 +00:00
brotli
2024-02-26 05:31:04 +00:00
llvmPackages . openmp
2024-04-28 21:48:53 +00:00
sse2neon
2024-02-26 05:31:04 +00:00
]
)
++ 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 ;
2024-02-26 05:36:08 +00:00
pythonPath =
let
2024-03-05 13:42:30 +00:00
ps = python3Packages ;
2024-02-26 05:36:08 +00:00
in
[
2024-07-10 03:40:55 +00:00
ps . materialx
2024-02-26 05:36:08 +00:00
ps . numpy
ps . requests
ps . zstandard
2024-04-28 21:48:53 +00:00
]
2024-09-13 16:23:37 +00:00
++ lib . optional openUsdSupport [ pyPkgsOpenusd ] ;
2012-09-19 20:41:15 +00:00
2020-02-28 18:55:13 +00:00
blenderExecutable =
2024-02-26 05:31:04 +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
''
2024-04-28 21:48:53 +00:00
+ lib . optionalString stdenv . isLinux ''
2024-02-26 05:34:26 +00:00
mv $ out/share/blender / $ { lib . versions . majorMinor finalAttrs . version } /python { , - ext }
2024-04-28 21:48:53 +00:00
''
+ ''
2024-02-26 05:31:04 +00:00
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'
'' ;
2018-03-30 19:58:28 +00:00
2019-05-22 16:34:09 +00:00
# Set RUNPATH so that libcuda and libnvrtc in /run/opengl-driver(-32)/lib can be
# found. See the explanation in libglvnd.
2024-07-07 20:28:43 +00:00
postFixup =
lib . optionalString cudaSupport ''
for program in $ out/bin/blender $ out/bin/.blender-wrapped ; do
isELF " $ p r o g r a m " || continue
2024-07-10 23:06:18 +00:00
addDriverRunpath " $ p r o g r a m "
2024-07-07 20:28:43 +00:00
done
''
+ lib . optionalString stdenv . isDarwin ''
makeWrapper $ out/Applications/Blender.app/Contents/MacOS/Blender $ out/bin/blender
'' ;
2019-05-22 16:34:09 +00:00
2023-09-27 04:13:56 +00:00
passthru = {
2024-03-05 13:42:30 +00:00
python = python3 ;
pythonPackages = python3Packages ;
2023-10-30 03:39:27 +00:00
2024-02-26 05:31:04 +00:00
withPackages =
f :
2024-03-04 00:40:04 +00:00
( callPackage ./wrapper.nix { } ) . override {
2024-02-26 05:31:04 +00:00
blender = finalAttrs . finalPackage ;
2024-03-05 13:42:30 +00:00
extraModules = ( f python3Packages ) ;
2024-02-26 05:31:04 +00:00
} ;
2023-09-27 04:13:56 +00:00
tests = {
2024-07-07 20:28:43 +00:00
render = runCommand " ${ finalAttrs . pname } - t e s t " { nativeBuildInputs = [ mesa . llvmpipeHook ] ; } ''
2023-09-27 04:13:56 +00:00
set - euo pipefail
cat < < ' PYTHON' > scene-config . py
import bpy
bpy . context . scene . eevee . taa_render_samples = 32
bpy . context . scene . cycles . samples = 32
2024-04-28 21:48:53 +00:00
if $ { if ( stdenv . isAarch64 && stdenv . isLinux ) then " T r u e " else " F a l s e " }:
2023-09-27 04:13:56 +00:00
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
2024-07-12 10:59:59 +00:00
for engine in BLENDER_EEVEE_NEXT CYCLES ; do
2023-09-27 04:13:56 +00:00
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
2024-04-28 21:48:53 +00:00
$ { lib . getExe finalAttrs . finalPackage } \
2023-09-27 04:13:56 +00:00
- - 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
'' ;
2024-06-26 00:29:42 +00:00
tester-cudaAvailable = cudaPackages . writeGpuTestPython { } ''
import subprocess
subprocess . run ( [ $ {
lib . concatMapStringsSep " , " ( x : '' " ${ x } " '' ) [
( lib . getExe ( blender . override { cudaSupport = true ; } ) )
" - - b a c k g r o u n d "
" - n o a u d i o "
" - - p y t h o n - e x i t - c o d e "
" 1 "
" - - p y t h o n "
" ${ ./test-cuda.py } "
]
} ] , check = True ) # noqa: E501
'' ;
2023-09-27 04:13:56 +00:00
} ;
} ;
2023-05-22 21:06:34 +00:00
2024-02-26 05:36:08 +00:00
meta = {
2010-05-08 21:25:56 +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 " ;
2020-03-14 00:12:28 +00:00
homepage = " h t t p s : / / w w w . b l e n d e r . o r g " ;
2010-05-08 21:25:56 +00:00
# They comment two licenses: GPLv2 and Blender License, but they
# say: "We've decided to cancel the BL offering for an indefinite period."
2020-12-15 18:25:32 +00:00
# OptiX, enabled with cudaSupport, is non-free.
2024-07-07 20:28:43 +00:00
license =
with lib . licenses ;
[ gpl2Plus ] ++ lib . optional cudaSupport ( unfree // { shortName = " N V i d i a O p t i X E U L A " ; } ) ;
2024-06-26 00:29:42 +00:00
2024-02-26 05:31:04 +00:00
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 "
2024-04-28 21:48:53 +00:00
" a a r c h 6 4 - d a r w i n "
2024-02-26 05:31:04 +00:00
] ;
2024-09-13 16:22:27 +00:00
broken = stdenv . isDarwin ; # fails due to too-old SDK, using newer SDK fails to compile
2024-08-22 15:44:47 +00:00
maintainers = with lib . maintainers ; [
amarshall
veprbl
] ;
2023-08-04 19:10:05 +00:00
mainProgram = " b l e n d e r " ;
2010-05-08 21:25:56 +00:00
} ;
2023-09-27 04:13:56 +00:00
} )