NixOS non-functional on a 4060 Ti?

I know NVIDIA Linux drivers are bad, but performance is just abysmal on NixOS for me on a 4060 Ti. I can’t imagine it being this bad on other distros, so I must be missing something in my config or perhaps there is a bug in the packages. I’ve tried so many desktop environments:

  • KDE Plasma - Plasma 5 Xorg can’t load the SDDM login screen, just shows a black screen with a cursor. Plasma 6 Wayland runs at like 4 fps.
  • GNOME Wayland - GDM works fine, but it runs with a lot of graphic glitches. Cursor is replaced by a white box. Icons are tofu. Laggy cursor.
  • Cinnamon - Gives me an error upon logging in, then puts me in an all black desktop with no taskbar.
  • XFCE - This one actually functions! Kind of. Blender doesn’t launch as I get Error GLX_ARB_create_context not available.

I’m following the NixOS wiki and I know I’m on the latest kernel and proprietary drivers, so I really have no idea why it’s like this. Worth mentioning is that games running through flatpak Steam don’t seem to want to use the GPU at all despite it showing up in the Steam diagnostics so it’s a kernel issue potentially?

My Nvidia configs:

{ config, lib, allowed-unfree-packages, ... }:
{
  nixpkgs.config = {
    allowUnfreePredicate = pkg: builtins.elem (lib.getName pkg) allowed-unfree-packages;
  };

  boot = {;
    kernelParams = [ "module_blacklist=i915" "module_blacklist=amdgpu" ];
    extraModprobeConfig = ''
      blacklist nouveau
      options nouveau modeset=0
    '';
  };

  hardware.opengl = lib.mkDefault {
    enable = true;
    driSupport = true;
    driSupport32Bit = true;
  };

  services.xserver.videoDrivers = [ "nvidia" ];

  hardware.nvidia = {
    modesetting.enable = true;
    nvidiaPersistenced = true;
    powerManagement.enable = false;
    open = false;
    nvidiaSettings = true;
    package = config.boot.kernelPackages.nvidiaPackages.stable; #tried both production and stable
  };

  environment.systemPackages = [
    pkgs.cudaPackages_12_2.cudatoolkit
  ];
}

allowed-unfree-packages has this:

let
   allowed-unfree-packages = [
    "steam"
    "steam-run"
    "nvidia-x11"
    "nvidia-settings"
    "nvidia-persistenced"
    "cudatoolkit"
    "cuda_cudart"
    "cuda_nvcc"
    "blender"
  ];

nvidia-smi

+-----------------------------------------------------------------------------------------+
| NVIDIA-SMI 550.54.14              Driver Version: 550.54.14      CUDA Version: 12.4     |
|-----------------------------------------+------------------------+----------------------+
| 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 RTX 4060 Ti     On  |   00000000:04:00.0  On |                  N/A |
|  0%   33C    P8             12W /  165W |     361MiB /  16380MiB |     18%      Default |
|                                         |                        |                  N/A |
+-----------------------------------------+------------------------+----------------------+
                                                                                         
+-----------------------------------------------------------------------------------------+
| Processes:                                                                              |
|  GPU   GI   CI        PID   Type   Process name                              GPU Memory |
|        ID   ID                                                               Usage      |
|=========================================================================================|
|    0   N/A  N/A      1902      G   ...jl7q8flnn-xorg-server-21.1.11/bin/X        327MiB |
|    0   N/A  N/A      9496      G   ...local/share/Steam/ubuntu12_32/steam          3MiB |
|    0   N/A  N/A      9676      G   ./steamwebhelper                               22MiB |
+-----------------------------------------------------------------------------------------+

lspci

04:00.0 VGA compatible controller: NVIDIA Corporation AD106 [GeForce RTX 4060 Ti 16GB] (rev a1)

Bizarrely nvidia-settings doesn’t show anything for this tab

Looking through the logs I notice nvidia-persistenced just flat out doesn’t work
nvidia-persistenced[11865]: Unable to access /var/run/nvidia-persistenced: Permission denied
Other than that, not many nvidia-related errors, I see one graphics library fails to load
xsession[2930]: ERROR: ld.so: object '/nix/store/7616k8phi8kabrpc7fpv6fgr9ndlg310-mesa-23441f/lib/libglapi.so.0' from LD_PRELOAD cannot be preloaded (cannot open shared object file): ignored. Could this be the cause?

Turns out I had a rogue config somewhere that was installing mesa drivers, probably causing a conflict