Can't get ComfyUI to work on NVIDIA Graphics Card NixOS [24.11] [stable]

Hello and good day to anyone reading!

for some background:
I’ve recently moved my machine over to linux, this is my 2nd distro after disliking mint. I found the concept of nix to be very pleasing, and thus I decided to try it out - I’ve been hooked ever since, though it’s been like a week, pleasant experience on all fronts thus far ^^.

the problem:
I have a bit of an issue with getting ComfyUI to work on my installation. I’ve followed the instructions to a tee (well, as best as I can, to a tee) but I keep having issues with CUDA drivers;

    from comfy import model_management
  File "/run/media/yassir/Backup Drive/flux/Comfy_Linux/ComfyUI/comfy/model_management.py", line 166, in <module>
    total_vram = get_total_memory(get_torch_device()) / (1024 * 1024)
                                  ^^^^^^^^^^^^^^^^^^
  File "/run/media/yassir/Backup Drive/flux/Comfy_Linux/ComfyUI/comfy/model_management.py", line 129, in get_torch_device
    return torch.device(torch.cuda.current_device())
                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/run/media/yassir/Backup Drive/flux/Comfy_Linux/ComfyUI/venv/lib/python3.12/site-packages/torch/cuda/__init__.py", line 973, in current_device
    _lazy_init()
  File "/run/media/yassir/Backup Drive/flux/Comfy_Linux/ComfyUI/venv/lib/python3.12/site-packages/torch/cuda/__init__.py", line 320, in _lazy_init
    torch._C._cuda_init()
RuntimeError: Found no NVIDIA driver on your system. Please check that you have an NVIDIA GPU and installed a driver from http://www.nvidia.com/Download/index.aspx

expected behavior would be for comfyui to recognize and see my gpu, and launch!

more info:

  • I am running this using a custom nix-shell and python environment to keep things isolated, here is that shell script:
{
  pkgs ? import <nixpkgs> { config.allowUnfree = true; }
}:
let
  python = pkgs.python312.withPackages (pyPkgs: [
    pyPkgs.pytorch
    pyPkgs.numpy
    pyPkgs.virtualenv
  ]);
in
pkgs.mkShell {
  buildInputs = [
    python
    pkgs.gcc12  # Use GCC 12 for compatibility with PyTorch
    pkgs.cudatoolkit_11
  ];

  shellHook = ''
    export PATH=$PATH:${pkgs.cudatoolkit_11}/bin
    export LD_LIBRARY_PATH=${pkgs.gcc12.cc.lib}/lib:$LD_LIBRARY_PATH
  '';
}

I believe the issue’s likely with this, as I’m very unconfident that I set up properly, so guidance is quite welcome!

  • here is are some relevant parts of my configuration.nix - I’m not providing the whole thing for clarity’s sake as my script’s quite a pigsty, but if asked I’ll happily oblige and provide the full script
...

 hardware.graphics = {
	enable = true;
...
# Load nvidia driver for Xorg and Wayland
  services.xserver.videoDrivers = ["nvidia"];

  # Nvidia proprietary drivers
  #  hardware.nvidia.package = config.boot.kernelPackages.nvidiaPackages.stable;
  hardware.nvidia.prime = {
    reverseSync.enable = true;
    # Enable if using an external GPU
    allowExternalGpu = false;

    # Make sure to use the correct Bus ID values for your system!
    intelBusId = "PCI:0:2:0";
    nvidiaBusId = "PCI:14:0:0";
    # amdgpuBusId = "PCI:54:0:0"; For AMD GPU
  };

  hardware.nvidia = {

    # Modesetting is required.
    modesetting.enable = true;

    # Nvidia power management. Experimental, and can cause sleep/suspend to fail.
    # Enable this if you have graphical corruption issues or application crashes after waking
    # up from sleep. This fixes it by saving the entire VRAM memory to /tmp/ instead 
    # of just the bare essentials.
    powerManagement.enable = false;

    # Fine-grained power management. Turns off GPU when not in use.
    # Experimental and only works on modern Nvidia GPUs (Turing or newer).
    powerManagement.finegrained = false;

    # Use the NVidia open source kernel module (not to be confused with the
    # independent third-party "nouveau" open source driver).
    # Support is limited to the Turing and later architectures. Full list of 
    # supported GPUs is at: 
    # https://github.com/NVIDIA/open-gpu-kernel-modules#compatible-gpus 
    # Only available from driver 515.43.04+
    # Currently alpha-quality/buggy, so false is currently the recommended setting.
    open = false;

    # Enable the Nvidia settings menu,
	# accessible via nvidia-settings.
    nvidiaSettings = true;

    # Optionally, you may need to select the appropriate driver version for your specific GPU.
    package = config.boot.kernelPackages.nvidiaPackages.stable;
  };
 };
...
# I'm supposing this could be relevant, not sure
  # Enable the KDE Plasma Desktop Environment.
  services.displayManager.sddm.enable = true;
  services.desktopManager.plasma6.enable = true;

 # Disable some Plasma6 packages
  environment.plasma6.excludePackages = with pkgs.kdePackages; [
    plasma-browser-integration
  ];

  # Make sure displayManager runs on Wayland
  services.displayManager.defaultSession = "plasma";

  # Enable GNOME Desktop Environment
  #services.xserver.displayManager.gdm.enable = true;
  #services.xserver.desktopManager.gnome.enable = true;
...
# Allow unfree packages
  nixpkgs.config.allowUnfree = true;

  # --- Packages

  # --- Dynamic Library packages

  programs.nix-ld.enable = true;
  programs.nix-ld.libraries = with pkgs; [

  ];
  # --- Dynamic Library packages


  # --- System Pacakges (Most packages go here) 
  # $ nix search wget
  environment.systemPackages = with pkgs; [
    # Qt5 packages
    qt5.qtbase
    qt5.qtdeclarative
    qt5.qtwebsockets
    qt5.qtwebchannel
    qt5.qtmultimedia
    qt5.qtwebengine

    # Qt6 packages
    qt6.qtbase
    qt6.qtdeclarative
    qt6.qtwebsockets
    qt6.qtwebchannel
    qt6.qtmultimedia
    qt6.qtwebengine   

    # ---
    pkgs.kitty
    pkgs.fira-code-nerdfont
    file 
    pkgs.kde-rounded-corners
    fuse
    vim 
    neovim
    vlc
    lf  
    pkgs.floorp
    pkgs.neofetch
    pkgs.discord
    pkgs.git
    
    # --- python 
    (python3.withPackages (ps: [ ps.websockets ]))
    python312
    # --- python

    pkgs.cudaPackages_11.cudatoolkit
    pkgs.obsidian
    cmake
    gcc
    ninja
    gnumake42
    ecm
    pkgs.parsec-bin
    pkgs.qbittorrent-enhanced
    pkgs.nicotine-plus #SoulseekQT 
    pkgs.strawberry-qt6  
    flatpak
    libsForQt5.qtstyleplugin-kvantum
    kdePackages.qtstyleplugin-kvantum 
    kdePackages.kfind
  ];

  • my graphics card is a 1080ti. it’s properly recognized by my system, I should have prime power management and so on turned off (because I don’t want it, I like using my gpu where possible), and my card is confirmed to work as I’ve played games on here and it gets seen just fine
  • I’m using cudatoolkit_11 purely out of ignorance, I don’t know how to get cuda12 and if I need it - much less if my card supports it. just mentioning this as I do get a warning about it when activating my shell - I doubt that’s the reason for this issue.
  • nvcc --version output:
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2022 NVIDIA Corporation
Built on Wed_Sep_21_10:33:58_PDT_2022
Cuda compilation tools, release 11.8, V11.8.89
Build cuda_11.8.r11.8/compiler.31833905_0
  • nvidia-smi output:
+-----------------------------------------------------------------------------------------+
| NVIDIA-SMI 565.77                 Driver Version: 565.77         CUDA Version: 12.7     |
|-----------------------------------------+------------------------+----------------------+
| 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 1080 Ti     Off |   00000000:01:00.0  On |                  N/A |
| 28%   64C    P0             82W /  270W |     944MiB /  11264MiB |     10%      Default |
|                                         |                        |                  N/A |
+-----------------------------------------+------------------------+----------------------+
                                                                                         
+-----------------------------------------------------------------------------------------+
| Processes:                                                                              |
|  GPU   GI   CI        PID   Type   Process name                              GPU Memory |
|        ID   ID                                                               Usage      |
|=========================================================================================|
|    0   N/A  N/A       988      G   /run/wrappers/bin/kwin_wayland                213MiB |
|    0   N/A  N/A      1077      G   /run/current-system/sw/bin/Xwayland             2MiB |
|    0   N/A  N/A      1136      G   ...lasma-workspace-6.2.5/bin/ksmserver          2MiB |
|    0   N/A  N/A      1139      G   ...k2lsjj2gb6dvqg-kded-6.8.0/bin/kded6          2MiB |
|    0   N/A  N/A      1162      G   ...sma-workspace-6.2.5/bin/plasmashell         96MiB |
|    0   N/A  N/A      1174      G   ...erd-6.2.5/libexec/kactivitymanagerd          2MiB |
|    0   N/A  N/A      1176      G   ...kspace-6.2.5/bin/gmenudbusmenuproxy          2MiB |
|    0   N/A  N/A      1177      G   ...rv-plasma-desktop-6.2.5/bin/kaccess          2MiB |
|    0   N/A  N/A      1178      G   ...c/polkit-kde-authentication-agent-1          2MiB |
|    0   N/A  N/A      1180      G   ...il-6.2.5/libexec/org_kde_powerdevil          2MiB |
|    0   N/A  N/A      1181      G   ....2.5/libexec/xdg-desktop-portal-kde          2MiB |
|    0   N/A  N/A      1182      G   ...-workspace-6.2.5/bin/xembedsniproxy          2MiB |
|    0   N/A  N/A      1305      G   /run/current-system/sw/bin/kitty               19MiB |
|    0   N/A  N/A      1315      G   ...t-system/sw/bin/xwaylandvideobridge          2MiB |
|    0   N/A  N/A      1323      G   ...over-6.2.5/libexec/DiscoverNotifier          2MiB |
|    0   N/A  N/A      1330      G   /run/current-system/sw/bin/kalendarac           2MiB |
|    0   N/A  N/A      1398      G   ...-floorp-11.21.0/bin/.floorp-wrapped        366MiB |
|    0   N/A  N/A      1401      G   /run/current-system/sw/bin/dolphin              2MiB |
|    0   N/A  N/A      1595      G   ...yOnDemand --variations-seed-version         41MiB |
|    0   N/A  N/A      1673      G   hidamari-player-0                              68MiB |
|    0   N/A  N/A      1915      G   ....0/libexec/kf6/baloo_file_extractor          2MiB |
|    0   N/A  N/A      2152      G   ...9aaq2ip-kwallet-6.8.0/bin/kwalletd6          2MiB |
|    0   N/A  N/A     12473      G   /run/current-system/sw/bin/kitty               28MiB |
|    0   N/A  N/A     17920      G   ...workspace-6.2.5/libexec/baloorunner          2MiB |
+-----------------------------------------------------------------------------------------+
  • both of the above are running with the nix-shell enabled,

if you need anything else to aid me with this, feel free to ask, I’ll be happy to include any other documents. I’d like to avoid using nix-env however! regardless, have a lovely day.

Don’t know why, but terminals which launched by conda-shell could find nvidia driver, such as conda-shell and vscode-fhs. At least it works for me.

I’ll try installing conda and then trying again with that, thanks for your input