1{ version
2, url ? null
3, sha256_32bit ? null
4, sha256_64bit
5, sha256_aarch64 ? null
6, openSha256 ? null
7, settingsSha256
8, settingsVersion ? version
9, persistencedSha256
10, persistencedVersion ? version
11, useGLVND ? true
12, useProfiles ? true
13, preferGtk2 ? false
14, settings32Bit ? false
15, ibtSupport ? false
16
17, prePatch ? ""
18, postPatch ? null
19, patchFlags ? null
20, patches ? []
21, broken ? false
22, brokenOpen ? broken
23}@args:
24
25{ lib, stdenv, callPackage, pkgs, pkgsi686Linux, fetchurl
26, kernel ? null, perl, nukeReferences, which, libarchive
27, # Whether to build the libraries only (i.e. not the kernel module or
28 # nvidia-settings). Used to support 32-bit binaries on 64-bit
29 # Linux.
30 libsOnly ? false
31, # don't include the bundled 32-bit libraries on 64-bit platforms,
32 # even if it’s in downloaded binary
33 disable32Bit ? stdenv.hostPlatform.system == "aarch64-linux"
34 # 32 bit libs only version of this package
35, lib32 ? null
36 # Whether to extract the GSP firmware
37, firmware ? openSha256 != null
38}:
39
40with lib;
41
42assert !libsOnly -> kernel != null;
43assert versionOlder version "391" -> sha256_32bit != null;
44
45let
46 nameSuffix = optionalString (!libsOnly) "-${kernel.version}";
47 pkgSuffix = optionalString (versionOlder version "304") "-pkg0";
48 i686bundled = versionAtLeast version "391" && !disable32Bit;
49
50 libPathFor = pkgs: lib.makeLibraryPath (with pkgs; [
51 libdrm xorg.libXext xorg.libX11
52 xorg.libXv xorg.libXrandr xorg.libxcb zlib stdenv.cc.cc
53 wayland mesa libGL openssl
54 ]);
55
56 self = stdenv.mkDerivation {
57 name = "nvidia-x11-${version}${nameSuffix}";
58
59 builder = ./builder.sh;
60
61 src =
62 if stdenv.hostPlatform.system == "x86_64-linux" then
63 fetchurl {
64 urls = if args ? url then [ args.url ] else [
65 "https://us.download.nvidia.com/XFree86/Linux-x86_64/${version}/NVIDIA-Linux-x86_64-${version}${pkgSuffix}.run"
66 "https://download.nvidia.com/XFree86/Linux-x86_64/${version}/NVIDIA-Linux-x86_64-${version}${pkgSuffix}.run"
67 ];
68 sha256 = sha256_64bit;
69 }
70 else if stdenv.hostPlatform.system == "i686-linux" then
71 fetchurl {
72 urls = if args ? url then [ args.url ] else [
73 "https://us.download.nvidia.com/XFree86/Linux-x86/${version}/NVIDIA-Linux-x86-${version}${pkgSuffix}.run"
74 "https://download.nvidia.com/XFree86/Linux-x86/${version}/NVIDIA-Linux-x86-${version}${pkgSuffix}.run"
75 ];
76 sha256 = sha256_32bit;
77 }
78 else if stdenv.hostPlatform.system == "aarch64-linux" && sha256_aarch64 != null then
79 fetchurl {
80 urls = if args ? url then [ args.url ] else [
81 "https://us.download.nvidia.com/XFree86/aarch64/${version}/NVIDIA-Linux-aarch64-${version}${pkgSuffix}.run"
82 "https://download.nvidia.com/XFree86/Linux-aarch64/${version}/NVIDIA-Linux-aarch64-${version}${pkgSuffix}.run"
83 ];
84 sha256 = sha256_aarch64;
85 }
86 else throw "nvidia-x11 does not support platform ${stdenv.hostPlatform.system}";
87
88 patches = if libsOnly then null else patches;
89 inherit prePatch postPatch patchFlags;
90 inherit version useGLVND useProfiles;
91 inherit (stdenv.hostPlatform) system;
92 inherit i686bundled;
93
94 outputs = [ "out" ]
95 ++ optional i686bundled "lib32"
96 ++ optional (!libsOnly) "bin"
97 ++ optional (!libsOnly && firmware) "firmware";
98 outputDev = if libsOnly then null else "bin";
99
100 kernel = if libsOnly then null else kernel.dev;
101 kernelVersion = if libsOnly then null else kernel.modDirVersion;
102
103 makeFlags = optionals (!libsOnly) (kernel.makeFlags ++ [
104 "IGNORE_PREEMPT_RT_PRESENCE=1"
105 "NV_BUILD_SUPPORTS_HMM=1"
106 "SYSSRC=${kernel.dev}/lib/modules/${kernel.modDirVersion}/source"
107 "SYSOUT=${kernel.dev}/lib/modules/${kernel.modDirVersion}/build"
108 ]);
109
110 hardeningDisable = [ "pic" "format" ];
111
112 dontStrip = true;
113 dontPatchELF = true;
114
115 libPath = libPathFor pkgs;
116 libPath32 = optionalString i686bundled (libPathFor pkgsi686Linux);
117
118 nativeBuildInputs = [ perl nukeReferences which libarchive ]
119 ++ optionals (!libsOnly) kernel.moduleBuildDependencies;
120
121 disallowedReferences = optionals (!libsOnly) [ kernel.dev ];
122
123 passthru = {
124 open = mapNullable (hash: callPackage ./open.nix {
125 inherit hash;
126 nvidia_x11 = self;
127 broken = brokenOpen;
128 }) openSha256;
129 settings = (if settings32Bit then pkgsi686Linux.callPackage else callPackage) (import ./settings.nix self settingsSha256) {
130 withGtk2 = preferGtk2;
131 withGtk3 = !preferGtk2;
132 };
133 persistenced = mapNullable (hash: callPackage (import ./persistenced.nix self hash) { }) persistencedSha256;
134 inherit persistencedVersion settingsVersion;
135 compressFirmware = false;
136 ibtSupport = ibtSupport || (lib.versionAtLeast version "530");
137 } // optionalAttrs (!i686bundled) {
138 inherit lib32;
139 };
140
141 meta = with lib; {
142 homepage = "https://www.nvidia.com/object/unix.html";
143 description = "X.org driver and kernel module for NVIDIA graphics cards";
144 license = licenses.unfreeRedistributable;
145 platforms = [ "x86_64-linux" ]
146 ++ optionals (sha256_32bit != null) [ "i686-linux" ]
147 ++ optionals (sha256_aarch64 != null) [ "aarch64-linux" ];
148 maintainers = with maintainers; [ jonringer kiskae ];
149 priority = 4; # resolves collision with xorg-server's "lib/xorg/modules/extensions/libglx.so"
150 inherit broken;
151 };
152 };
153
154in self