Blender: Difference between revisions

Smudgebun (talk | contribs)
m HIP: fixed package name
Smudgebun (talk | contribs)
m UI is dim on Vulkan backend and KDE Plasma: Updated known affected versions
 
(13 intermediate revisions by the same user not shown)
Line 2: Line 2:
[https://www.blender.org/ Blender] is an open-source 3D suite for modelling, animation, VFX, and more.
[https://www.blender.org/ Blender] is an open-source 3D suite for modelling, animation, VFX, and more.


The default <code>blender</code> nix package is compiled without support for any compute APIs (CUDA, OptiX, oneAPI, HIP). If you want to install Blender with support for compute APIs, see: [[#Advanced Installation]]  
The default <code>blender</code> nix package is compiled without support for any compute APIs (CUDA, OptiX, oneAPI, HIP), and can be installed with the following in your configuration.
 
<syntaxhighlight lang="nix">
environment.systemPackages = with pkgs; [
  blender
];
</syntaxhighlight>
 
If you want to install Blender with support for compute APIs, see: [[#Advanced Installation]]
 
== Configuration ==
=== Installing With Additional Python Packages ===
To install additional Python modules into Blender, use the <code>withPackages</code> attribute.
 
Example using a normal Blender package:
 
<syntaxhighlight lang="nix">
environment.systemPackages = with pkgs; [
  (blender.withPackages(ps: [ ps.pyserial ps.fs ])
];
</syntaxhighlight>
 
Examples using abnormal Blender Packages:
<syntaxhighlight lang="nix">
let
  blender-cuda = blender.override {config.cudaSupport=true;};
in {
 
  environment.systemPackages = with pkgs; [
    (blender-cuda.withPackages(ps: [ ps.yq ])
#  (pkgsRocm.blender.withPackages(ps: [ ps.pyserial ps.fs ])
  ];
}
</syntaxhighlight>
 
In these functions, <code>ps</code> is an alias for <code>python313Packages</code>.
 
Installing with additional packages will result in a binary named <code>blender-wrapped</code> as it adds the python modules by wrapping Blender in a custom Python environment. When using a binary or unofficial Blender nix package, support for this feature will vary depending on if and how the packager implemented it.
 
A workaround if using a package that doesn't support <code>withPackages</code> is to install the python packages globally.
 
<syntaxhighlight lang="nix">
environment.systemPackages = with pkgs; [
  python313Packages.yq
  python313Packages.pyserial
];
</syntaxhighlight>
 
Or if it fits your use case better, you can install them in a nix-shell and run Blender from within that shell.
 
{{file|shell.nix|nix|
<nowiki>
let
  nixpkgs = fetchTarball "https://github.com/NixOS/nixpkgs/tarball/nixos-25.11";
  pkgs = import nixpkgs { config = {}; overlays = []; };
in
 
pkgs.mkShellNoCC {
  packages = with pkgs; [
    python313Packages.yq
    python313Packages.fs
#    Optionally you can declare the Blender package you want to use in the shell, so you can run the shell in --pure.
#    Can be useful if you're trying to make a reproducible development shell or similar.
    pkgsRocm.blender
  ];
 
}
</nowiki>
}}


== Tips & Tricks ==
== Tips & Tricks ==


=== Blendfarm ===
=== Blendfarm ===
The Blendfarm Network Renderer for Blender is provided by [https://github.com/NixOS/nixpkgs/blob/master/nixos/modules/services/misc/blenderfarm.nix services.blendfarm]. A very simple example configuration is shown below.
The Blendfarm network renderer for Blender is handled by {{nixos:option|services.blendfarm}}. A very simple example configuration is shown below.


{{file|configuration.nix|nix|
{{file|configuration.nix|nix|
Line 30: Line 98:
These are alternative distribution methods that package the Blender binaries, meaning they have support for all APIs.
These are alternative distribution methods that package the Blender binaries, meaning they have support for all APIs.
==== Steam ====
==== Steam ====
Launching [https://store.steampowered.com/app/365670/Blender/ Blender through Steam] will run Linux native Blender in the Steam Runtime environment, and will receive automatic updates. If you force Steam to run the Windows version (through Proton) by selecting "Force the use of a specific Steam Play compatibility tool" under Properties > Compatibility, the APIs will fail as they will not have the relevant Windows drivers.
Installing [https://store.steampowered.com/app/365670/Blender/ Blender through Steam] will run Linux native Blender in the Steam Runtime environment, and it will receive automatic updates through Steam. Note that if you make Steam run the Windows version (through Proton) by selecting "Force the use of a specific Steam Play compatibility tool" under Properties > Compatibility, the APIs will fail as they will not have the relevant Windows drivers.


==== The blender-bin Flake ====
==== The blender-bin Flake ====
Line 68: Line 136:


==== The cudaSupport Flag ====
==== The cudaSupport Flag ====
Whether a compatible package is built with CUDA support is managed by the <code>cudaSupport</code> flag enabled. This can either be done with a global flag
Whether a compatible package is built with CUDA support is managed by the <code>cudaSupport</code> flag enabled.


<syntaxhighlight lang="nix"> nixpkgs.config.cudaSupport = true; </syntaxhighlight>
The following example shows how to override specifically the Blender package for CUDA support, for general information on the topic see: [[CUDA#Enabling CUDA In Packages|Enabling CUDA In Packages]].
 
Or by overriding specifically the Blender package.


<syntaxhighlight lang="nix">
<syntaxhighlight lang="nix">
environment.systemPackages = [
environment.systemPackages = with pkgs; [
   (blender.override {config.cudaSupport=true;})
   (blender.override {config.cudaSupport=true;})
/* (blender.override {
    config.cudaSupport=true;
    config.rocmSupport=true;}) # to compile blender with both HIP and CUDA/OptiX support */
];
];
</syntaxhighlight>
</syntaxhighlight>


It's important to note that any package installed with the <code>cudaSupport</code> flag enabled that is CUDA-compatible will be compiled from source, as Hydra does not build (and therefore cache.nixos.org does not cache) with CUDA support enabled. With larger programs like Blender this can be very resource-intensive, so it is recommended to limit the number of cores or jobs that the process will take with the <code>--max-jobs</code> / <code>-j</code> and <code>--cores</code> flags when calling for example <code>nix-shell</code> or <code>nixos-rebuild</code>. This is also why it is recommended to only enable <code>cudaSupport</code> for the programs you need it for.
If installing Blender with <code>cudaSupport</code>, it is highly recommended you set up the [[CUDA#Setting up CUDA Binary Cache|CUDA Binary Cache]]. If you do not have it set up, and install Blender with <code>cudaSupport</code>, your machine will be compiling Blender from source.  
 
Compiling Blender is very resource-intensive, so if you are unable to use the CUDA Cache, please see the associated warning and information in [[CUDA#Enabling CUDA In Packages]].


==== Community Flakes ====
==== Community Flakes ====
In addition to the [[#The blender-bin Flake|#blender-bin flake]], there is also [https://github.com/adithyagenie/blender-cuda-nixos blender-cuda-nixos], which compiles Blender with <code>cudaSupport</code> enabled and caches it on cachix so you don't need to build it yourself. For instructions on adding it to your configuration, see its [https://github.com/adithyagenie/blender-cuda-nixos/blob/master/README.md README].
In addition to the [[#The blender-bin Flake|#blender-bin flake]], there is also [https://github.com/adithyagenie/blender-cuda-nixos blender-cuda-nixos], which compiles Blender with <code>cudaSupport</code> enabled and caches it on cachix so you don't need to build it yourself. For the most up-to-date instructions on adding it to your configuration, see its [https://github.com/adithyagenie/blender-cuda-nixos/blob/master/README.md README].


=== HIP ===
=== HIP ===
With the deprecation of the <code>blender-hip</code> package,<ref name="deprecate-hip"> {{pull|463064}}</ref> the easiest way to add Blender with HIP support is now with the <code>pkgsRocm.blender</code> package. Other methods are to use the <code>rocmSupport</code> flag the same way as [[#The cudaSupport Flag|#The cudaSupport Flag]], or to use a [[#Binary Packages|#Binary Package]].
With the deprecation of the <code>blender-hip</code> package,<ref name="deprecate-hip"> {{pull|463064}}</ref> the easiest way to add Blender with HIP support is now with the <code>pkgsRocm.blender</code> package. Other methods are to use the <code>rocmSupport</code> config variable, or to use a [[#Binary Packages|#Binary Package]].
 
The below example is Blender-specific. For more general information on enabling ROCm/HIP in your configuration, see: [[AMD GPU#Enabling  ROCm & HIP For Packages]].
 
<syntaxhighlight lang="nix">
environment.systemPackages = with pkgs; [
 
  pkgsRocm.blender


Unlike <code>cudaSupport</code>, most if not all packages with <code>rocmSuppport</code> are built by Hydra and cached into cache.nixos.org. That said, it is still recommended to enable <code>rocmSupport</code> only as much as you will need it, to avoid that chance of unnecessary recompilation on your machine.
/* (blender.override {
    config.rocmSupport=true;
    config.cudaSupport=false;}) # (equivalent to `pkgsRocm.blender`) */
 
/* (blender.override {
    config.cudaSupport=true;
    config.rocmSupport=true;}) # to compile blender with both HIP and CUDA/OptiX support */
];
</syntaxhighlight>


=== oneAPI ===
=== oneAPI ===
Currently, Nixpkgs has extremely limited oneAPI support, (see: {{issue|367722|oneAPI Tracking}}), which is explicitly blocking oneAPI integration into the Blender package (see: {{issue|447245|Blender oneAPI Support}}). As such, the current only way to have oneAPI support on NixOS is through one of the [[#Binary Packages|#Binary Packages]]
Currently, Nixpkgs has extremely limited oneAPI support (see: {{issue|367722|<nowiki>[Tracking] OneAPI Packages</nowiki>}}), which is explicitly blocking {{issue|447245|Blender oneAPI Support}}. As such, the current only way to have oneAPI support on NixOS is through one of the [[#Binary Packages|#Binary Packages]].


=== Last Resorts ===
=== Last Resorts ===
Line 100: Line 187:
=== UI is dim on Vulkan backend and KDE Plasma ===
=== UI is dim on Vulkan backend and KDE Plasma ===


This is a cross-distro issue on current KDE Plasma (Wayland Session, KDE Version 6.6.3) and NVIDIA drivers (Versions 595.XX). A workaround option that doesn't require downgrading is to force XWayland by running Blender with the following command. See more information at the related {{issue|link=https://projects.blender.org/blender/blender/issues/155467||issue}} on Blender's repo.
This is a cross-distro issue on current KDE Plasma with NVIDIA, (confirmed issue on KDE Version 6.6.2-6.6.4 Wayland Session with NVIDIA drivers Versions 595.XX, though may affect others too). A workaround option that doesn't require downgrading is to force XWayland by running Blender with the following command. See more information at the related {{issue|link=https://projects.blender.org/blender/blender/issues/155467||issue}} on Blender's repo.
<syntaxhighlight lang="sh">
<syntaxhighlight lang="sh">
WAYLAND_DISPLAY=0 blender
WAYLAND_DISPLAY=0 blender
</syntaxhighlight>
</syntaxhighlight>


== References ==
== References ==
<references />
<references />