Blender - different GPU behavior with and without sudo

hi all again,
I’ve installed blender (unsupported) in the configuration.nix file

environment.systemPackages = let
    unstable = import <nixos-unstable> { config = { allowUnfree = true; }; };
  in with pkgs; [ 
      (unstable.blender.override {
	cudaSupport = true;

then I open blender at it sees my Nivida GPU without problem.
The problem arise when I install LuxBlend addon (is an alternate render engine); if I run blender as user I get, in the addons settings, “GPU API, not available in this build” but if I start blender as root everything works as inteded and I can use the GPU to render without any problem.

How can I make blender have the same behavior when started as user?


Some of the kernel interfaces that GPU drivers use are protected.
Is your user part of the video and render group?

With declarative users:

users.users.<yourname>.extraGroups = [ "render" "video" ];

added, rebuilt and rebooted but nothing changed. Still everything works if blender is launched with sudo but not if started by the user.

Could you provide some more details for reproducing your error? What environment are you running Blender in (e.g. NixOS or else), how do you install LuxBlend, etc. E.g. you could attach the outputs of nix-shell -p nix-info --run "nix-info -m" and nvidia-smi in a <details></details> environment

You are perfectly right.
here the info request:

 - system: `"x86_64-linux"`
 - host os: `Linux 6.1.52, NixOS, 23.05 (Stoat), 23.05.3526.360a7d31c30a`
 - multi-user?: `yes`
 - sandbox: `yes`
 - version: `nix-env (Nix) 2.13.5`
 - channels(nemo): `""`
 - channels(root): `"nixos-23.05, nixos-unstable"`
 - nixpkgs: `/nix/var/nix/profiles/per-user/root/channels/nixos`

NixOs Stable, fresh install 3 days ago.

Sun Sep 17 18:22:46 2023       
| NVIDIA-SMI 535.86.05              Driver Version: 535.86.05    CUDA Version: 12.2     |
| GPU  Name                 Persistence-M | Bus-Id        Disp.A | Volatile Uncorr. ECC |
| Fan  Temp   Perf          Pwr:Usage/Cap |         Memory-Usage | GPU-Util  Compute M. |
|                                         |                      |               MIG M. |
|   0  NVIDIA GeForce GTX 1060 ...    Off | 00000000:01:00.0  On |                  N/A |
| N/A   46C    P8               6W /  60W |     21MiB /  6144MiB |      0%      Default |
|                                         |                      |                  N/A |
| Processes:                                                                            |
|  GPU   GI   CI        PID   Type   Process name                            GPU Memory |
|        ID   ID                                                             Usage      |
|    0   N/A  N/A      2073      G   ...84-gnome-shell-44.2/bin/gnome-shell        1MiB |

Blender installed from unstable with CUDA support in configuration.nix

environment.systemPackages = let
    unstable = import <nixos-unstable> { config = { allowUnfree = true; }; };
  in with pkgs; [ 
      (unstable.blender.override {
	cudaSupport = true;

LuxBlend addon downloaded from their github, beta build that works with 3.6.2 LTS blender (that’s why I need 3.6.2 blender from unstable), installed directly from blender.
Preference > addons > install

No error showed when installed or activated the addon, just that message in the addon menu and no GPU. Blender correctly detect my GTX 1060 if using cycles and LuxBlend work if setup for CPU usage, but that is not an option for me.

LuxBlend addon downloaded from their github

Are you referring to this? Releases · LuxCoreRender/BlendLuxCore · GitHub
If so, I see they’re shipping some prebuilt shared libraries (including vendored copies of nixpkgs’ cudaPackages.cuda_nvrtc) which likely need to be patchelf-ed or used with programs.nix-ld.enable = true:

❯ unzip -l  | rg .so'$'
  5456768  09-10-2023 14:22   BlendLuxCore/bin/
 22295304  09-10-2023 14:22   BlendLuxCore/bin/
 59825064  09-10-2023 14:54   BlendLuxCore/bin/

Does the add-on really work with CUDA on when you use sudo?

host os: `Linux 6.1.52, NixOS, 23.05 (Stoat)

Just to make sure then, hardware.opengl.enable = true?

   in with pkgs; [ 

This should be redundant

yes, that. 2.7beta1

sorry but I didn’t undestrand this part

yes, here my config

# Enable OpenGL
    hardware.opengl = {
    enable = true;
    driSupport = true;
    driSupport32Bit = true;

So I can remove it? I was under the impression that cuda was needed.

it seems so at least. Didn’t test it too much tho.

(blender.override { cudaSupport = true; }) is already linked to all the necessary cuda libraries; you add cudatoolkit when you compile new programs that use cuda

sorry but I didn’t undestrand this part

I suspect that the add-on is broken regardless of sudo, because it relies on some system libraries it wouldn’t be able to find on NixOS unless you explicitly exposed them or perhaps Blender had already loaded them. Seems like these also come prebuilt in the archive though:

Downloads/BlendLuxCore/bin via 🐍 v3.10.12
❯ patchelf --print-needed
❯ patchelf --print-rpath
❯ ls  oidnDenoise

Still, you might want to rebuild nixos with programs.nix-ld.enable = true and, for example, try running Blender from a nix-shell with mkShell { NIX_LD_LIBRARY_PATH = lib.makeSearchPath "lib" [ "/run/opengl-driver" cudaPackages_11.cuda_nvrtc ]; } (and you might need to experiment with adding embree openimagedenoise tbb to the list). This is only a concern when using a prebuilt add-on

1 Like

Mmm. Ok I’ll check and see if I was mistaken about it working with root privilege. Thanks for now.

sorry to bother, I’ve tried the command you posted but gives me this:

bash: syntax error near unexpected token `}'

I’m learning nix language but I still don’t understand why bash is complaining.

I just got around to try and reproduce your error. I ran bin/blender built from the (blender.override { cudaSupport = true; }) expression, installed the through settings -> addons -> install (logs: “pyluxcore successfully registered”), setup “LuxCoreRender” as the “Render Engine” for the default cube scene, and finally ran rendering with F12. As expected, this fails with an error related to libnvrtc:

[LuxRays][64.573] [BVHKernel] CUDA program compilation error:
nvrtc: error: failed to open
  Make sure that is installed correctly.
Traceback (most recent call last):
  File "/home/ss/.config/blender/3.6/scripts/addons/BlendLuxCore/engine/", line 91, in render_final
    final.render(self, depsgraph)
  File "/home/ss/.config/blender/3.6/scripts/addons/BlendLuxCore/engine/", line 44, in render
    _render_layer(engine, depsgraph, statistics, layer)
  File "/home/ss/.config/blender/3.6/scripts/addons/BlendLuxCore/engine/", line 56, in _render_layer
    engine.session = engine.exporter.create_session(depsgraph, engine=engine, view_layer=view_layer)
  File "/home/ss/.config/blender/3.6/scripts/addons/BlendLuxCore/export/", line 217, in create_session
RuntimeError: BVHKernel CUDA program compilation error
ERROR: BVHKernel CUDA program compilation error
Info: Compiling CUDA kernels (just once, usually takes 15-30 minutes)
Error: BVHKernel CUDA program compilation error

I then created a shell.nix file as described above and:

$ cat > shell.nix << EOF
with import <nixpkgs> { config.allowUnfree = true; };
mkShell {
  NIX_LD_LIBRARY_PATH = lib.makeSearchPath "lib" [
$ nix-shell shell.nix # enter the environment where NIX_LD_LIBRARY_PATH is set up
$ echo $NIX_LD_LIBRARY_PATH # takes priority over shipped with BlendLuxCore
$ ls -l /lib64/ # note I'm using NixOS with programs.nix-ld.enable = true:
lrwxrwxrwx 1 root root 71 Sep 15 20:46 /lib64/ -> /nix/store/386r5hy238s7djbpdpijxlj2f8kfz7cw-nix-ld-1.2.2/libexec/nix-ld
$ blender
[LuxRays][7.968] OpenCL support: enabled
[LuxRays][7.971] CUDA support: enabled
[LuxCore][20.624] Noise estimation: first pass
[LuxCore][32.515] Noise estimation: Error mean = 0.00170071
[LuxCore][50.613] Noise estimation: Error mean = 0.000993632
[LuxCore][70.259] Noise estimation: Error mean = 0.000427202
1 Like

Alternatively, instead of nix-shell environments you could also just set a default NIX_LD_LIBRARY_PATH globally in your NixOS configuration.nix, e.g. in environment.variables.NIX_LD_LIBRARY_PATH = pkgs.lib.makeSearchPath "lib" [ ... ], albeit this may be more fragile

P.S. Uhm, sorry I’m just dumping more and more text, it’s probably too much to consume at once and more than was needed to solve the problem

1 Like