So, you can in theory do this. But it’s probably best to fully explain why this is so hard and why nobody in their right mind should buy nvidia GPUs when they intend to use a Linux system (no offense, I’ve known this for over a decade and still repeated that mistake just a few years ago).
The nvidia driver is a third-party kernel module. What this means is that it’s a bit of code that is not part of the Linux kernel, but prepared in such a way that it is loaded into the Linux kernel as foreign code at boot time.
This means that it is not tied to the Linux release schedule, and the kernel is developed entirely without care for what happens to the nvidia driver. It could not be made to care even if that was desired, the nvidia driver makes effectively arbitrary changes to the kernel. Even more so because the nvidia driver is proprietary, and has a habit of borderline-infringing on kernel copyright (though admittedly, there’s also an open kernel module now, which is a tiny step in the right direction).
These kinds of issues don’t happen at all with in-kernel drivers, like the official AMD and intel drivers, as well as nouveau
(the driver for nvidia cards developed by third party FOSS developers, who have historically been almost unable to get power management - and therefore anything more than the bare minimum rendering capability - to work; this is currently improving a bit).
Linux distributions end up having to pick up the pieces of this mismatch. After all, the average user would not be able to pick versions of the Linux kernel and nvidia driver that work together, let alone compile them and get them prepared to actually run. Nor should they be expected to, doing so would be incredibly tedious.
Nvidia doesn’t particularly care, of course, distro maintainers effectively work for free for them to make their hardware usable. Without distro maintainers, it’s unlikely anyone would have cared about Linux for use with their GPUs in the first place, so they don’t have much leverage.
What does this mean for you in practice? Well, the NixOS maintainers need to be careful to make sure that a specific version of Linux works with a specific version of the nvidia driver. There aren’t many such maintainers. As a result, updates are far from instant, especially on the stable channels, because nvidia also doesn’t have any clear stability guarantees for updates.
The build system for the nvidia driver version is also quite complex. As such, it’s not trivial to find the current nvidia driver version on search.nixos.org. I typically just look at the package definitions for my current nixpkgs branch.
This is the current beta definition for nixos-23.11
(stable): https://github.com/NixOS/nixpkgs/blob/6832d0d99649db3d65a0e15fa51471537b2c56a6/pkgs/os-specific/linux/nvidia-x11/default.nix#L59
And this is the one for nixos-unstable
: https://github.com/NixOS/nixpkgs/blob/f8e2ebd66d097614d51a56a755450d4ae1632df1/pkgs/os-specific/linux/nvidia-x11/default.nix#L59
Note that the discourse bot will automatically change those links to be permalinks, if you want to see up-to-date files in the future you will need to manually select the correct branch.
As you see, nixos-unstable
currently has the version of the driver you’re looking for. So switching to unstable and using the beta driver will give you what you want.
You can in also override the package version as you see fit. I often do this because - in addition to being horrible to package and work with - nvidia’s drivers are also often very buggy, especially if you use wayland. In simple cases, that’d look something like this:
hardware.nvidia = {
package = config.boot.kernelPackages.nvidiaPackages.beta.overrideAttrs (old: let
version = "550.40.07";
in {
src = pkgs.fetchurl {
url = "https://download.nvidia.com/XFree86/Linux-x86_64/${version}/NVIDIA-Linux-x86_64-${version}.run";
sha256 = "";
};
});
};
YMMV though, as the actual build instructions might not work with any old nvidia driver version.
Hope that wasn’t too much of an information dump, and sorry for the bad news. I should start an nvidia-on-NixOS support group.