Hardware acceleration on chromium with nvidia

I’ve been struggling for the past couple of days with getting my nvidia, hyprland, nixos setup to run properly and in doing so I’ve unfortunately not been successful. I am running a tuxedo stellaris laptop with both intel i9-13900HX as well as an NVIDIA 4070. Here are the problems I am facing:

if I am using iGPU i am able to make Hyprland use the graphics of my iGPU and hardware acceleration works as expected. Unfortunately I then run into the issue that Hyprland is not able to detect my display. Running the same setup with KDE under wayland everything works as expected. running this under sway with --use-unsupported-gpu works, but has crazy flickering.

Now since I cannot seem to be going the iGPU route I figured I was going to try to go the route of using a dGPU as at this point I mostly just want it to be running somehow. Switching the bios to dGPU makes the external monitors work and Hyprland as well as chromium now have to run under with the nvidia GPU. this works fine on Hyprland, but chromium seems to not properly know what to do. I’ve checked multiple places like Chromium - NixOS Wiki to try and get some intel on this. My current configuration looks like this:

nixpkgs.config.packageOverrides = pkgs: {
    vaapiIntel = pkgs.vaapiIntel.override { enableHybridCodec = true; };
  };

  # Enable OpenGL
  hardware.opengl = {
    enable = true;
    driSupport = true;
    driSupport32Bit = true;
    extraPackages = with pkgs; [
      # trying to fix `WLR_RENDERER=vulkan sway`
      vulkan-validation-layers
      # https://nixos.wiki/wiki/Accelerated_Video_Playback
      intel-media-driver # LIBVA_DRIVER_NAME=iHD
      vaapiIntel         # LIBVA_DRIVER_NAME=i965 (older but works better for Firefox/Chromium)
      vaapiVdpau
      libvdpau-va-gl
    ];
  };

  hardware.nvidia = {

    # Modesetting is required.
    modesetting.enable = true;

    # Nvidia power management. Experimental, and can cause sleep/suspend to fail.
    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;

    prime = {
      offload = {
        enable = true;
        enableOffloadCmd = true;
      };
      #reverseSync.enable = true;
      intelBusId = "PCI:0:2:0";
      nvidiaBusId = "PCI:1:0:0";
    };
  };

i only included the relevant parts here. my config files can be found here

I have also tried a combination of using prime.sync instead of offload as only the dGPU is available anyways without any luck. This is the output of nvidia-smi:

Thu Nov 30 13:35:23 2023
+---------------------------------------------------------------------------------------+
| NVIDIA-SMI 545.29.02              Driver Version: 545.29.02    CUDA Version: 12.3     |
|-----------------------------------------+----------------------+----------------------+
| 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 4070 ...    Off | 00000000:01:00.0  On |                  N/A |
| N/A   41C    P5               9W / 115W |    613MiB /  8188MiB |      4%      Default |
|                                         |                      |                  N/A |
+-----------------------------------------+----------------------+----------------------+

+---------------------------------------------------------------------------------------+
| Processes:                                                                            |
|  GPU   GI   CI        PID   Type   Process name                            GPU Memory |
|        ID   ID                                                             Usage      |
|=======================================================================================|
|    0   N/A  N/A     57092      G   alacritty                                    23MiB |
|    0   N/A  N/A     77164      G   /run/current-system/sw/bin/Hyprland         381MiB |
|    0   N/A  N/A     79871      G   alacritty                                    29MiB |
|    0   N/A  N/A     81549      G   alacritty                                    21MiB |
|    0   N/A  N/A     89350      G   alacritty                                    21MiB |
+---------------------------------------------------------------------------------------+

I do however think that it is related to a faulty driver installation of some kind as running the command:

 nix-shell -p libva-utils --run vainfo

results in this output:

Trying display: wayland
libva info: VA-API version 1.18.0
libva info: User environment variable requested driver 'nvidia'
libva info: Trying to open /run/opengl-driver/lib/dri/nvidia_drv_video.so
libva error: dlopen of /run/opengl-driver/lib/dri/nvidia_drv_video.so failed: /nix/store/whypqfa83z4bsn43n4byvmw80n4mg3r8-glibc-2.37-45/lib/libc.so.6: version `GLIBC_2.38' not found (required by /run/opengl-driver/lib/dri/nvidia_drv_video.so)
libva info: Trying to open /usr/lib/dri/nvidia_drv_video.so
libva info: Trying to open /usr/lib32/dri/nvidia_drv_video.so
libva info: Trying to open /usr/lib/x86_64-linux-gnu/dri/nvidia_drv_video.so
libva info: Trying to open /usr/lib/i386-linux-gnu/dri/nvidia_drv_video.so
libva info: va_openDriver() returns -1
vaInitialize failed with error code -1 (unknown libva error),exit

output of ldd --version

ldd (GNU libc) 2.38
Copyright (C) 2023 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Written by Roland McGrath and Ulrich Drepper.

It looks like it is unable to find the correct GLIBC, but I have no idea how to fix that. I would highly appreciate if anybody would be able to give me a lead!

Hey welcome!

There is something that is a little unclear to me

if I am using iGPU i am able to make Hyprland use the graphics of my iGPU and hardware acceleration works as expected. Unfortunately I then run into the issue that Hyprland is not able to detect my display.

What do mean you can make Hyprland use the your iGPU but it doesn’t detect the display? How are you using the iGPU without display?

It looks like it is unable to find the correct GLIBC, but I have no idea how to fix that.

Which version of NixOS are you on right now?

Hey there!

Thank you very much for reaching out!
What do mean you can make Hyprland use the your

iGPU but it doesn’t detect the display? How are you using the iGPU without display?

So If I am running with the BIOS Setting of iGPU only the integrated monitor of my laptop works. also when I am running the command nvidia-smi I can see that nothing is running through the GPU as it is in offload mode, which is what I would expect.

Which version of NixOS are you on right now?

I am a bit unsure about that tbh, as my nixos journey isn’t that old. but the output of nix-info -m is -

system: `"x86_64-linux"`
 - host os: `Linux 6.1.63, NixOS, 24.05 (Uakari), 24.05.20231124.5a09cb4`
 - multi-user?: `yes`
 - sandbox: `yes`
 - version: `nix-env (Nix) 2.18.1`
 - channels(luca): `"home-manager"`
 - channels(root): `"nixos-23.05, nixpkgs"`
 - nixpkgs: `/nix/var/nix/profiles/per-user/root/channels/nixos`

Also make note of my full configuration that can be found here

Okay, so you are on the unstable channel it appears.

So to reframe your problem:

Is it how to get the external display working with the intel iGPU on Hyprland?

Or do you want to run the dGPU and fix chromium with that?

I have an older Intel laptop (8th Gen) with an older Nvidia dGPU (MX250) and I only ever use that with the nividia-offload script for NixOS that you can find on the wiki. But I also rarely use external monitors with that laptop.

I would prefer to get iGPU running with Hyprland so that I do not need to worry about driver compatibility on wayland with nvidia as the experience hasn’t been very nice. Unfortunately from what I can tell in their FAQ Faq | Hyprland Wiki using a dGPU is the currently known workaround to get external monitors working. Therefore I decided not to prusue this route at least in this post.

Instead with the dGPU I figured I would be on a track that could be fixable as I can clearly see that nix-shell -p libva-utils --run vainfo is returning an error. Which leads me to believe that If I am capable of fixing this error it would also fix the hardware acceleration on chromium as this is an essential feature for me as I often have video calls and do screensharing and stuff.

I hope that clears it up a bit. Please let me know if anything is still unclear! Thank you very much

yes, unless you want to mainly use your laptop as a workstation I would strongly recommend going with the Intel iGPU for power efficiency reasons.

I am not sure the FAQ is up-to-date. Hyprland is moving fast so I would not bet on it. You might search through GitHub issues or join their Discord server to see if anyone has a config that works for a similar setup.

fix the hardware acceleration on chromium

So that is the issue? Well that might be an issue related to chromium itself. Depending on circumstances I suppose.

nix-shell -p libva-utils --run vainfo

On my AMD gpu desktop I get this output below. What do you get exactly?

Trying display: wayland
libva info: VA-API version 1.18.0
libva info: Trying to open /run/opengl-driver/lib/dri/radeonsi_drv_video.so
libva info: Found init function __vaDriverInit_1_18
libva info: va_openDriver() returns 0
vainfo: VA-API version: 1.18 (libva 2.18.1)
vainfo: Driver version: Mesa Gallium driver 23.0.3 for AMD Radeon Pro W6800 (navi21, LLVM 15.0.7, DRM 3.49, 6.1.55)
vainfo: Supported profile and entrypoints
      VAProfileMPEG2Simple            :	VAEntrypointVLD
      VAProfileMPEG2Main              :	VAEntrypointVLD
      VAProfileVC1Simple              :	VAEntrypointVLD
      VAProfileVC1Main                :	VAEntrypointVLD
      VAProfileVC1Advanced            :	VAEntrypointVLD
      VAProfileH264ConstrainedBaseline:	VAEntrypointVLD
      VAProfileH264ConstrainedBaseline:	VAEntrypointEncSlice
      VAProfileH264Main               :	VAEntrypointVLD
      VAProfileH264Main               :	VAEntrypointEncSlice
      VAProfileH264High               :	VAEntrypointVLD
      VAProfileH264High               :	VAEntrypointEncSlice
      VAProfileHEVCMain               :	VAEntrypointVLD
      VAProfileHEVCMain               :	VAEntrypointEncSlice
      VAProfileHEVCMain10             :	VAEntrypointVLD
      VAProfileHEVCMain10             :	VAEntrypointEncSlice
      VAProfileJPEGBaseline           :	VAEntrypointVLD
      VAProfileVP9Profile0            :	VAEntrypointVLD
      VAProfileVP9Profile2            :	VAEntrypointVLD
      VAProfileAV1Profile0            :	VAEntrypointVLD
      VAProfileNone                   :	VAEntrypointVideoProc

I will come back with my Intel / Nvidia laptop edit this post and add the output from there as well later.

Edit: So this I get for the integrated Intel drivers. But the nvidia ones don’t really get picked up with vainfo combined with nvidia-offload. Not sure why that is:

Trying display: wayland
libva info: VA-API version 1.20.0
libva info: Trying to open /run/opengl-driver/lib/dri/iHD_drv_video.so
libva info: Trying to open /usr/lib/dri/iHD_drv_video.so
libva info: Trying to open /usr/lib32/dri/iHD_drv_video.so
libva info: Trying to open /usr/lib/x86_64-linux-gnu/dri/iHD_drv_video.so
libva info: Trying to open /usr/lib/i386-linux-gnu/dri/iHD_drv_video.so
libva info: va_openDriver() returns -1
libva info: Trying to open /run/opengl-driver/lib/dri/i965_drv_video.so
libva info: Found init function __vaDriverInit_1_20
libva info: va_openDriver() returns 0
vainfo: VA-API version: 1.20 (libva 2.20.0)
vainfo: Driver version: Intel i965 driver for Intel(R) Kaby Lake - 2.4.1
vainfo: Supported profile and entrypoints
      VAProfileMPEG2Simple            :	VAEntrypointVLD
      VAProfileMPEG2Simple            :	VAEntrypointEncSlice
      VAProfileMPEG2Main              :	VAEntrypointVLD
      VAProfileMPEG2Main              :	VAEntrypointEncSlice
      VAProfileH264ConstrainedBaseline:	VAEntrypointVLD
      VAProfileH264ConstrainedBaseline:	VAEntrypointEncSlice
      VAProfileH264ConstrainedBaseline:	VAEntrypointEncSliceLP
      VAProfileH264Main               :	VAEntrypointVLD
      VAProfileH264Main               :	VAEntrypointEncSlice
      VAProfileH264Main               :	VAEntrypointEncSliceLP
      VAProfileH264High               :	VAEntrypointVLD
      VAProfileH264High               :	VAEntrypointEncSlice
      VAProfileH264High               :	VAEntrypointEncSliceLP
      VAProfileH264MultiviewHigh      :	VAEntrypointVLD
      VAProfileH264MultiviewHigh      :	VAEntrypointEncSlice
      VAProfileH264StereoHigh         :	VAEntrypointVLD
      VAProfileH264StereoHigh         :	VAEntrypointEncSlice
      VAProfileVC1Simple              :	VAEntrypointVLD
      VAProfileVC1Main                :	VAEntrypointVLD
      VAProfileVC1Advanced            :	VAEntrypointVLD
      VAProfileNone                   :	VAEntrypointVideoProc
      VAProfileJPEGBaseline           :	VAEntrypointVLD
      VAProfileJPEGBaseline           :	VAEntrypointEncPicture
      VAProfileVP8Version0_3          :	VAEntrypointVLD
      VAProfileVP8Version0_3          :	VAEntrypointEncSlice
      VAProfileHEVCMain               :	VAEntrypointVLD
      VAProfileHEVCMain               :	VAEntrypointEncSlice
      VAProfileHEVCMain10             :	VAEntrypointVLD
      VAProfileHEVCMain10             :	VAEntrypointEncSlice
      VAProfileVP9Profile0            :	VAEntrypointVLD
      VAProfileVP9Profile0            :	VAEntrypointEncSlice
      VAProfileVP9Profile2            :	VAEntrypointVLD

Thank you very much for sharing!

So for my workload I don’t really care if it is not power efficient. Mostly I want to get back to being productive even if that cost some energy. Most of the time I am in a docking station anyways. The output from nix-shell -p libva-utils --run vainfo is only

Trying display: wayland
libva info: VA-API version 1.18.0
libva info: User environment variable requested driver 'nvidia'
libva info: Trying to open /run/opengl-driver/lib/dri/nvidia_drv_video.so
libva error: dlopen of /run/opengl-driver/lib/dri/nvidia_drv_video.so failed: /nix/store/whypqfa83z4bsn43n4byvmw80n4mg3r8-glibc-2.37-45/lib/libc.so.6: version `GLIBC_2.38' not found (required by /run/opengl-driver/lib/dri/nvidia_drv_video.so)
libva info: Trying to open /usr/lib/dri/nvidia_drv_video.so
libva info: Trying to open /usr/lib32/dri/nvidia_drv_video.so
libva info: Trying to open /usr/lib/x86_64-linux-gnu/dri/nvidia_drv_video.so
libva info: Trying to open /usr/lib/i386-linux-gnu/dri/nvidia_drv_video.so
libva info: va_openDriver() returns -1
vaInitialize failed with error code -1 (unknown libva error),exit

and if I switch in BIOS from iGPU to dGPU i get a similar output to the one you shown before where also only the intel drivers are properly recognized. But as I stated above I would like to get nvidia to work and I thought that this error libva error: dlopen of /run/opengl-driver/lib/dri/nvidia_drv_video.so failed: /nix/store/whypqfa83z4bsn43n4byvmw80n4mg3r8-glibc-2.37-45/lib/libc.so.6: version `GLIBC_2.38’ not found (required by /run/opengl-driver/lib/dri/nvidia_drv_video.so)
would be something to start out from as clearly somehow a wrong glibc version is supplied somewhere, even tho the correct version is available on my system as seen in the ldd output. :confused: