Need CUDA-enabled latest Blender on nixOS-stable

revised for clarity after post rename:

Let me not XY problem this: my desired combination is nixos-stable + the latest official blender release, with CUDA. I don’t really want bleeding edge anything. I need the latest Blender release available, but not at the cost of having my entire system on nixos-unstable. If this isn’t going to be doable, or is overly complicated for my level of nixpertise, my only choice might be to not use nixOS anymore, which would be very frustrating because my configuration is solid and reliable and works, but I am an artist and any number of days I can’t use Blender is actual work time on projects lost.

PS running the official blender linux binary doesn’t work for me on nixOS, I know those kinds of binaries aren’t supported on nixOS, but I’ve read the wiki for dealing with that, to try and get it to launch, and don’t have the wherewithal to hunt and peck at the micro-issues that pop up in that process either, like not finding the shared libraries and everything else I know nothing about.

Version 4.5.3 is available in nixos-unstable: NixOS Search

I don’t know the best way to mix stable & unstable. You can probably search and find a lot of opinions (including that it’s not officially supported) on how to do that.

Hello,

I tried that yesterday and it was downloading Blender 2.93. Somebody told me to pin a specific tarball which worked, I have 4.5.3 on my system, but that doesn’t help because the build doesn’t have CUDA enabled.

Thank you

So your issue is that you want to use an unstable package on stable and you’re using nix run to work around this by grabbing a specific package from unstable?

How does that even work given your nixpkgs registry entry should be the same as your system flake’s nixpkgs input?

Anyway, grabbing the package from unstable is pretty easy. Just add a new flake input for unstable and use that:

# flake.nix
{
  inputs = {
    nixpkgs.url = "https://channels.nixos.org/nixos-25.05/nixexprs.tar.xz";
    nixpkgsUnstable.url = "https://channels.nixos.org/nixos-unstable/nixexprs.tar.xz";
  };

  outputs = { nixpkgs, ... } @ inputs: {
    nixosConfigurations."<yourHostname>" = nixpkgs.lib.nixosSystem {
        system = "<yourSystem>";
        modules = [
          ./configuration.nix
        ];

        specialArgs.flakeInputs = inputs;
    };
  };
}
# configuration.nix
{ pkgs, flakeInputs, ... }: {
  environment.systemPackages = [
    (flakeInputs.nixpkgsUnstable.legacyPackages.${pkgs.system}.blender.override {
      cudaSupport = true;
    })
  ];
}

YMMV in practice, I don’t know how CUDA interacts with all of this exactly.

Edit: Ah, your issue is that config doesn’t propagate to another nixpkgs instance. I added the override manually for you.

I’m trying to incorporate what you did. I moved the 1st block into a file called flake.nix I created in /etc/nixos and then incorporated the changes to the configuration as outlined and tried to nixos rebuild switch and I got an error:

error: flake ‘path:/etc/nixos’ does not provide attribute ‘packages.x86_64-linux.nixosConfigurations.“nixos”.config.system.build.nixos-rebuild’, ‘legacyPackages.x86_64-linux.nixosConfigurations.“nixos”.config.system.build.nixos-rebuild’ or ‘nixosConfigurations.“nixos”.config.system.build.nixos-rebuild’
➜ nixos

Blockquote

No, blender-bin works fine but I don’t know how to make it persistent

What is the command you used to rebuild your system?

Please use triple back quotes when copy pasting console commands and/or terminal logs, it’s easier to read.

1 Like

Right, you mean you didn’t have a flake.nix before then, I assume. You using nix run threw me off, given that that’s from the 3.0 CLI. That also explains why nix run even works since your system doesn’t have a flake input to use for the registry so it defaults to unstable, though I still wonder how you get cuda support this way.

I’d really recommend using nix-shell instead of nix run with your setup.

Anyway, in that case you’re most likely using channels, but probably best to first confirm that as @drupol asks.

If you are using channels, remove the flake.nix again, and instead start by adding a new channel system-wide in your terminal:

$ nix-channel --add https://nixos.org/channels/nixos-unstable nixos-unstable

Then import it and grab the package from there in your configuration.nix:

# configuration.nix
{ ... }: let
  unstablePkgs = import <nixos-unstable> { };
in {
  environment.systemPackages = [
    (unstabkePkgs.blender.override { cudaSupport = true; })
  ];
}

Hello, yes I’m using channels. I’ve removed all flake.nix stuff and tried your latest method.

Is that unstable channel meant to be added as root or regular user? Anyway, I added it as both sudo and regular user, following error now occurs when I run sudo nixos-rebuild switch.

[sudo] password for nixed: 
building Nix...
building the system configuration...
error:
       … while calling the 'head' builtin
         at /nix/store/a7aqxhmxwyximn46rqw9n5443yxnpsy5-nixos-25.05/nixos/lib/attrsets.nix:1571:13:
         1570|           if length values == 1 || pred here (elemAt values 1) (head values) then
         1571|             head values
             |             ^
         1572|           else

       … while evaluating the attribute 'value'
         at /nix/store/a7aqxhmxwyximn46rqw9n5443yxnpsy5-nixos-25.05/nixos/lib/modules.nix:1083:7:
         1082|     // {
         1083|       value = addErrorContext "while evaluating the option `${showOption loc}':" value;
             |       ^
         1084|       inherit (res.defsFinal') highestPrio;

       … while evaluating the option `system.build.toplevel':

       … while evaluating definitions from `/nix/store/a7aqxhmxwyximn46rqw9n5443yxnpsy5-nixos-25.05/nixos/nixos/modules/system/activation/top-level.nix':

       … while evaluating the option `system.systemBuilderArgs':

       … while evaluating definitions from `/nix/store/a7aqxhmxwyximn46rqw9n5443yxnpsy5-nixos-25.05/nixos/nixos/modules/system/activation/activatable-system.nix':

       … while evaluating the option `system.activationScripts.etc.text':

       … while evaluating definitions from `/nix/store/a7aqxhmxwyximn46rqw9n5443yxnpsy5-nixos-25.05/nixos/nixos/modules/system/etc/etc-activation.nix':

       … while evaluating definitions from `/nix/store/a7aqxhmxwyximn46rqw9n5443yxnpsy5-nixos-25.05/nixos/nixos/modules/system/etc/etc.nix':

       … while evaluating the option `environment.etc.dbus-1.source':

       … while evaluating the option `environment.systemPackages':

       … while evaluating definitions from `/etc/nixos/configuration.nix':

       (stack trace truncated; use '--show-trace' to show the full, detailed trace)

       error: file 'nixos-unstable' was not found in the Nix search path (add it using $NIX_PATH or -I)

The command I shared, nix run blender-bin was a random command I found on google and was the only thing that has yet allowed me to run Blender 4.5.3 recognizing my GPU. To clarify, I am just getting set up with Nvidia now, my problem is caused by my projects being already saved in Blender 4.5.3 format combined with my refusal to switch the main system channel to unstable, compacted by a coincidental switch to an Nvidia laptop.

If my system were on unstable, all I would need is the cuda override on the nixpkgs blender package but I don’t want to switch my main system to unstable.

Flakes are frustrating solutions because I have bad luck getting them working and don’t know how to properly implement them, on top of not needing flakes for anything else in my current config which has matured to cover everything I need and will ever need, after 3 years of using nix OS.

When you use nix run you’re using a flake :wink: I’m surprised that works since that particular nixpkgs shouldn’t have the cudaSupport override.

Hm, can you share the output of sudo nix-channel --list, and maybe run a sudo nix-channel --update?

Also, yeah, it’s supposed to be in the root user’s channels, I’d recommend deleting the non-root user channel so you don’t leave an outdated channel lying around accidentally.

Ok, I think we are getting somewhere. I missed updating the channels. Now my errors are as follows:

I have unfree enabled in my overall configuration but afaik this has to be overridden somehow.

building Nix...
building the system configuration...
error:
       … while calling the 'head' builtin
         at /nix/store/9iswvhwdhwri7ng3qrqjy5ppw710gpd4-nixos-25.05/nixos/lib/attrsets.nix:1571:13:
         1570|           if length values == 1 || pred here (elemAt values 1) (head values) then
         1571|             head values
             |             ^
         1572|           else

       … while evaluating the attribute 'value'
         at /nix/store/9iswvhwdhwri7ng3qrqjy5ppw710gpd4-nixos-25.05/nixos/lib/modules.nix:1083:7:
         1082|     // {
         1083|       value = addErrorContext "while evaluating the option `${showOption loc}':" value;
             |       ^
         1084|       inherit (res.defsFinal') highestPrio;

       … while evaluating the option `system.build.toplevel':

       … while evaluating definitions from `/nix/store/9iswvhwdhwri7ng3qrqjy5ppw710gpd4-nixos-25.05/nixos/nixos/modules/system/activation/top-level.nix':

       … while evaluating the option `system.systemBuilderArgs':

       … while evaluating definitions from `/nix/store/9iswvhwdhwri7ng3qrqjy5ppw710gpd4-nixos-25.05/nixos/nixos/modules/system/activation/activatable-system.nix':

       … while evaluating the option `system.activationScripts.etc.text':

       … while evaluating definitions from `/nix/store/9iswvhwdhwri7ng3qrqjy5ppw710gpd4-nixos-25.05/nixos/nixos/modules/system/etc/etc-activation.nix':

       … while evaluating definitions from `/nix/store/9iswvhwdhwri7ng3qrqjy5ppw710gpd4-nixos-25.05/nixos/nixos/modules/system/etc/etc.nix':

       … while evaluating the option `environment.etc.dbus-1.source':

       (stack trace truncated; use '--show-trace' to show the full, detailed trace)

       error: Package ‘blender-4.5.3’ in /nix/store/i5xyfsln5yd2w48lj9d1w8nbp81n9whl-nixos-unstable/nixos-unstable/pkgs/by-name/bl/blender/package.nix:432 has an unfree license (‘gpl2Plus NVidia OptiX EULA’), refusing to evaluate.

       a) To temporarily allow unfree packages, you can use an environment variable
          for a single invocation of the nix tools.

            $ export NIXPKGS_ALLOW_UNFREE=1

          Note: When using `nix shell`, `nix build`, `nix develop`, etc with a flake,
                then pass `--impure` in order to allow use of environment variables.

       b) For `nixos-rebuild` you can set
         { nixpkgs.config.allowUnfree = true; }
       in configuration.nix to override this.

       Alternatively you can configure a predicate to allow specific packages:
         { nixpkgs.config.allowUnfreePredicate = pkg: builtins.elem (lib.getName pkg) [
             "blender"
           ];
         }

       c) For `nix-env`, `nix-build`, `nix-shell` or any other Nix command you can add
         { allowUnfree = true; }
       to ~/.config/nixpkgs/config.nix.

Read the error message, I’ve formatted it for clarity:

This is because you’ve enabled CUDA support, which makes blender contain nonfree components.

… wait, no, the problem is the usual second nixpkgs instance doesn’t inherit config. So, replace this:

with:

unstablePkgs = import <nixos-unstable> {
  config.allowUnfree = true;
};

… or of course the allowUnfreePredicate equivalent.

If you want to, i believe you can also do this:

# configuration.nix
{ unstablePkgs, ... }: {
  _module.args = {
    unstablePkgs = import <nixos-unstable> {
      config.allowUnfree = true;
    };
  };

  environment.systemPackages = [
    (unstabkePkgs.blender.override { cudaSupport = true; })
  ];
}

Then if you have other modules besides configuration.nix where you want to use unstablePkgs you don’t need to import or configure unstable again; just put it in the module args and the one defined here will be reused.

This might cause infinite recursion, though, I’m not sure. If it does, I’d only start using that trick when i actually have a second module, and start using configuration.nix as an entrypoint and not actually define any configuration in there. But maybe I’m taking a few too many steps for you here.

I can read the error message. The problem is that I already have allowUnfree enabled in my configuration. I can’t enable it twice because the build complains I have already declared it.

Presumably I couldn’t have NVIDIA drivers installed had I not done that?

error:
       … while evaluating the attribute 'config'
         at /nix/store/9iswvhwdhwri7ng3qrqjy5ppw710gpd4-nixos-25.05/nixos/lib/modules.nix:359:9:
          358|         options = checked options;
          359|         config = checked (removeAttrs config [ "_module" ]);
             |         ^
          360|         _module = checked (config._module);

       … while calling the 'seq' builtin
         at /nix/store/9iswvhwdhwri7ng3qrqjy5ppw710gpd4-nixos-25.05/nixos/lib/modules.nix:359:18:
          358|         options = checked options;
          359|         config = checked (removeAttrs config [ "_module" ]);
             |                  ^
          360|         _module = checked (config._module);

       (stack trace truncated; use '--show-trace' to show the full, detailed trace)

       error: attribute 'nixpkgs.config.allowUnfree' already defined at /etc/nixos/configuration.nix:21:1
       at /etc/nixos/configuration.nix:380:3:
          379|   # Allow unfree packages
          380|   nixpkgs.config.allowUnfree = true;
             |   ^
          381|
building Nix...
error:
       … while evaluating the attribute 'config'
         at /nix/store/9iswvhwdhwri7ng3qrqjy5ppw710gpd4-nixos-25.05/nixos/lib/modules.nix:359:9:
          358|         options = checked options;
          359|         config = checked (removeAttrs config [ "_module" ]);
             |         ^
          360|         _module = checked (config._module);

       … while calling the 'seq' builtin
         at /nix/store/9iswvhwdhwri7ng3qrqjy5ppw710gpd4-nixos-25.05/nixos/lib/modules.nix:359:18:
          358|         options = checked options;
          359|         config = checked (removeAttrs config [ "_module" ]);
             |                  ^
          360|         _module = checked (config._module);

       (stack trace truncated; use '--show-trace' to show the full, detailed trace)

       error: attribute 'nixpkgs.config.allowUnfree' already defined at /etc/nixos/configuration.nix:21:1
       at /etc/nixos/configuration.nix:380:3:
          379|   # Allow unfree packages
          380|   nixpkgs.config.allowUnfree = true;
             |   ^
          381|
building the system configuration...
error:
       … while evaluating the attribute 'config.system.build.toplevel'
         at /nix/store/9iswvhwdhwri7ng3qrqjy5ppw710gpd4-nixos-25.05/nixos/lib/modules.nix:359:9:
          358|         options = checked options;
          359|         config = checked (removeAttrs config [ "_module" ]);
             |         ^
          360|         _module = checked (config._module);

       … while calling the 'seq' builtin
         at /nix/store/9iswvhwdhwri7ng3qrqjy5ppw710gpd4-nixos-25.05/nixos/lib/modules.nix:359:18:
          358|         options = checked options;
          359|         config = checked (removeAttrs config [ "_module" ]);
             |                  ^
          360|         _module = checked (config._module);

       (stack trace truncated; use '--show-trace' to show the full, detailed trace)

       error: attribute 'nixpkgs.config.allowUnfree' already defined at /etc/nixos/configuration.nix:21:1
       at /etc/nixos/configuration.nix:380:3:
          379|   # Allow unfree packages
          380|   nixpkgs.config.allowUnfree = true;
             |   ^
          381|

Yep, sorry, I wasn’t aware you had it configured and assumed. Read the edit :slight_smile:

Ok, this was actually a set of problems I’ve been down before and got this far. It looks like the edits are now resulting in the rebuild command downloading the sources for Blender to build and compile, fingers crossed. Thanks for the help so far.

1 Like

FWIW, I’d actually appreciate knowing if the _module.args thing works; if it does, I’ll just suggest people do that right off the bat from now on. Might even write an FAQ on the wiki about this.

Hello, so I’m not sure what’s happening now. The system kills konsole which is running the rebuild, and then the fans stop spinning down a few minutes later. I rebooted and blender isn’t in the system so I don’t know if the entire rebuild fails because it’s out of memory or what. I have 6c12t but only 16gb ram.

Fixed my issues re: memory, now Blender 4.5.3 with CUDA is working. Thank you so much.

Regarding the approach with _module.args, I can try that in the future, maybe, although I strongly prefer one single configuration.nix and don’t intend to flakify at any point, getting to this point has been enough unplanned adventure for me, for now. I appreciate your help getting me to this point, I’ll mark the post containing the answer as the solution.

Thank you

1 Like

Hey fellow artist, so I know this is already done but have you checked nix warez blender build? all you gotta do is add it to your flake and install it like how you would do any flake software flake.

inputs = {
    nix-warez.url = "github:edolstra/nix-warez?dir=blender";
 }

Just add that line (obv second line) to your flake.nix in the input section. Next you just gotta install it how you normally do any flake software. I used to use hm so here is what I did:

{ inputs, pkgs, settings, ... }: let
    unstable = import inputs.nixpkgs-unstable { inherit (pkgs) system; };
in{
  home-manager.users.${settings.account.name}.home.packages = with pkgs; [
    # Use the prefix 'unstable.' for unstable packages
    firefox
    bottles
    pureref
    inputs.nix-warez.packages."${system}".blender_4_5
  ];
}

This should ideally work and is a much better solution rather than building it every single time you need a new update. In inputs.nix-warez.packages."${system}".blender_4_5, the .blender_4_5 lets you choose the version you need, you can change it to .blender_4_2. To see more options go to nix-warez/blender/flake.nix at f49a87422539d748a34b9f3b07a7b8ced7242dff · edolstra/nix-warez · GitHub and scroll a bit through the code. Hope that helps dude !!

edit: seems like you have issues understanding flakes, so heres a really good guide on it Introduction to Nix & NixOS | NixOS & Flakes Book. Would highly recommend reading through it

edit 2: This is blender bin btw and this makes it persistent (yeah mb I didnt really read the entirety of your post but skimmed it)