There are 3 Nvidia Wiki pages for NixOS

I am trying to make a generic basic config (one size fits most) that others can use. The AMD and Intel configurations were really easy. But then I stumbled upon Nvidia, and discovered it was not going to be so easy, especially when there are 3 NVIDIA Wiki pages.

  1. Nvidia - NixOS Wiki
  2. NVIDIA - NixOS Wiki
  3. NixOS Manual

There was another source that tried to make sense of this here on the forums (cannot seem to find it now). But here is the code I am currently using.

I do not have an NVIDIA card, so I cannot test and confirm, anything. Which means, despite the amount of information (along with the contradictions), I freely admit, I may know nothing.

# ============
# 🖼️ NVIDIA GPU Support
# ============

# NVIDIA drivers are proprietary, but NixOS makes them easy to install.
# These are required for hardware acceleration and optimal performance.

# ⚠️ NOTE: Wayland support for NVIDIA is improving, but X11 still tends to offer better compatibility.
#          KDE Plasma works with both.

# 🔍 Tip: If you're unsure which driver version you need (some cards require legacy versions),
# visit: https://nixos.wiki/wiki/Nvidia

# đź’» For laptops with Intel and NVIDIA GPUs (Optimus support)
# hardware.nvidia.enable = true;  # Enable NVIDIA drivers for the NVIDIA GPU
# hardware.nvidia.prime.enable = true;  # Enable Optimus for switching between Intel and NVIDIA GPUs
# ⚠️ Do NOT enable modesetting for Optimus systems
# hardware.nvidia.modesetting.enable = true;  # This should be left commented out for laptops with Optimus

# 🖥️ For desktops with a single NVIDIA GPU
# hardware.nvidia.enable = true;  # Enable the NVIDIA drivers for the NVIDIA GPU
# hardware.nvidia.modesetting.enable = true;  # Enable modesetting for better performance
# âś… Uncomment the line below if you want to always use NVIDIA as the primary GPU
# services.xserver.videoDrivers = [ "nvidia" ];  # Make NVIDIA the default graphics card

# ⚙️ Optional: Use the stable version of NVIDIA drivers for reliability
# hardware.nvidia.package = config.boot.kernelPackages.nvidiaPackages.stable;

# ⚙️ Optional: Enable 32-bit libraries for older applications and games
# hardware.nvidia.package = pkgs.linuxPackages.nvidia_x11;


# END of Nvidia GPU Support
# ============

So a bit of a clarification of what each of those links are:

  1. The unofficial wiki
  2. The official wiki
  3. The manual

The unofficial wiki used to be “essentially” the “official” wiki, until in the past year we got the official wiki. The manual is just a manual which is tied to specific release channels.

5 Likes

#1 is basically dead, don’t use it.
#3 probably shouldn’t exist either?

#2 might be your best bet.

It gets worse; different NVIDIA cards need different configuration, they are often paired with iGPUs which add another layer of configuration, and the specific desktop environment you use changes how it needs to be configured. The driver version in use can also change things, and can cause simple updates to result in issues.

Since it’s a third party kernel module it also often just breaks for adventurous users who try non-default kernels. And this is before we start talking about the issues NVIDIA cards often cause for suspend… Hell, I’m fairly certain the existing NixOS modules have configuration that simply does not actually work (powermanagement.finegrained).

Using an NVIDIA GPU at all is almost certain to cause problems. Your configuration has some issues, and the wiki pages/manual are quite a mess too since it’s effectively just random users explaining the workarounds that happen to be effective on their systems.

For now, I would just stay away from recommending anything for NVIDIA at all without extensive testing on many systems. If you want to give people a comfortable ootb experience, ask them to use nouveau and accept the performance penalty, or use a different hardware vendor - NVIDIA have not been very good at supporting Linux.

2 Likes

It would be helpful if you pointed those out. I am not going to just ignore Nvidia users, and while I have no doubt the configuration for Nvidia may not be perfect for everyone, I would like a generic setup that could work for most.

I suppose if worse came to worst, I could just leave it with this setting as the standard option since it would provide the default, stable drivers.

# ⚙️ Optional: Use the stable version of NVIDIA drivers for reliability
# hardware.nvidia.package = config.boot.kernelPackages.nvidiaPackages.stable;

My main issues are your comments regarding the package version.

That’s the NixOS default, so I would not define it at all: hardware.nvidia.package

Your comment implies that the stable driver is not the default, so that’s misleading.

That comment simply does not apply to that line. You need hardware.graphics.enable32Bit, but you don’t need to enable it manually most of the time - steam enables it by default, so it’s only useful if you’re going to be running wine manually.

You’re also missing the hardware.nvidia.open option, so any user who uses this config will get a confusing message about a missing setting.

Furthermore, your optimus config will not work on wayland because it only sets it up on X11, so on modern Gnome it won’t do anything. You’re missing the nvidia-offload command or any explanation about how to use it anyway, so it’s not going to be doing anything. Since you also do not enable the powermanagement, this just results in the nvidia GPU being turned on uselessly and burning battery. Not that the powermanagement features work IME.

… I could go on, there’s just a lot of context you need when trying to use NVIDIA on Linux.

I’ve been working on a module that intends to guide people through all this by taking an opinionated approach and just offering simple options that tell the module what your hardware/software combination is. But I still need to work on getting the wayland configuration set in a programmable way, and fix whatever is causing the issues with powermanagement upstream. And then presumably go through a lot of bugfixing when others start using it and showing me how broken these drivers are - I’ve seen a lot of issues on this discourse, too many to have remembered all the workarounds.

… and I’m not even touching the legacy drivers. I’m of the opinion that NVIDIA GPUs that aren’t covered by the latest stable driver are simply unusable on a modern Linux system, and that you should not even attempt it.

5 Likes

Wonderful. So it’s not that I had not enough information, it is I had too much, and conflicting. lol - Sometimes you have to laugh at yourself.

I thank you for your pointers, and I will try to, once again, generate a more working config.

edit: I should add that I recommend people use the Flatpak version of Wine and Steam. I have found it to be more stable and universally applied.

I used to use the flatpak version. I would not recommend it on NixOS. There are many little integration details that don’t play well with the xdg portals, resulting in a frustrating experience.

Can you please be a little more specific? I do not notice any issues and have been using them for months. Perhaps, I have yet to stumble upon them?

With the exception of some fontconfig issues, I’ve found flatpak steam to generally work better.

1 Like

I think this will be my basic config for a one-size-fits-most solution.

# ============
# 🖼️ NVIDIA GPU Support
# ============

# NVIDIA drivers are proprietary, but NixOS makes them easy to install.
# These are required for hardware acceleration and optimal performance.

# ⚠️ NOTE: Wayland support for NVIDIA is improving, but X11 still tends to offer better compatibility.
#          KDE Plasma works with both.

# 🔍 Tip: If you're unsure which driver version you need (some cards require legacy versions),
# visit: https://wiki.nixos.org/wiki/NVIDIA

# đź’ˇ Uncomment the lines below to enable NVIDIA driver support.

# ✅ Basic setup — uncomment to enable NVIDIA drivers
# hardware.nvidia.enable = true;

# âś… Enable nvidia-settings, NVIDIA's GUI configuration tool
# hardware.nvidia.nvidiaSettings = true;

# âś… Optional: Enable 32-bit libraries (needed for older apps and games)
# # hardware.graphics.enable32Bit = true;

# âś… Optional: Enables NVIDIA's built-in modesetting
# ⚠️ Do NOT enable modesetting for Optimus systems
# hardware.nvidia.modesetting.enable = true;

# END of Nvidia GPU Support
# ============

^ I should add before anyone comments.

I’m not worried about open source drivers or power management. Just to enable the drivers and allow the user access to the generic settings. If they want to dig deeper or need more, they can explore that on their own, and I link to the Wiki where they can obtain that information.

1 Like

Steam has lots of interaction with the host outside of simple game launching features. Various big picture mode features will not work and steam controller configuration doesn’t connect properly with the flatpak version. I think that’s the detail that made me finally switch to the NixOS version.

It also is quite difficult to get mangohud/gamescope to work once you’re in a flatpak, though I believe there are extensions on the flatpak side for that these days? I think I ran into issues with GPU drivers (typical), too, but it’s been a good year or two.

I’ve not had any issues whatsoever since switching to the NixOS version, so my experience is the exact opposite of yours. Would be interesting to know what the NixOS module can do better, honestly.

You still have to select either the open or proprietary driver version, or nix will throw an eval error because the option is not configured. Since NVIDIA recommends the open driver, you should enable the open driver. This has nothing to do with nouveau by the way, and is actually the official, NVIDIA-developed kernel module which enables all the functionality of your GPU - it even has more functionality than the proprietary version at this point, AIUI.

Basically, you must set hardware.nvidia.open, and setting it to false is wrong, I don’t know why the module still makes you pick and doesn’t just set it to true by default so I can stop explaining this all the time. I should just push up a PR to fix that.

nvidia-settings is also enabled by default, and I’d just completely remove the comment about optimus systems, since it might make someone think this does do offload correctly - if anything, recommend that people look up details on a wiki if they want to do GPU offload or something, and just have the general purpose config be NVIDIA-only, if you don’t care about power management.

That said, IME people are often immediately upset about comparatively poor battery life on Linux and will be turned away from the platform by this kind of thing, so I’d personally prioritize that much more highly.

I also have to say, I question the wisdom of writing configurations that are supposed to be plug-and-play with neither the hardware to test them nor even checking if they will evaluate. You can at least check if the config works without installing anything by running nixos-rebuild build.

3 Likes

Where did you get that from, out of interest? The upstream nvidia module explicitly enables modesetting if offload is enabled: nixpkgs/nixos/modules/hardware/video/nvidia.nix at d6db763e76b550834bb9594a9edf6bf44389955e · NixOS/nixpkgs · GitHub

Better testing? idk. This oneliner broke steam for me: buildFHSEnvBubblewrap: bind /etc/dconf by michaelBelsanti · Pull Request #369279 · NixOS/nixpkgs · GitHub

I didn’t feel like micromanaging the NixOS steam module longterm, after basically doing so for half a year. If I play games, it’s not to give myself more busywork :slight_smile: The in-tree (intel) drivers work fine, never saw issues with big picture mode or remote play. Gamescope didn’t work for me on the nixpkgs steam either, so no loss for me there.

1 Like

The open source kernel modules are only supported by GPUs of Turing architecture or newer [1] [2]. I have a Maxwell GPU, so have to set hardware.nvidia.open to false.


  1. NVIDIA Transitions Fully Towards Open-Source GPU Kernel Modules | NVIDIA Technical Blog ↩︎

  2. GitHub - NVIDIA/open-gpu-kernel-modules: NVIDIA Linux open GPU kernel module source ↩︎

2 Likes

I’m not suggesting the option should be removed, having it be required just adds confusion. It’s no different from the .package option being required for legacy cards, but having a default value that makes sense for all those users who use GPUs actually still supported by the vendor.

Really, a map of GPU names to some kind of option set would make more sense, but I suppose that’s firmly in nixos-hardware territory.

1 Like

Fair enough, I suppose bugs due to changes on NixOS happen; I don’t see a reason the same would not happen when a mistake is made in the flatpak world, though, this seems like the kind of thing that using a different packaging solution doesn’t actually solve.

In the general case, you’re correct; however with steam specifically, I don’t know enough to fix the issues with the steam nixpkgs package and NixOS module, but I believe they stem from the hacks nixpkgs uses to handle FHS envs in the first place along with some of the change management issues that I find unique to nixpkgs. I found that the flatpak version gave me a higher chance of just-working, though as you say that may just be luck, but I recall having to deal with new issues every few weeks with the nixpkgs steam that I simply don’t have to think about anymore.