Things can “work” and be suboptimal or have long-term risks
That’s my issue with a lot of the cargo culting around nvidia, people have subtly broken or problematic configurations and often don’t find out for months.
Feel free to also read my related rant here; If nothing else, it’ll show you some of the pitfalls you may fall into. This is precisely why I said it’s not that easy in the other thread, by the way, there is a lot of misinformation around ![]()
nvidia configuration on NixOS, especially for laptops, is quite broken.
Ok, this means you’re among the lucky population for whom multi-GPU just happens to work out of the box; wayland compositors reuse whichever GPU was used during boot (the so-called “boot-vga”), and use that as the “primary” GPU.
Since this entirely depends on firmware behavior, BIOS configuration and firmware updates, as well as quite random things (like whether you have an external display connected or are on AC power), can affect the choice of this GPU. Some firmwares always choose the dGPU, like for example the firmware for the laptop in this thread.
For this reason I’d recommend actually configuring this the way you want, instead of relying on the firmware to make the correct choice, but let’s get to that after we clean up your configuration, because there’s a lot to be desired here also.
So let’s review:
Don’t set this. Your plasma module does this. It has nothing to do with nvidia, people are just cargo culting it because someone with a silly setup needs it and associated it with their graphics driver, and it’s been copy-pasted by people ever since.
Set this to just [ "nvidia" ]. The modesetting driver should be loaded by the kernel automatically since it isn’t blacklisted, and not placing nvidia at the top can cause issues.
This should be true for any post-Turing GPU. People set this to false if they don’t understand the difference between nouveau and nvidia or if they have an old GPU or if they copy-paste without thinking from someone to whom one of those two things applies.
Don’t set this, it’s the default, and force-setting default values prevents upstream maintenance.
This is actually mostly sensible, though the default is false. It’s technically an experimental feature of the nvidia driver, but it persists GPU memory for GPUs with more than 256MB of onboard memory during sleep. Without it, if you’re running something on your GPU that needs more memory (like, any game these days), you’ll wake your system to a black screen. Particularly impactful on laptops which you might put to sleep by closing the lid, especially in hybrid sleep mode (since suspend-to-ram shouldn’t run into issues here).
It is experimental, but I’ve rarely seen people have issues with it, so I recommend keeping it on. It’s useful to understand what it does, though, so you know what to try disabling if you run into issues with sleep.
This should be completely useless since you are on wayland, it literally only sets xserver configuration which you’re not using (well, xwayland kinda does, but I believe that your compositor controls the GPU even for xwayland windows - I have not yet verified this since I’ve focused on reusing this module in my past attempts at fixing the nvidia module).
You’re also missing some configuration that would allow your system to properly suspend the GPU when not in use, so currently you’re wasting about 20W of power continuously.
So, in a nutshell, I’d replace your configuration with this:
# nvidia.nix
#
# *Specifically* for a 3050 ti in a system with an iGPU; don't reuse
# blindly unless you know what you're doing.
{
services.xserver.videoDrivers = [ "nvidia" ];
hardware.nvidia = {
open = true;
powerManagement = {
enable = true;
# *Not* experimental, unlike `powerManagement.enable`, it has
# nothing to do with sleep and it's actually broken by NixOS by
# default; see my rant
finegrained = true;
};
# You should at least try this with a PRIME setup
dynamicBoost.enable = true;
};
}
I’d also recommend putting this in a separate file (nvidia.nix as the comment says), and importing it in your configuration.nix’s imports, like hardware-configuration.nix. That just helps keep things separate.
While I’m at it, never play with the boot.kernelPackages option, as explained in my rant. If you want to prevent mistakes, or forgetting this in the future, add to the above nvidia.nix:
assertions = lib.singleton {
assertion =
lib.strings.compareVersions config.boot.kernelPackages.kernel.version pkgs.linuxKernel.kernels.linux_default.version
<= 0;
message = "The nvidia driver can only support the LTS kernel.";
};
You’ll also have to add { pkgs, config, lib, ... }: to the top of the module.
Caveat emptor: The nvidia driver is messy and this might not actually work or might have subtle bugs. I also don’t have a system with an intel GPU to test with, so I don’t know for sure if the modesetting driver behaves the same as amdgpu.
We may have to experiment a little, but in theory (according to the nvidia documentation) this is how your system should be configured - though we probably additionally want to force-set the primary GPU used by plasma once you’ve confirmed this works.
I don’t blame anyone for not having read the docs or experimented much, this driver is a PITA, but god do I wish people would stop assuming all setups can be configured the same, or that they know how it works just because they can get their system to boot.