Nvidia hardware video acceleration on NixOS fresh install

I’d like to get video acceleration/ VA-API working on my machine, but firefox doesn’t like my setup. Using nixos-24.11 and hyprland/wayland:
image

And I can’t run some commands from other threads I found:

> NVD_LOG=1 nix shell nixpkgs#libva-utils -c vainfo
Trying display: wayland
libva info: VA-API version 1.22.0
libva info: User environment variable requested driver 'nvidia'
libva info: Trying to open /run/opengl-driver/lib/dri/nvidia_drv_video.so
     13177.076873512 [376000-376000] ../src/vabackend.c: 168                     init CUDA ERROR 'unknown error' (999)

libva info: Found init function __vaDriverInit_1_0
     13177.076894526 [376000-376000] ../src/vabackend.c:2187       __vaDriverInit_1_0 Initialising NVIDIA VA-API Driver: 40
     13177.076896462 [376000-376000] ../src/vabackend.c:2196       __vaDriverInit_1_0 Now have 0 (0 max) instances
     13177.076898110 [376000-376000] ../src/vabackend.c:2222       __vaDriverInit_1_0 Selecting Direct backend
     13177.099345600 [376000-376000] ../src/direct/nv-driver.c: 295            init_nvdriver Initing nvdriver...
     13177.099364711 [376000-376000] ../src/direct/nv-driver.c: 313            init_nvdriver NVIDIA kernel driver version: 565.77, major version: 565, minor version: 77
     13177.099368254 [376000-376000] ../src/direct/nv-driver.c: 320            init_nvdriver Got dev info: 100 1 2 6
     13177.105230822 [376000-376000] ../src/direct/direct-export-buf.c:  27       findGPUIndexFromFd CUDA ERROR 'initialization error' (3)

     13177.105234994 [376000-376000] ../src/vabackend.c:2252       __vaDriverInit_1_0 CUDA ERROR 'initialization error' (3)

libva error: /run/opengl-driver/lib/dri/nvidia_drv_video.so init failed
libva info: va_openDriver() returns 1
vaInitialize failed with error code 1 (operation failed),exit
> nvidia-settings --glxinfo

ERROR: libEGL setup error : libEGL.so.1: cannot open shared object file: No such file or directory

I have an Intel CPU and nvidia graphics card:

> nix shell nixpkgs#pciutils -c lspci -kd ::03xx
00:02.0 Display controller: Intel Corporation AlderLake-S GT1 (rev 0c)
        DeviceName: Onboard - Video
        Subsystem: Micro-Star International Co., Ltd. [MSI] Device 7d30
        Kernel driver in use: i915
        Kernel modules: i915
01:00.0 VGA compatible controller: NVIDIA Corporation GA102 [GeForce RTX 3080 Ti] (rev a1)
        Subsystem: eVga.com. Corp. Device 3967
        Kernel driver in use: nvidia
        Kernel modules: nvidiafb, nouveau, nvidia_drm, nvidia

Relevant config:

{ config, pkgs, ... }:
{
  # ...

  boot = {
    blacklistedKernelModules = [ "nouveau" ];
    extraModulePackages = [ config.boot.kernelPackages.nvidia_x11 ];
    initrd.kernelModules = [ "nvidia" ];
  };

  hardware = {
    graphics.enable = true;

    nvidia = {
      open = true;
      powerManagement.enable = true;
    };
  };

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

(Full config here)

hyprland.conf

env = GBM_BACKEND,nvidia-drm
env = __GLX_VENDOR_LIBRARY_NAME,nvidia
env = NVD_BACKEND,direct
env = LIBVA_DRIVER_NAME,nvidia
env = __GL_GSYNC_ALLOWED,1

env = MOZ_DISABLE_RDD_SANDBOX,1

I’m using firefox 137 with about:config:

    "gfx.x11-egl.force-enabled" = true;
    "media.hardware-video-decoding.force-enabled" = true;

Ok I guess this just got fixed in nixos/hardware/nvidia: eager load nvidia-uvm for open driver · NixOS/nixpkgs@419e4d1 · GitHub

so for now until nixos-25.05 I can just manually add nvidia_uvm to kernelModules?

after doing modprobe nvidia_uvm i got:
image

> NVD_LOG=1 nix shell nixpkgs#libva-utils -c vainfo
Trying display: wayland
libva info: VA-API version 1.22.0
libva info: User environment variable requested driver 'nvidia'
libva info: Trying to open /run/opengl-driver/lib/dri/nvidia_drv_video.so
libva info: Found init function __vaDriverInit_1_0
     14799.529758437 [420891-420891] ../src/vabackend.c:2187       __vaDriverInit_1_0 Initialising NVIDIA VA-API Driver: 40
     14799.529761022 [420891-420891] ../src/vabackend.c:2196       __vaDriverInit_1_0 Now have 0 (0 max) instances
     14799.529762556 [420891-420891] ../src/vabackend.c:2222       __vaDriverInit_1_0 Selecting Direct backend
     14799.545690304 [420891-420891] ../src/direct/nv-driver.c: 295            init_nvdriver Initing nvdriver...
     14799.545707865 [420891-420891] ../src/direct/nv-driver.c: 313            init_nvdriver NVIDIA kernel driver version: 565.77, major version: 565, minor version: 77
     14799.545710648 [420891-420891] ../src/direct/nv-driver.c: 320            init_nvdriver Got dev info: 100 1 2 6
libva info: va_openDriver() returns 0
vainfo: VA-API version: 1.22 (libva 2.22.0)
vainfo: Driver version: VA-API NVDEC driver [direct backend]
vainfo: Supported profile and entrypoints
      VAProfileMPEG2Simple            : VAEntrypointVLD
      VAProfileMPEG2Main              : VAEntrypointVLD
      VAProfileVC1Simple              : VAEntrypointVLD
      VAProfileVC1Main                : VAEntrypointVLD
      VAProfileVC1Advanced            : VAEntrypointVLD
      VAProfileH264Main               : VAEntrypointVLD
      VAProfileH264High               : VAEntrypointVLD
      VAProfileH264ConstrainedBaseline: VAEntrypointVLD
      VAProfileHEVCMain               : VAEntrypointVLD
      VAProfileVP8Version0_3          : VAEntrypointVLD
      VAProfileVP9Profile0            : VAEntrypointVLD
      VAProfileAV1Profile0            : VAEntrypointVLD
      VAProfileHEVCMain10             : VAEntrypointVLD
      VAProfileHEVCMain12             : VAEntrypointVLD
      VAProfileVP9Profile2            : VAEntrypointVLD
      VAProfileHEVCMain444            : VAEntrypointVLD
      VAProfileHEVCMain444_10         : VAEntrypointVLD
      VAProfileHEVCMain444_12         : VAEntrypointVLD
     14799.754066826 [420891-420891] ../src/vabackend.c:2095              nvTerminate Terminating 0xbee50c0
     14799.754485191 [420891-420891] ../src/vabackend.c:2109              nvTerminate Now have 0 (0 max) instances
> nvidia-smi
Thu Apr 24 15:35:52 2025
+-----------------------------------------------------------------------------------------+
| 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 RTX 3080 Ti     Off |   00000000:01:00.0  On |                  N/A |
|  0%   60C    P2            126W /  400W |    2300MiB /  12288MiB |      8%      Default |
|                                         |                        |                  N/A |
+-----------------------------------------+------------------------+----------------------+

+-----------------------------------------------------------------------------------------+
| Processes:                                                                              |
|  GPU   GI   CI        PID   Type   Process name                              GPU Memory |
|        ID   ID                                                               Usage      |
|=========================================================================================|
|    0   N/A  N/A      2296      G   /run/current-system/sw/bin/Hyprland          1295MiB |
|    0   N/A  N/A      2333      G   ghostty                                        69MiB |
|    0   N/A  N/A      2378      G   Xwayland                                        5MiB |
|    0   N/A  N/A    417726      G   ...irefox-137.0.1/bin/.firefox-wrapped        323MiB |
|    0   N/A  N/A    424091      C   ...firefox-137.0.1/lib/firefox/firefox        430MiB |
+-----------------------------------------------------------------------------------------+

Still having some issues, when watching videos I get:

src/gbm_drv_common.c:131: GBM-DRV error (get_bytes_per_component): Unknown or not supported format: 943212370

Edit: maybe driver issue? A lot of videos (temporarily) freeze at start while the audio is playing correctly · Issue #369 · elFarto/nvidia-vaapi-driver · GitHub