Help building python313Packages.xformers with CUDA support

All xformers dependencies were built and installed successfully on a previous nixos-rebuild switch. According to nvidia-smi the legacy nvidia drivers are installed and working correctly, and my GPUs are recognized.

System Hardware Information:

  • AMD FX-8320 Eight-Core Processor @3828.570 MHz & 2048 KB Cache.
  • 32GB of System RAM.
  • 2x NVIDIA Quadro K6000 GPUs w/12GB VRAM each.
  • 248GB of swap distributed in multiple files across 2 different mechanical hard drives (to increase I/O bandwith).

NixOS Information:

# nix-info -m

  • system: `“x86_64-linux”`
  • host os: `Linux 6.12.59, NixOS, 25.11 (Xantusia), 25.11.1335.09eb77e94fa2`
  • multi-user?: `yes`
  • sandbox: `yes`
  • version: `nix-env (Nix) 2.31.2`
  • channels(root): `“nixos-25.11”`
  • nixpkgs: `/nix/store/j4hbw1ws742nmsfhbd9r22k1qgivk7hc-nixos-25.11/nixos`

I have this line in my configuration.nix: nixpkgs.config.cudaSupport = true;

Here is a portion of my software.nix file including my declaration for xformers:

python313Packages.torch-bin
python313Packages.numpy
python313Packages.tensorflow
#python312Packages.xformers
(python313Packages.xformers.overrideAttrs (finalAttrs: previousAttrs: {
OMP_NUM_THREADS = 2;
MKL_NUM_THREADS = 2;
NUMEXPR_NUM_THREADS = 2;
PYTORCH_NUM_THREADS = 2;
}))
python312Packages.vllm

The number of threads for the xformers package was necessary as the build process was not respecting my limited system RAM and without constraining it manually, the build would end up hanging due to swap I/O bandwitdth limitations, with both swap disks running at 100% bandwidth utilization, and the CPU in a 98% iowait state across all 8 cores. As you will see from the build log below, manually constraining concurrent processes seems to have solved that issue, but now I am seeing a new issue.

The blockquote below is a portion of the build log. When it reaches the end of the blockquote the system is seeing lots of systemd.coredump and thousands of drkonqi-coredump-processor processes owned by root for about 32-39 hours. Thoses processes have since finished but the build hasn’t progressed. It is supposed to be building python312Packages.vllm next. The only processes still owned by nixbld* are 5 of something like /nix/store/path/bin/python3.13 -m pytest/ -k not (test_custom_linear_solve_aux) –numprocesses=4 -Wignore…. and thousands of the following /nix/store/path/bin/python3.13 -u -c import sys;exec(eval(sys.stid.readline())). However there is almost no CPU utilization, and almost no disk I/O bandwidth utilization. The system is basically idle at this point.

**Successfully built xformers-0.0.30-cp313-cp313-linux_x86_64.whl** 
**Successfully built xformers-0.0.30-cp313-cp313-linux_x86_64.whl** 
Finished creating a wheel... 
Finished creating a wheel... 
Finished executing pypaBuildPhase 
Finished executing pypaBuildPhase 
buildPhase completed in 10 hours 15 minutes 50 seconds 
Running phase: pythonRuntimeDepsCheckHook 
Executing pythonRuntimeDepsCheck 
Checking runtime dependencies for xformers-0.0.30-cp313-cp313-linux_x86_64.whl 
buildPhase completed in 10 hours 15 minutes 50 seconds 
Running phase: pythonRuntimeDepsCheckHook 
Executing pythonRuntimeDepsCheck 
Checking runtime dependencies for xformers-0.0.30-cp313-cp313-linux_x86_64.whl 
Finished executing pythonRuntimeDepsCheck 
Finished executing pythonRuntimeDepsCheck 
pythonRuntimeDepsCheckHook completed in 33 seconds 
Running phase: installPhase 
Executing pypaInstallPhase 
pythonRuntimeDepsCheckHook completed in 33 seconds 
Running phase: installPhase 
Executing pypaInstallPhase 
Successfully installed xformers-0.0.30-cp313-cp313-linux_x86_64.whl 
Finished executing pypaInstallPhase 
Running phase: pythonOutputDistPhase 
Executing pythonOutputDistPhase 
Successfully installed xformers-0.0.30-cp313-cp313-linux_x86_64.whl 
Finished executing pypaInstallPhase 
Running phase: pythonOutputDistPhase 
Executing pythonOutputDistPhase 
Finished executing pythonOutputDistPhase 
Running phase: fixupPhase 
Finished executing pythonOutputDistPhase 
Running phase: fixupPhase 
shrinking RPATHs of ELF executables and libraries in /nix/store/3fi419x969mfzr2vpzrdsljj9fal9c8p-python3.13-xformers-0.0.30 
shrinking RPATHs of ELF executables and libraries in /nix/store/cyfwvwnpr2x16w90crsh2kk7qm259v1a-python3.13-xformers-0.0.30 
shrinking /nix/store/3fi419x969mfzr2vpzrdsljj9fal9c8p-python3.13-xformers-0.0.30/lib/python3.13/site-packages/xformers/\_C_flashattention3.so 
shrinking /nix/store/cyfwvwnpr2x16w90crsh2kk7qm259v1a-python3.13-xformers-0.0.30/lib/python3.13/site-packages/xformers/\_C_flashattention3.so 
shrinking /nix/store/3fi419x969mfzr2vpzrdsljj9fal9c8p-python3.13-xformers-0.0.30/lib/python3.13/site-packages/xformers/\_C.so 
shrinking /nix/store/cyfwvwnpr2x16w90crsh2kk7qm259v1a-python3.13-xformers-0.0.30/lib/python3.13/site-packages/xformers/\_C.so 
checking for references to /build/ in /nix/store/3fi419x969mfzr2vpzrdsljj9fal9c8p-python3.13-xformers-0.0.30... 
patching script interpreter paths in /nix/store/3fi419x969mfzr2vpzrdsljj9fal9c8p-python3.13-xformers-0.0.30 
checking for references to /build/ in /nix/store/cyfwvwnpr2x16w90crsh2kk7qm259v1a-python3.13-xformers-0.0.30... 
stripping (with command strip and flags -S -p) in  /nix/store/3fi419x969mfzr2vpzrdsljj9fal9c8p-python3.13-xformers-0.0.30/lib 
patching script interpreter paths in /nix/store/cyfwvwnpr2x16w90crsh2kk7qm259v1a-python3.13-xformers-0.0.30 
stripping (with command strip and flags -S -p) in  /nix/store/cyfwvwnpr2x16w90crsh2kk7qm259v1a-python3.13-xformers-0.0.30/lib 
shrinking RPATHs of ELF executables and libraries in /nix/store/5b89m01jc9d4hj0wl2jj2l1n1xna40dg-python3.13-xformers-0.0.30-dist 
checking for references to /build/ in /nix/store/5b89m01jc9d4hj0wl2jj2l1n1xna40dg-python3.13-xformers-0.0.30-dist... 
patching script interpreter paths in /nix/store/5b89m01jc9d4hj0wl2jj2l1n1xna40dg-python3.13-xformers-0.0.30-dist 
shrinking RPATHs of ELF executables and libraries in /nix/store/qf92qylwngva6yj8f6vsvi7xcv6mm87x-python3.13-xformers-0.0.30-dist 
checking for references to /build/ in /nix/store/qf92qylwngva6yj8f6vsvi7xcv6mm87x-python3.13-xformers-0.0.30-dist... 
patching script interpreter paths in /nix/store/qf92qylwngva6yj8f6vsvi7xcv6mm87x-python3.13-xformers-0.0.30-dist 
Executing pythonRemoveTestsDir 
Executing pythonRemoveTestsDir 
Finished executing pythonRemoveTestsDir 
Finished executing pythonRemoveTestsDir 
Running phase: pythonCatchConflictsPhase 
Running phase: pythonCatchConflictsPhase 
Running phase: pythonRemoveBinBytecodePhase 
Running phase: pythonRemoveBinBytecodePhase 
Running phase: pythonImportsCheckPhase 
Running phase: pythonImportsCheckPhase 
Executing pythonImportsCheckPhase 
Check whether the following modules can be imported: xformers 
Executing pythonImportsCheckPhase 
Check whether the following modules can be imported: xformers 
pythonImportsCheckPhase completed in 8 minutes 6 seconds 
pythonImportsCheckPhase completed in 8 minutes 6 seconds

Is this still a help topic or should I submit a package build issue to GitHub? I should probably include some of the coredump info, but I am not sure how to do that. Any other information I should provide? Should I let it keep running? Should I pkill -u nixbld* && killall nixos-rebuild and then try nixos-rebuild switch again (since it seems xformers may have been built already)? Should I run tests to verify that xformers is actually working before trying to build vLLM again?

Sounds like deadlock in the upstream test cases. I’d try a blatant doCheck = false; and if that fixes it report the bug upstream.

I know this is quite common, but people run into issues with it left right and centre. Consider setting just .override { torch = torch.override { cudaSupport = true; }; }; there’s no need to enable cuda support system-wide - you most likely don’t need it in Firefox, for example.

Can you please show me where the `.override { torch = torch.override { cudaSupport = true; }; };` goes within the context of the overall configuration. As written, it is a bit confusing. Pretty sure it is not just torch that I need compiled with CUDA support. I would also need tensorflow, xformers, & vllm (maybe numpy) compiled with CUDA support. Also things like FreeCAD, Blender, etc.

I am assuming that doCheck = false; would go something like:

python313Packages.torch-bin
python313Packages.numpy
python313Packages.tensorflow
#python312Packages.xformers
(python313Packages.xformers.overrideAttrs (finalAttrs: previousAttrs: {
OMP_NUM_THREADS = 2;
MKL_NUM_THREADS = 2;
NUMEXPR_NUM_THREADS = 2;
PYTORCH_NUM_THREADS = 2;
doCheck = false;
}))
python312Packages.vllm

Rebuilding with doCheck = false; resulted in a very different build log, but ultimately the same situation with thousands of /nix/store/path/bin/python3.13 -u -c import sys;exec(eval(sys.stid.readline())) processes once the build got to 95%. System is completely idle with no more progress being made. No core dumps this time. Here is what the build log looks like:

snipped

adding ‘xformers-0.0.30.dist-info/METADATA’
adding ‘xformers-0.0.30.dist-info/WHEEL’
adding ‘xformers-0.0.30.dist-info/top_level.txt’
adding ‘xformers-0.0.30.dist-info/RECORD’
removing build/bdist.linux-x86_64/wheel
… [ 22%]
Successfully built xformers-0.0.30-cp313-cp313-linux_x86_64.whl
Finished creating a wheel…
Finished executing pypaBuildPhase
buildPhase completed in 55 minutes 15 seconds
Running phase: pythonRuntimeDepsCheckHook
Executing pythonRuntimeDepsCheck
Checking runtime dependencies for xformers-0.0.30-cp313-cp313-linux_x86_64.whl
Finished executing pythonRuntimeDepsCheck
Running phase: installPhase
Executing pypaInstallPhase
Successfully installed xformers-0.0.30-cp313-cp313-linux_x86_64.whl
Finished executing pypaInstallPhase
Running phase: pythonOutputDistPhase
Executing pythonOutputDistPhase
Finished executing pythonOutputDistPhase
Running phase: fixupPhase
shrinking RPATHs of ELF executables and libraries in /nix/store/cb1ix4av50zqrwnh4cns9hn8i603dpak-python3.13-xformers-0.0.30
shrinking /nix/store/cb1ix4av50zqrwnh4cns9hn8i603dpak-python3.13-xformers-0.0.30/lib/python3.13/site-packages/xformers/_C_flashattention3.so
shrinking /nix/store/cb1ix4av50zqrwnh4cns9hn8i603dpak-python3.13-xformers-0.0.30/lib/python3.13/site-packages/xformers/_C.so
checking for references to /build/ in /nix/store/cb1ix4av50zqrwnh4cns9hn8i603dpak-python3.13-xformers-0.0.30…
patching script interpreter paths in /nix/store/cb1ix4av50zqrwnh4cns9hn8i603dpak-python3.13-xformers-0.0.30
stripping (with command strip and flags -S -p) in /nix/store/cb1ix4av50zqrwnh4cns9hn8i603dpak-python3.13-xformers-0.0.30/lib
shrinking RPATHs of ELF executables and libraries in /nix/store/kn6k34wpza5h1zmj5wwm380azsxarp3n-python3.13-xformers-0.0.30-dist
checking for references to /build/ in /nix/store/kn6k34wpza5h1zmj5wwm380azsxarp3n-python3.13-xformers-0.0.30-dist…
patching script interpreter paths in /nix/store/kn6k34wpza5h1zmj5wwm380azsxarp3n-python3.13-xformers-0.0.30-dist
Executing pythonRemoveTestsDir
Finished executing pythonRemoveTestsDir
Running phase: pythonCatchConflictsPhase
Running phase: pythonRemoveBinBytecodePhase
Running phase: pythonImportsCheckPhase
Executing pythonImportsCheckPhase
Check whether the following modules can be imported: xformers
pythonImportsCheckPhase completed in 39 seconds
… [ 22%]
…s..sssss…s…s…s…ssssssss [ 23%]
s…s…s.sss…s… [ 23%]

snipped

s… [ 94%]
… [ 94%]
… [ 94%]
…ss..sss…ss..ss…ss..sss [ 94%]
…ssssss… [ 94%]
…sssssss.sssssssssssssssssssssss [ 95%]
sssssssssssss…ssssssssss… [ 95%]
… [ 95%]

Having seen in the log (for the second time) Successfully built xformers-0.0.30-cp313-cp313-linux_x86_64.whl I commented out python313Packages.vllm and re-ran nixos-rebuild switch. That finished pretty immediately and installed the GRUB menu option. Uncommenting python313Packages.vllm and re-running nixos-rebuild switch show the same build log as before, so clearly that last hang up was with building vllm. I am going to attempt doCheck = false; there as well.

Those are pytest logs, definitely looks like you’re still running tests. Looking more closely at what you’re doing, you’re trying to override things for python packages (duh, sorry). I imagine that you’re just dumping the result in environment.systemPackages.

This won’t work. Firstly, the python ecosystem has its own derivation functions, which work subtly differently; you’re overriding the underlying mkDerivation, but the checks presumably run in the buildPythonPackage level, and generally overrides on the mkDerivation level won’t work.

Secondly, using nix is kinda like putting every package you use in a venv. Currently, you’re creating a separate venv for every single python package you’re installing, and you never even add a python interpreter to any of these venvs. Those python packages you’re installing will never be used.

We should fix both of those things:

# e.g. in configuration.nix
{ pkgs, ... }:
{
  environment.systemPackages =
    let
      python = pkgs.python313.override {
        packageOverrides = final: prev: {
          # Basically all other python packages derive their `cudaSupport`
          # from whether torch/tensorflow have it enabled
          torch = prev.torch.override { cudaSupport = true; };
          tensorflow = prev.tensorflow.override { cudaSupport = true; };
        };
      };
      pythonWithPackages = python.withPackages (ppkgs: [ ppkgs.torch ]);
    in
    [ pythonWithPackages ];
}

… now, this won’t fix your build issues. You can hack around the xformers tests like so:

{ pkgs, ... }:
{
  environment.systemPackages =
    let
      python = pkgs.python313.override {
        packageOverrides = final: prev: {
          torch = prev.torch.override { cudaSupport = true; };
          tensorflow = prev.tensorflow.override { cudaSupport = true; };

          xformers = prev.xformers.overridePythonAttrs (old: {
            doCheck = false;
          });
        };
      };
      pythonWithPackages = python.withPackages (ppkgs: [ ppkgs.torch ]);
    in
    [ pythonWithPackages ];
}

… If you need to make other changes, it should be pretty obvious what the pattern is. With a bit of luck you may not have to override anything else.

You might also want to try out the cuda cache; with any luck (and a reasonably up-to-date nixpkgs) that should prevent rebuilds entirely.

You can also set those specifically instead of with the global config.cudaSupport, e.g.:

{ pkgs, ... }:
{
  environment.systemPackages = [
    (pkgs.blender.override { cudaSupport = true; })
  ];
}

… of course, at some point it might make sense to disable cudaSupport for a subset of packages instead. But you seem to have a pretty clear idea of which packages need it.

Then you just watch for unexpected rebuilds. But IMO opt-in is better; would be nice if the python package set had a more easily accessible way to override the callPackage used to build the python modules, that’d make overriding cudaSupport for specifically all python packages, but not the whole desktop, easier.

Well just trying again seems to have gotten me much farther even if the doCheck = false; I added to the package overrides apparently did nothing. As I mentioned earlier, I already got XFormers installed, the second hang with all the ….sss… stuff I think was related to JAX. Re-running got past that, and another vLLM dependancy, and I am fairly close to completion with building vLLM itself. So I am not sure what the underlying issue was.

Regarding opt-in overrides, I did comment out firefox when I saw it trying to build from source as I just wanted to clear the hurdles I was particularly interested in first. This machine will be running headless when I am doing LLM workflows. If I sit down to use Blender or FreeCAD, then I would need Firefox. The rest of the system either built fast with CUDA support, or was in the set of packages that I wanted CUDA support for. So is there a way to override just Firefox, and say no CUDA support for this?

Regarding how my virtual environment is laid out, I did not include that in my post. I have a little bit more nuanced config than most people. I have a separate software.nix file that gets included in configuration.nix as well as a local.nix file. The local.nix file has everything that is specific only to that one machine, or is not for public knowledge (e.g. usernames, language, timezone, UUID disk mounts, etc). It contains a mixture of what people normally have in configuration.nix and hardware.nix and it has been working quite nicely. My software.nix file (the file that gets edited most often and why I wanted it separate) contains the normal system wide package set declaration, which I have kept very minimal. Just what I want root to have for doing system maintenance. I then define a user package set let userPackageSet = with pkgs; [
(which is where the snip of packages I included in my post comes from). The user package set has all of the software that I want my user to have access to. I then reference that user package set when declaring my user. The basic structure of my software.nix file looks like:

{ config, pkgs, lib, ... }:
let userPackageSet = with pkgs; [
All_USER_PACKAGE_DECLARATIONS
];
in
{
environment.systemPackages = with pkgs; [
ALL_SYSTEM_WIDE_PACKAGE_DECLARATIONS
];
users.users.USERNAME = {
isNormalUser =true;
description = "REAL_NAME”;
extraGroups = [ "networkmanager" "wheel" ];
packages = userPackageSet;
};
}

I would really like to be able to move the user declaration to local.nix and keep the user package set declaration in software.nix, but I haven’t been able to crack that nut yet.

I wish I had known of that CUDA cache a few weeks ago. :joy:

You’d have to follow the dependencies of Firefox to find the one that has the cuda switch. nix why-depends or nix-tree might help.

Yeah, so, that should still not be working. You probably do have a binary of some kind for xformers, assuming it has one, but it’s not properly intrgrated with your system python. Trying import xformers or such in a python shell should fail.

I suppose if you don’t actually use python that may well be sufficient for you.

Wait, so python packages are not installed like regular software? I can run all of the software I declared in my userPackageSet as the user, but I indeed cannot import xformers or any of the other python packages I declared in the userPackageSet from a python shell. What specifically do I need to change in my config to make these python packages available to the user?

You’d use python.withPackages as I suggested in my snippets, e.g. for a python with torch:

That creates something like a venv in which torch is available. If you put the result in environment.systemPackages or home.packages or such, that makes that available as your “installed” python, as far as “installed” means anything on NixOS.

Hence I went through all the effort to figure out overrides on a python package level and wrote those snippets… :stuck_out_tongue: If I’d had to guess, I imagine it didn’t work for you at first because you override the packages by declaring them multiple times or something.

I haven’t gotten around to using home manager yet. I will eventually, but my home folder is shared by some Debian machines (via GlusterFS), so I have some development to do to automatically add all of the dot files (based on hostname as an overlay to the data in the /home/user folder.

I was attempting to still manage per user software declarations at the global level (requiring root permissions). So could I do something like this for my software.nix?

{ config, pkgs, lib, … }:
let userPackageSet = with pkgs; [
let
python = pkgs.python313.override {
packageOverrides = final: prev: {
torch = prev.torch.override { cudaSupport = true; };
tensorflow = prev.tensorflow.override { cudaSupport = true; };
};
};
pythonWithPackages = python.withPackages (ppkgs: [
python313Packages.torch-bin
python313Packages.numpy
python313Packages.tensorflow
python313Packages.xformers
python313Packages.vllm
]);
in
[ pythonWithPackages ];
All_OTHER_USER_PACKAGE_DECLARATIONS
];
in
{
environment.systemPackages = with pkgs; [
ALL_SYSTEM_WIDE_PACKAGE_DECLARATIONS
];
users.users.USERNAME = {
isNormalUser =true;
description = "REAL_NAME”;
extraGroups = [ “networkmanager” “wheel” ];
packages = userPackageSet;
};
}

This seems to be working, using the cuda cache. Still running the nixos-rebuild switch –upgrade.

{ config, pkgs, lib, ... }:

let
llmPythonPackages = with pkgs; [
python313Packages.torch-bin
python313Packages.numpy
python313Packages.tensorflow
python313Packages.xformers
python313Packages.vllm
python313Packages.opencv4
];

llmPython = pkgs.python313.withPackages (ps: llmPythonPackages);

### venv wrapper here?

userPackageSet = with pkgs; [
llmPython
THE_REST_OF_THE_USER_PACKAGES

I haven’t gotten this working yet with my userPackageSet declaration. I got errors saying cudaSupport wasn’t a recognized override option or something like that; for blender, opencv, and firefox (trying to set it explicitly false and leave the global override in place). So I still have the global cuda support enabled, even for firefox. This is what I am going to try next:

userPackageSet = with pkgs; [
OTHER_PACKAGES_TOP
(blender.override { cudaSupport = true; })
(opencv.override { cudaSupport = true; })
(firefox.override { cudaSupport = false; })
OTHER_PACKAGES_BOTTOM
];

I have a working config using the cuda cache now. My user can now import the python modules.

{ config, pkgs, lib, … }:

let
llmPythonPackages = with pkgs; [
python313Packages.numpy
python313Packages.tensorflow
python313Packages.xformers
python313Packages.vllm
python313Packages.opencv4
];

llmPython = pkgs.python313.withPackages (ps: llmPythonPackages);

userPackageSet = with pkgs; [
llmPython
nvidia-system-monitor-qt
cudaPackages.nccl
cudaPackages.cuda_nvcc
cudaPackages.cudnn
cudaPackages.cuda_cudart
cudaPackages.cudatoolkit
cudaPackages.cuda_opencl
THE_REST_OF_MY_USER_PACKAGES
];
in
{

environment.systemPackages = with pkgs; [
MINIMAL_SYSTEM_WIDE_PACKAGES
];

users.users.USERNAME = {
isNormalUser = true;
description = "REAL_NAME”;
extraGroups = [ “networkmanager” “wheel” ];
packages = userPackageSet;
};
}

Or as a flake:

{
description = “LLM‑Python dev environment”;
inputs = {
nixpkgs.url = “github:NixOS/nixpkgs/nixos-25.11”;
};
outputs = { self, nixpkgs, … }:
let
system = “x86_64-linux”;
pkgs = import nixpkgs {
inherit system;
config = {
allowUnfree = true;
cudaSupport = true;
};
};
llmPythonPackages = with pkgs; [
python313Packages.numpy
python313Packages.tensorflow
python313Packages.xformers
python313Packages.vllm
python313Packages.opencv4
];
llmPython = pkgs.python313.withPackages (ps: llmPythonPackages);
in
{
devShells.${system}.default = pkgs.mkShell {
packages = [ llmPython ];
shellHook = ‘’
echo “LLM Python environment ready.”
echo " python → ${llmPython}/bin/python"
echo " pip → ${llmPython}/bin/pip"
‘’;
};
};
}

Note: I was getting a duplicate path error during the build when I explicitly declared torch-bin in the llmPythonPackages declaration. So it was removed in the final config and left to the other packages to pull torch-bin in as a dependency.

While that works, I’d suggest doing this:

let
  llmPythonPackages = ppkgs: with ppkgs; [
    numpy
    tensorflow
    xformers
    vllm
    opencv4
    torch
  ];
  llmPython = pkgs.python313.withPackages llmPythonPackages;
in
  ...

That way you get the correct packages for the correct python. I think that should fix your collision, too - you want torch, not torch-bin, since your other packages use that.

Btw, while block quotes are far from the worst way I’ve seen people paste code, you probably should learn how to use code blocks.