Graphics unworkable with 22.11 + Optimus + NVidia

Graphics on my Lenovo W520, although basically working (I’m typing this on the W520), are unsatisfactory:

  1. X is running at 16% to 98% of one core and the machine is slow and the fan runs continually.
  2. One screen (DP, 4k) blinks every 10 seconds or so.
    Here’s the relevant config.:
{ config, pkgs, lib, ... }:

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

	hardware.nvidia.package = config.boot.kernelPackages.nvidiaPackages.legacy_390;

	# For nvidia
	nixpkgs.config.allowUnfree = true; = {
		# offload.enable = true;
		sync.enable = true;

		# Bus ID of the NVIDIA GPU. You can find it using lspci, either under 3D or VGA
		nvidiaBusId = "PCI:1:0:0";

		# Bus ID of the Intel GPU. You can find it using lspci, either under 3D or VGA
		intelBusId = "PCI:0:2:0";

What can I do?

You have to wrap the Parameters into a executable like in this tutorial. Im using a lenovo to and only worked after I did that. Nvidia - NixOS Wiki
After that every app you need to use the GPU you have to add the prefix nvidia-offload

Sorry but I don’t understand. I’ve read that NVidia page but it covers many circumstances and configurations. What Parameters? and you have to prefix every app. with nvidia-offload? That’s unworkable surely as it means the GUI menu is useless and you have to run everything from a command window.

You dont need run every app from dedicated GPU, only the one you need, but yes you need prefix it. If you need run a app from a gnome menu for example just edit the *.desktop or *.application with the nvidia-offload and done. About the configuration here a example

OK, I’ve updated my configuration but I still think it’s not right. The laptop is still rather sluggish and the fans run most of the time while it’s idling. However, there’s no heavy usage visible in top, which makes me think drivers are responsible for hammering the CPU.
Is there anything still obviously wrong in my configuration?

Is it possible to add the export declarations to the display-manager.service file so that they are available to any application launched from the desktop?

There are three modes available:

  1. sync - Uses only the NVIDIA GPU for rendering. This means rendering can only happen on screens which the NVIDIA GPU has access to. Since only the NVIDIA GPU is used, the nvidia-offload script is not needed.
  2. offload - Uses the non-NVIDIA GPU for rendering by default and only uses the NVIDIA GPU when instructed. The environment variables set by the nvidia-offload script is what instructs the rendering to be done by the NVIDIA GPU, which will do it’s thing and hands off the final rendering to the primary GPU for rendering to the screen. In this mode, only one screen can be used.
  3. reverse prime (not available on 22.11) - The primary GPU is used for rendering and supports multiple screens by allowing access to screens only connected to the NVIDIA GPU. It’s my understanding that only content rendered on the screen connected to the NVIDIA GPU can be rendered with the NVIDIA GPU.

I tried switching to = true; but the rebuild reported that it’s available only for versions >= 435.21.

According to NVIDIA’s documentation the legacy 390 driver supports prime: Chapter 17. Using the NVIDIA Driver with Optimus Laptops

I don’t know why there’s an assertion requiring the 435 driver. I found the commit which implements prime: nixos/nvidia: implement prime render offload · NixOS/nixpkgs@026b601 · GitHub

But I was unable to find a PR discussing it’s implementation.

Hmm, so it might be end-of-the-road for NixOS on this laptop. I wonder if it’s possible to have the 435 decision reviewed. I suppose I should raise a PR about it.

You can use a modified copy of the module to see if PRIME works with the 390 driver. If it does, then it makes sense to open a PR about it.

The feature was release on that driver version, I would not expect it to work on a driver version older than that.

Prime Render Offload that is.

What about the Nouveau drivers? How would I use those instead?

Sorry to ask to be spoon-fed but I just do not have time to dive into this myself.