Nixpkgs: nvidia fails to build on unstable

Created on 15 Jun 2020  路  15Comments  路  Source: NixOS/nixpkgs

Describe the bug
Nvidia fails to build with 5.7 on unstable.

/build/kernel/nvidia/nv-vm.c: In function 'nv_set_memory_array_type':
/build/kernel/nvidia/nv-vm.c:66:13: error: implicit declaration of function 'set_memory_array_uc'; did you mean 'set_pages_array_uc'? [-Werror=implicit-function-declaration]
   66 |             set_memory_array_uc(pages, num_pages);
      |             ^~~~~~~~~~~~~~~~~~~
      |             set_pages_array_uc
/build/kernel/nvidia/nv-vm.c:69:13: error: implicit declaration of function 'set_memory_array_wb'; did you mean 'set_pages_array_wb'? [-Werror=implicit-function-declaration]
   69 |             set_memory_array_wb(pages, num_pages);
      |             ^~~~~~~~~~~~~~~~~~~
      |             set_pages_array_wb

builder for '/nix/store/qlkblmpmz43vgl8ydh3zj7if0mzrp1jl-nvidia-x11-440.82-5.7.2.drv' failed with exit code 2

Seems like there is a fix

bug kernel

Most helpful comment

Thanks; @srid, @romildo - the issue was that nvidia-settings and nvidia-persistenced were still being compiled with the _unpatched_ version (I haven't had this case, because those apps are disabled for bumblebee).

Could you please try this one?

{ config, pkgs, ... }: {
  nixpkgs.overlays = [
    (self: super: {
      linuxPackages_latest = super.linuxPackages_latest.extend (self: super: {
        nvidiaPackages = super.nvidiaPackages // {
          stable = super.nvidiaPackages.stable.overrideAttrs (attrs: {
            patches = [
              (pkgs.fetchpatch {
                name = "nvidia-kernel-5.7.patch";
                url = "https://gitlab.com/snippets/1965550/raw";
                sha256 = "03iwxhkajk65phc0h5j7v4gr4fjj6mhxdn04pa57am5qax8i2g9w";
              })
            ];

            passthru = {
              settings = pkgs.callPackage (import <nixpkgs/pkgs/os-specific/linux/nvidia-x11/settings.nix> self.nvidiaPackages.stable "15psxvd65wi6hmxmd2vvsp2v0m07axw613hb355nh15r1dpkr3ma") {
                withGtk2 = true;
                withGtk3 = false;
              };

              persistenced = pkgs.lib.mapNullable (hash: pkgs.callPackage (import <nixpkgs/pkgs/os-specific/linux/nvidia-x11/persistenced.nix> self.nvidiaPackages.stable hash) { }) "13izz9p2kg9g38gf57g3s2sw7wshp1i9m5pzljh9v82c4c22x1fw";
            };
          });
        };
      });
    })
  ];
}

(for reference: those two fancy hashes were copied from pkgs/os-specific/linux/nvidia-x11/default.nix)

All 15 comments

I just did some research on this and found the following (including a patch):

https://forums.developer.nvidia.com/t/nvidia-440-82-kernel-5-7-patch/125815/5

oops I found that link and forgot to add it in my message after Seems like there is a fix xD

cc @eadwu @baracoder

As a quick fix from user-side (configuration.nix), you can do:

{ ... }: {
  # ...

  nixpkgs = {
    overlays = [
      (self: super: {
        linuxPackages_latest = super.linuxPackages_latest.extend (self: super: {
          nvidia_x11 = super.nvidia_x11.overrideAttrs (attrs: {
            patches = [
              ./nvidia/conftest.patch
            ];
          });
        });
      })
    ];
  };
}

edit: there's a better snippet a few posts below

@Patryk27 That did not work for me (the patch doesn't seem to be applied). Is your config online?

@srid: Unfortunately, I don't have my configuration online - an excerpt that's responsible for configuring nvidia on my machine is: https://gist.github.com/Patryk27/696ed8c3d7ff028c5ca84a3ee06ba745. Could you maybe post your logs for nixos-rebuild switch? I'd be more than happy to help in figuring out the issue.

I have the following in configuration.nix, the patch is applied, but compilation still fails.

    nixpkgs.overlays = [
      (self: super: {
        linuxPackages_latest = super.linuxPackages_latest.extend (self: super: {
          nvidia_x11 = super.nvidia_x11.overrideAttrs (attrs: {
            patches = [
              (pkgs.fetchpatch {
                name = "nvidia-kernel-5.7.patch";
                url = "https://gitlab.com/snippets/1965550/raw";
                sha256 = "03iwxhkajk65phc0h5j7v4gr4fjj6mhxdn04pa57am5qax8i2g9w";
              })
            ];
          });
        });
      })
    ];
[...]
patching sources
applying patch /nix/store/8lndb4192rlp7a7c0skgbrd9sjyx3wfw-nvidia-kernel-5.7.patch
patching file kernel/conftest.sh
configuring
[...]
/build/kernel/nvidia/nv-vm.c: In function 'nv_set_memory_array_type':
/build/kernel/nvidia/nv-vm.c:66:13: error: implicit declaration of function 'set_memory_array_uc'; did you mean 'set_pages_array_uc'? [-Werror=implicit-function-declaration]
   66 |             set_memory_array_uc(pages, num_pages);
      |             ^~~~~~~~~~~~~~~~~~~
      |             set_pages_array_uc
/build/kernel/nvidia/nv-vm.c:69:13: error: implicit declaration of function 'set_memory_array_wb'; did you mean 'set_pages_array_wb'? [-Werror=implicit-function-declaration]
   69 |             set_memory_array_wb(pages, num_pages);
      |             ^~~~~~~~~~~~~~~~~~~
      |             set_pages_array_wb
[...]

@romildo: How are you using your Nvidia drivers - just something like services.xserver.videoDrivers = [ "modesetting" "nvidia" ];?

I've had that issue before too (patch being seemingly ignored), and - in my case - it was caused by Nvidia being loaded _twice_, in different versions (I was doing OPENCL_VENDOR_PATH = "${pkgs.linuxPackages.nvidia_x11}/etc/OpenCL/vendors"; somewhere inside my configuration.nix instead of referring to pkgs.linuxPackages_latest).

Here are the sections of the configuration.nix where nvidia is mentioned on my system.

{ config, pkgs, ... }:

let

  myNvidia = {
    # NVIDIA Optimus Prime: prime render offload
    # Https://nixos.wiki/wiki/Nvidia
    # https://github.com/NixOS/nixpkgs/pull/66601
    hardware.nvidia.prime.sync.enable = true;
    #hardware.nvidia.prime.offload.enable = true;
    hardware.nvidia.prime.intelBusId = "PCI:0:2:0";
    hardware.nvidia.prime.nvidiaBusId = "PCI:1:0:0";
    #hardware.nvidia.modesetting.enable = true; ###! ??? prevent tearing

    services.xserver.videoDrivers = [ "nvidia" ];

    services.xserver.displayManager.sddm.setupScript = ''
      # workaround for using NVIDIA Optimus without Bumblebee
      xrandr --setprovideroutputsource modesetting NVIDIA-0
      xrandr --auto
    '';

    nixpkgs.overlays = [
      (self: super: {
        linuxPackages_latest = super.linuxPackages_latest.extend (self: super: {
          nvidia_x11 = super.nvidia_x11.overrideAttrs (attrs: {
            patches = [
              (pkgs.fetchpatch {
                name = "nvidia-kernel-5.7.patch";
                url = "https://gitlab.com/snippets/1965550/raw";
                sha256 = "03iwxhkajk65phc0h5j7v4gr4fjj6mhxdn04pa57am5qax8i2g9w";
              })
            ];
          });
        });
      })
    ];
  };

  # ...

in

{
  imports = [
    myNvidia
    # ...
  ];

  # ...
}

Thanks; @srid, @romildo - the issue was that nvidia-settings and nvidia-persistenced were still being compiled with the _unpatched_ version (I haven't had this case, because those apps are disabled for bumblebee).

Could you please try this one?

{ config, pkgs, ... }: {
  nixpkgs.overlays = [
    (self: super: {
      linuxPackages_latest = super.linuxPackages_latest.extend (self: super: {
        nvidiaPackages = super.nvidiaPackages // {
          stable = super.nvidiaPackages.stable.overrideAttrs (attrs: {
            patches = [
              (pkgs.fetchpatch {
                name = "nvidia-kernel-5.7.patch";
                url = "https://gitlab.com/snippets/1965550/raw";
                sha256 = "03iwxhkajk65phc0h5j7v4gr4fjj6mhxdn04pa57am5qax8i2g9w";
              })
            ];

            passthru = {
              settings = pkgs.callPackage (import <nixpkgs/pkgs/os-specific/linux/nvidia-x11/settings.nix> self.nvidiaPackages.stable "15psxvd65wi6hmxmd2vvsp2v0m07axw613hb355nh15r1dpkr3ma") {
                withGtk2 = true;
                withGtk3 = false;
              };

              persistenced = pkgs.lib.mapNullable (hash: pkgs.callPackage (import <nixpkgs/pkgs/os-specific/linux/nvidia-x11/persistenced.nix> self.nvidiaPackages.stable hash) { }) "13izz9p2kg9g38gf57g3s2sw7wshp1i9m5pzljh9v82c4c22x1fw";
            };
          });
        };
      });
    })
  ];
}

(for reference: those two fancy hashes were copied from pkgs/os-specific/linux/nvidia-x11/default.nix)

@Patryk27 That worked, thanks!

This workaround fixed it for me too.

confirming the workaround as well. the backport for 20.03 looks merged but updating nix-channel was not enough for me, I might have missed something...

the backport for 20.03 looks merged but updating nix-channel was not enough for me, I might have missed something...

The latest commit for nixos-20.03 looks like its older than the backport's, I suspect we're waiting on builds and a merge to the release branch. You can see the merged commits on the branch here:

https://github.com/NixOS/nixpkgs-channels/commits/nixos-20.03

The nvidia update PR which fixed the issue is in both unstable and stable now.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

joepie91 picture joepie91  路  102Comments

globin picture globin  路  65Comments

globin picture globin  路  65Comments

Infinisil picture Infinisil  路  146Comments

peti picture peti  路  75Comments