Force using nvidia GPU

Hi there,

I have an issue with my laptop that I can’t seem to get my head around.

I own a Dell XPS 15 7590 which have an integrated GPU and a discrete NVIDIA GPU:

$ nix shell 'nixpkgs#pciutils' -c lspci -k | grep -iEA2 'vga|3d'
00:02.0 VGA compatible controller: Intel Corporation CoffeeLake-H GT2 [UHD Graphics 630] (rev 02)
	DeviceName:  Onboard IGD
	Subsystem: Dell Device 0905
--
01:00.0 3D controller: NVIDIA Corporation TU117M [GeForce GTX 1650 Mobile / Max-Q] (rev a1)
	Subsystem: Dell Device 0905
	Kernel driver in use: nvidia
	Kernel modules: nvidiafb, nouveau, nvidia_drm, nvidia
02:00.0 PCI bridge: Intel Corporation JHL6340 Thunderbolt 3 Bridge (C step) [Alpine Ridge 2C 2016] (rev 02)
	Subsystem: Dell Device 0905

I followed the wiki to configure my drivers and NVIDIA Prime.

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

hardware = {
  opengl = {
    enable = true;
    driSupport = true;
    driSupport32Bit = true;
  };

  nvidia = {
    modesetting.enable = true;
    open = false;
    nvidiaSettings = true;
    package = config.boot.kernelPackages.nvidiaPackages.production;

    powerManagement = {
      enable = true;
      finegrained = false;
    };

    prime = {
      intelBusId = "PCI:0:2:0";
      nvidiaBusId = "PCI:1:0:0";
      offload.enable = false;
      sync.enable = true;
    };
};

I have two external monitors:

  • iiyama GB3467WQSU-B5
  • Acer Predator XB271HUABMIPRZ

Both monitors are connected to my laptop and they work fine, however their maximum refresh rate (165Hz) is not available in xrandr:

DP-1 connected 3440x1440+0+0 (normal left inverted right x axis y axis) 800mm x 330mm
   3440x1440     59.94*+
   1920x1440     59.90  
   1600x1200     59.87  
   1440x1080     59.87  
   1400x1050     59.86  
   1280x1024     59.89  
   1280x960      59.94  
   1152x864      59.78  
   1024x768      59.68  
   800x600       59.86  
   640x480       59.38  
   320x240       59.52  
   1920x1200     59.88  
   1680x1050     59.95  
   1440x900      59.89  
   1280x800      59.81  
   1152x720      59.75  
   960x600       59.63  
   928x580       59.88  
   800x500       59.50  
   768x480       59.90  
   720x480       59.71  
   640x400       59.20  
   320x200       58.96  
   2560x1440     59.91  
   2048x1152     59.90  
   1920x1080     59.96  
   1600x900      59.95  
   1368x768      59.88  
   1280x720      59.86  
   1024x576      59.90  
   864x486       59.92  
   720x400       59.55  
   640x350       59.77  
DP-3 connected 2560x1440+3440+0 (normal left inverted right x axis y axis) 600mm x 340mm
   2560x1440     59.91*+
   1920x1440     59.90  
   1600x1200     59.87  
   1440x1080     59.87  
   1400x1050     59.86  
   1280x1024     59.76  
   1280x960      59.94  
   1152x864      59.78  
   1024x768      59.68  
   800x600       59.86  
   640x480       59.38  
   320x240       59.52  
   1920x1200     59.88  
   1680x1050     59.85  
   1440x900      59.89  
   1280x800      59.81  
   1152x720      59.75  
   960x600       59.63  
   928x580       59.88  
   800x500       59.50  
   768x480       59.38  
   720x480       59.71  
   640x400       59.20  
   320x200       58.96  
   2048x1152     59.90  
   1920x1080     59.88  
   1600x900      59.82  
   1368x768      59.88  
   1280x720      59.86  
   1024x576      59.90  
   864x486       59.45  
   720x400       59.55  
   640x350       59.77  
eDP-1 connected primary 1920x1080+1520+1440 (normal left inverted right x axis y axis) 340mm x 190mm
   1920x1080     59.88*+
   1440x1080     59.87  
   1400x1050     59.86  
   1280x1024     59.89  
   1280x960      59.94  
   1152x864      59.78  
   1024x768      59.68  
   800x600       59.86  
   640x480       59.38  
   320x240       59.52  
   1680x1050     59.95  
   1440x900      59.89  
   1280x800      59.81  
   1152x720      59.75  
   960x600       59.63  
   928x580       59.88  
   800x500       59.50  
   768x480       59.90  
   720x480       59.71  
   640x400       59.20  
   320x200       58.96  
   1600x900      59.95  
   1368x768      59.88  
   1280x720      59.86  
   1024x576      59.90  
   864x486       59.92  
   720x400       59.55  
   640x350       59.77

I’m using Gnome as my window manager, and in the Display settings I cannot change the refresh rate of any monitor at all:



I can see my GPU is available in nvidia-settings:

And it is also usable as a Docker container is using it:

mars 18 10:57:35 g-xps systemd[1]: Started docker-tabby.service.
mars 18 10:57:35 g-xps docker-tabby-start[18751]: 2024-03-18T09:57:35.809784Z  INFO tabby::serve: crates/tabby/src/serve.rs:103: Starting server, this might takes a few minutes...
mars 18 10:57:35 g-xps docker-tabby-start[18751]: ggml_init_cublas: GGML_CUDA_FORCE_MMQ:   no
mars 18 10:57:35 g-xps docker-tabby-start[18751]: ggml_init_cublas: CUDA_USE_TENSOR_CORES: yes
mars 18 10:57:35 g-xps docker-tabby-start[18751]: ggml_init_cublas: found 1 CUDA devices:
mars 18 10:57:35 g-xps docker-tabby-start[18751]:   Device 0: NVIDIA GeForce GTX 1650, compute capability 7.5
mars 18 10:57:37 g-xps docker-tabby-start[18751]: 2024-03-18T09:57:37.056435Z  INFO tabby::routes: crates/tabby/src/routes/mod.rs:35: Listening at 0.0.0.0:8080

I know that when I was using Arch I could use prime-select to “force select” the NVIDIA GPU so that all applications would use it, but I can’t find a way to do that on NixOS and also I can’t find the prime-select package.

So, in the end I have two questions:

  1. Does anyone have a clue as to how I should configure my system in order to be able to use my monitors at their maximum refresh rate?
  2. How should I configure my system to do the exact opposite of the Prime offload mode: always rely on the discrete GPU to run my applications?

Thanks for any input!

Did you get this fixed?

Having the same issue. Integrated gpu being used instead of discrete gpu.

When I switch from wayland to x11 everything seems to work though, just not on wayland…

Sadly no, I didn’t get this fixed. Neither did I bother to try it on x11 instead of wayland. But since wayland is the future (afaik), I don’t think it’s a good enough solution for me.

That being said, I’m currently in the process of rewriting my whole configuration and found that nixos-hardware provides a profile to disable Intel GPU.

Don’t know if this could help you, but I will try it once my new configuration is ready.

Please let me know if you try this before I do!

That is neat, I probably won’t be trying it before you do since I did seem to get the discrete gpu to work at least partly, but do let me know your findings.

I gave up on trying to get it to work and decided to update to kde 6 since its default is wayland.
This seemed to get the discrete gpu working for everything window/plasma related, which is good enough for me.
Youtube videos are still being hardware accelerated by the intel gpu it seems but apart from that it seems to be working, although I haven’t tried gaming yet.

I was finally able to test the Intel GPU disabling!

First, I had an issue with the nixos-hardware profile I previously linked. It defines two options:

  • boot.blacklistedKernelModules = mkDefault [ "i915" ]
  • boot.kernelParams = mkDefault [ "i915.modeset=0" ]

Those options, once evaluated, didn’t contain these strings… I suspect that this is related to priorities since mkDefault is used to define the options.

Therefore I set these options myself in my configuration and checked that they were defined as expected once evaluated. They were!

I switched and everything worked fine, but when running glxgears I didn’t see any changes in “GPU Utilization” in nvidia-settings! After a reboot and typing my luks password the screen kept stuck… I never made it to the login screen.

So, sadly, this doesn’t fix the issue.

I’m gonna keep looking, but I really don’t understand why the GPU is not used rn.