In nixos 21.11, problems with legacy nvidia drivers and linux kernel 5.15

Hey Nixos discourse users, I am new here and I am new to Nixos. I am having a very noobie (if that is a word) problem with my Nixos system.

To put it shortly, since the upgrade to Nixos 21.11 I have been looking to access the newer kernel (5.15 to be exact) through the use of: linuxKernel.packages.linux_5_15.nvidia_x11_legacy340

I had previously used this method of using legacy drivers: services.xserver.videoDrivers = [ "nvidia"];
hardware.nvidia.package = config.boot.kernelPackages.nvidiaPackages.legacy_340;

boot.kernelPackages = pkgs.linuxPackages_5_4;

and there is nothing wrong with it, I just kinda want the newer kernel for reasons I don’t understand to be honest. As I am new I do not understand the syntax for the configuration.nix as well as i would like too so please help me install this new linux kernel with the legacy drivers as well!

Thanks to any responses/help :slight_smile:

TLDR: Please help me install this package: linuxKernel.packages.linux_5_15.nvidia_x11_legacy340
as I would like to use the newer linux kernel.

1 Like

You want to set services.xserver.videoDrivers not to nvidia, but to nvidiaLegacy340, as documented in the example there.

That will correctly set hardware.nvidia.package for your kernel version, and you can just stop specifying the kernel at all so you automatically pick the latest supported by NixOS.

As a word of warning, you may run into tons of breakage if you try linuxPackages_latest. I only try to help maintain the non-legacy nvidia, and that one already breaks on newer kernels often enough.

Hey, thanks for the quick response.

I have previously tried this (sorry I should have specified) and received this result during the building of the system configuration.
error: Selecting an nvidia driver has been modified for NixOS 19.03. The version is now set using `hardware.nvidia.package`.

But thank you again for the quick response

Well, I’ll be, I thought it went the other way around, my bad!

I assume you’ve simply tried:

hardware.nvidia.package = config.boot.kernelPackages.nvidia_x11_legacy340;

Edit: Nevermind, I think I got the attributes right the first time; Haven’t tested it though.

?

config.boot.kernelPackages should resolve to whichever linux kernel version you have set, and all kernel package sets have an nvidia_x11_legacy340 attribute (i.e., the package you want to install).

At that point setting either of these should do the trick:

# If you want the latest kernel always (will result
# in occasional breakage)
boot.kernelPackages = pkgs.linuxPackages_latest;
# If you want specifically 5.15, and are ok staying
# on that version until you manually upgrade
boot.kernelPackages = pkgs.linuxKernel.packages.linux_5_15;

Hmm

Thank you for the quick response, after running it with your most recent recommendations I encountered problems with the building of the nvidia-340 drivers. Correct me if I am wrong but I believe this is because of the fact that the nvidia-340 drivers only support 5.4 lts and below kernel versions without significant patches.

However I am lead to believe that this package:

linuxKernel.packages.linux_5_15.nvidia_x11_legacy340

could be the fix to that / it may contain all the necessary patches. How do you recommend I implement this package/driver into my system?
Thanks

You’re already using that package then :slight_smile: The build failures stem from the fact that the legacy340 driver cannot run on Linux 15.5. It is still automatically packaged for all Linux kernels, nix will simply try to build the package on the fly for you - and inevitably fail because it’s unsupported. There is no secret downstream magic (currently).

This is why I would suggest not using linuxPackages_latest, unless you can assume maintenance of that driver package yourself and perhaps apply some of the patches that are floating around on the internet. I would still suggest trying linuxPackages_default, since I believe that version is actually tested to work with the drivers.

Sorry for my lack of knowledge but do I enable the default kernel by just not specifying because I tried without any specified kernel and the build failed but perhaps I am doing it wrong?

Edit: It attempted to build for kernel 5.10.81-dev

Just not specifying any version will build the default kernel, yes. If that doesn’t work it’s probably worth raising a bug upstream.

Thank you, it didn’t build so where do you recommend I raise a bug report?

GitHub - NixOS/nixpkgs: Nix Packages collection :slight_smile:

Note that you may in response get a “we can’t support that driver for newer kernels”, or “please package the patches yourself”. I don’t think there’s much interest in drivers that old.