Enabling NVIDIA makes graphics slower

I use NixOS on a Lenovo Thinkpad P1 Gen 2 (equivalent to X1 Extreme G2) with hybrid graphics (nvidia and intel).
When i activate the nvidia gpu with prime sync (or offloading, doesn’t change anything weirdly), in my configuration.nix like this:

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

  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;
  };

  hardware.nvidia.prime = {
    #sync.enable = true; # sync mode, gpu will stay active
    offload = {
      enable = true;
      enableOffloadCmd = true;
    };
    # Make sure to use the correct Bus ID values for your system!
    intelBusId = "PCI:0:2:0";
    nvidiaBusId = "PCI:1:0:0";
  };

The graphics overall get slower, gnome is a bit sluggish and hovering over fields changes their shade slower. The overall UX just feels worse. The GPU does get utilized tough. If i run nvidia-smi and run a 4k video in Firefox (which runs fine) i see GPU utilization and temp go up.

Altough if i disable the nvidia gpu by commenting out:

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

Gnome will feel faster and nicer to use which does not make sense to me.

Does anybody have some experience with this and could help me set this up to run smooth with both gpus? Help would be really appreciated.

Here is my full config:
configuration.nix: My nixos configuration.nix · GitHub
hardware-configuration.nix: hardware-configuration.nix · GitHub
nvidia-smi output: nvidia-smi · GitHub
System specs: neofetch · GitHub

I know this is a month late but I have a very similar issue. This is most likely because your laptop uses a MUXless design in which the GPU is wired in such a way that it passes the info into the intel gpu’s framebuffer which as you can guess makes it appear choppy and sluggish. As from your nvidia-smi output when your gpu is enabled, gnome is being started on the nvidia card which means everything is getting passed through the framebuffer. If you use a secondary display it may be less sluggish (if your hdmi and other outputs are wired to the gpu). Another thing you can try is using a de / wm such as hyprland and specifically forcing it to launch on the intel gpu then using something such as nvidia-offload when you want to do gpu intense loads. It’s not clean but it should work

1 Like

In the end i switched from Wayland to X which already made everything run way smoother. There was also a Bug in Gnome which has been fixed now iiuc.
Works better now but would be great if the Nvidia drivers would be compatible with Wayland, pretty sad that the 3rd biggest company [by market cap] in the world can’t develop a correctly functioning linux driver.

Might still need to

  • load intel too
  services.xserver.videoDrivers = [
    "nvidia"
    "intel"
  ];
  • enable opengl
  hardware.opengl = {
    enable = true;
    driSupport = true;
    driSupport32Bit = true;
  };
  • add boot module for
  boot.extraModulePackages = [
    config.boot.kernelPackages.nvidia_x11
  ];

Here’s my current config (some boot. options may not be needed):

{ config, ... }:

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

  boot.extraModulePackages = [
    config.boot.kernelPackages.nvidia_x11
  ];
  boot.blacklistedKernelModules = [
    "nouveau"
    "rivafb"
    "nvidiafb"
    "rivatv"
    "nv"
    "uvcvideo"
  ];
  services.xserver.videoDrivers = [
    "nvidia"
    "intel"
  ];

  hardware.nvidia = {
    package = config.boot.kernelPackages.nvidiaPackages.latest; # `latest` is `555.58.02` currently

    modesetting.enable = true;
    powerManagement.enable = true;
    powerManagement.finegrained = false;
    open = false;
    nvidiaSettings = true;

    prime = {
      intelBusId = "PCI:0:2:0";
      nvidiaBusId = "PCI:1:0:0";
    };
  };
}
1 Like

Thanks, will try your additional options.

in my case my issue was seemingly related to hyprland. Switching from it to sway fixed it for me so for now I just use sway on that laptop

Doesn’t that effectively disable all the improvements nvidia have been making to wayland support? Assuming it even does anything on modern drivers, I’d imagine it’s disabled given their modern drivers don’t even support GPUs without heavy firmware anymore.

Also disabling nvidia fb while enabling modesetting and forcing nvidia fb on the kernel command line seems like it’s not fully thought out. Unsure how that interacts with multi-gpu stuff, though.

Doesn’t that effectively disable all the improvements nvidia have been making to wayland support?

Also disabling nvidia fb while enabling modesetting and forcing nvidia fb on the kernel command line

Quite possible :joy:
I added some config in an attempt to fix some issues with Diablo 4 on Wayland from nvidia forum’s solutions / guesses (game would crash when changing settings, changing map location, randomly too sometimes, etc)
I ended up switching back to X11 and never encountered any issues so far while being able to running higher graph settings (which is a bit odd).
I haven’t changed config since then as it was “stable” enough for me at that time - will update in few days and update post above if needed.