Issues with my nvidia GPU config

I’m running Nixos-stable.

I currently have my nvidia GPU configured with the following configuration that I got from Nvidia - NixOS Wiki

hardware.nvidia.package = config.boot.kernelPackages.nvidiaPackages.stable

 # Enable OpenGL
  hardware.opengl = {
    enable = true;
    driSupport = true;
    driSupport32Bit = true;
  };

  # Load nvidia driver for Xorg and Wayland
  services.xserver.videoDrivers = ["nvidia"];

  hardware.nvidia = {

    # Modesetting is required.
    modesetting.enable = true;

    # Nvidia power management. Experimental, and can cause sleep/suspend to fail.
    powerManagement.enable = false;
    # Fine-grained power management. Turns off GPU when not in use.
    # Experimental and only works on modern Nvidia GPUs (Turing or newer).
    powerManagement.finegrained = false;

    # Use the NVidia open source kernel module (not to be confused with the
    # independent third-party "nouveau" open source driver).
    # Support is limited to the Turing and later architectures. Full list of 
    # supported GPUs is at: 
    # https://github.com/NVIDIA/open-gpu-kernel-modules#compatible-gpus 
    # Only available from driver 515.43.04+
    # Currently alpha-quality/buggy, so false is currently the recommended setting.
    open = false;

    # Enable the Nvidia settings menu,
	# accessible via `nvidia-settings`.
    nvidiaSettings = true;

    # Optionally, you may need to select the appropriate driver version for your specific GPU.
    package = config.boot.kernelPackages.nvidiaPackages.stable;
  };

I’ve followed this configuration in the past, and it worked without any issues. But for some reason now, when I run:

sudo nixos-rebuild switch

I’m met with the following error.

2452 | long get_user_pages(unsigned long start, unsigned long nr_pages,
      |      ^~~~~~~~~~~~~~
make[4]: *** [/nix/store/xc40qp3lkvh5yxvjb16r1pxsbn80m9rd-linux-6.6-dev/lib/modules/6.6.0/source/scripts/Makefile.build:243: /build/kernel/nvidia/nv-i2c.o] Error 1
make[4]: *** [/nix/store/xc40qp3lkvh5yxvjb16r1pxsbn80m9rd-linux-6.6-dev/lib/modules/6.6.0/source/scripts/Makefile.build:243: /build/kernel/nvidia/nv-dma.o] Error 1
make[4]: *** [/nix/store/xc40qp3lkvh5yxvjb16r1pxsbn80m9rd-linux-6.6-dev/lib/modules/6.6.0/source/scripts/Makefile.build:243: /build/kernel/nvidia/nv.o] Error 1
make[4]: *** [/nix/store/xc40qp3lkvh5yxvjb16r1pxsbn80m9rd-linux-6.6-dev/lib/modules/6.6.0/source/scripts/Makefile.build:243: /build/kernel/nvidia/nv-acpi.o] Error 1
make[4]: *** [/nix/store/xc40qp3lkvh5yxvjb16r1pxsbn80m9rd-linux-6.6-dev/lib/modules/6.6.0/source/scripts/Makefile.build:243: /build/kernel/nvidia/nv-dmabuf.o] Error 1
make[3]: *** [/nix/store/xc40qp3lkvh5yxvjb16r1pxsbn80m9rd-linux-6.6-dev/lib/modules/6.6.0/source/Makefile:1913: /build/kernel] Error 2
make[2]: *** [/nix/store/xc40qp3lkvh5yxvjb16r1pxsbn80m9rd-linux-6.6-dev/lib/modules/6.6.0/source/Makefile:234: __sub-make] Error 2
make[2]: Leaving directory '/nix/store/xc40qp3lkvh5yxvjb16r1pxsbn80m9rd-linux-6.6-dev/lib/modules/6.6.0/build'
make[1]: *** [Makefile:234: __sub-make] Error 2
make[1]: Leaving directory '/nix/store/xc40qp3lkvh5yxvjb16r1pxsbn80m9rd-linux-6.6-dev/lib/modules/6.6.0/source'
make: *** [Makefile:82: modules] Error 2
error: builder for '/nix/store/vkv3qv5wcps5gdhgbw69a25my9q7hhdg-nvidia-x11-525.47.34-6.6.drv' failed with exit code 2
error: 1 dependencies of derivation '/nix/store/wvrc205n5i8sm68qs3s7h67lp2y2ym50-etc.drv' failed to build
error: 1 dependencies of derivation '/nix/store/0bc0h9szwfg7vpdx6cfbw7q1wsy9lzaw-linux-6.6-modules.drv' failed to build
error: 1 dependencies of derivation '/nix/store/h9dcxpqvlcihi377q04l0sl419kk870j-system-path.drv' failed to build
error: 1 dependencies of derivation '/nix/store/ncaas9kasragqcfgyn0033i3851iilq8-nixos-system-nixos-Razer_Blade14_2015-23.05.4738.41de143fda10.drv' failed to build

I’m not sure what caused this error as I’ve had no issues with this nvidia config in the past.

Quick question: which kernel version are you running? What is your boot.kernelPackages?

boot.kernelPackages = pkgs.linuxPackages_latest;

I’m running Linux kernel 6.5.5, but I know that if I rebuild with my current boot.kernelpackages config, it’ll upgrade it to 6.6.0

Since this error appears to be related to the building of nvidia kernel modules, my first idea would be, if this is possible for you to do, to try linuxPackages instead of linuxPackages_latest. That would put your system on the LTS kernel version 6.1.XX.

2 Likes

I hadn’t upgraded in a while and was having the exact same problem.
Changing to linuxPackages worked for me. Thanks.

  boot.kernelPackages = pkgs.linuxPackages_xanmod; 
  boot.kernelPackages = pkgs.linuxPackages_xanmod_latest; 
  boot.kernelPackages = pkgs.linuxPackages_xanmod_stable; 
  boot.kernelPackages = pkgs.linuxPackages_xanmod_tt; 

  kernelPackages = pkgs.linuxKernel.packages.linux_zen;

How does one choose a specific linuxPackage? 6.5 seemed to work fine for me before these errors occurred.

This fixed it for me as well!

If anyone wants to know, linuxPackages_6_5 works well with nvidia drivers!

xanmod kernel stable and nvidia driver stable with opengl
I too have an issue upgrading to latest 6.6x kernel as it dosnt rebuild my nvidia driver

      #---------------------------------------------------------------------
      # Optionally, you may need to select the appropriate driver version for your specific GPU.
      # old:  535.86.05 (STABLE)
      #---------------------------------------------------------------------
      package = config.boot.kernelPackages.nvidiaPackages.stable;      

      # Check legacy drivers https://www.nvidia.com/en-us/drivers/unix/legacy-gpu/
      # hardware.nvidia.package = config.boot.kernelPackages.nvidiaPackages.legacy_340
      # hardware.nvidia.package = config.boot.kernelPackages.nvidiaPackages.legacy_390

      #---------------------------------------------------------------------
      # Fix screen flipping to black randomly.        old:  535.86.05 (STABLE)
      #---------------------------------------------------------------------
      # package = config.boot.kernelPackages.nvidiaPackages.stable.overrideAttrs {
      #  src = pkgs.fetchurl {
      #    url =
      #      "https://download.nvidia.com/XFree86/Linux-x86_64/545.29.02/NVIDIA-Linux-x86_64-545.29.02.run";
       #   sha256 = "46770f95a4a386f0455023b359d5d21373c07d13c222b5805f224c74b3cab885";
          # sha256 = "sha256-QTnTKAGfcvKvKHik0BgAemV3PrRqRlM3B9jjZeupCC8=";
      #  };
      #};