5 , sha256_aarch64 ? null
7 , settingsSha256 ? null
8 , settingsVersion ? version
9 , persistencedSha256 ? null
10 , persistencedVersion ? version
11 , fabricmanagerSha256 ? null
12 , fabricmanagerVersion ? version
16 , settings32Bit ? false
18 , usePersistenced ? true
19 , useFabricmanager ? false
45 , # Whether to build the libraries only (i.e. not the kernel module or
46 # nvidia-settings). Used to support 32-bit binaries on 64-bit
49 , # don't include the bundled 32-bit libraries on 64-bit platforms,
50 # even if it’s in downloaded binary
51 disable32Bit ? stdenv.hostPlatform.system == "aarch64-linux"
52 # 32 bit libs only version of this package
54 # Whether to extract the GSP firmware, datacenter drivers needs to extract the
56 , firmware ? openSha256 != null || useFabricmanager
57 # Whether the user accepts the NVIDIA Software License
59 , acceptLicense ? config.nvidia.acceptLicense or false
62 assert !libsOnly -> kernel != null;
63 assert lib.versionOlder version "391" -> sha256_32bit != null;
64 assert useSettings -> settingsSha256 != null;
65 assert usePersistenced -> persistencedSha256 != null;
66 assert useFabricmanager -> fabricmanagerSha256 != null;
67 assert useFabricmanager -> !useSettings;
70 nameSuffix = lib.optionalString (!libsOnly) "-${kernel.version}";
71 pkgSuffix = lib.optionalString (lib.versionOlder version "304") "-pkg0";
72 i686bundled = lib.versionAtLeast version "391" && !disable32Bit;
74 libPathFor = pkgs: lib.makeLibraryPath (with pkgs; [
87 dbus # for nvidia-powerd
90 # maybe silly since we've ignored this previously and just unfree..
91 throwLicense = throw ''
92 Use of NVIDIA Software requires license acceptance of the license:
94 - License For Customer Use of NVIDIA Software [1]
96 You can express acceptance by setting acceptLicense to true your nixpkgs.config.
100 nixpkgs.config.allowUnfree = true;
101 nixpkgs.config.nvidia.acceptLicense = true;
105 nvidia.acceptLicense = true;
107 [1]: https://www.nvidia.com/content/DriverDownloads/licence.php?lang=us
110 self = stdenv.mkDerivation {
111 name = "nvidia-${if useFabricmanager then "dc" else "x11"}-${version}${nameSuffix}";
113 builder = ./builder.sh;
116 if !acceptLicense && (openSha256 == null) then throwLicense else
117 if stdenv.hostPlatform.system == "x86_64-linux" then
120 urls = if args ? url then [ args.url ] else [
121 "https://us.download.nvidia.com/XFree86/Linux-x86_64/${version}/NVIDIA-Linux-x86_64-${version}${pkgSuffix}.run"
122 "https://download.nvidia.com/XFree86/Linux-x86_64/${version}/NVIDIA-Linux-x86_64-${version}${pkgSuffix}.run"
124 sha256 = sha256_64bit;
126 else if stdenv.hostPlatform.system == "i686-linux" then
129 urls = if args ? url then [ args.url ] else [
130 "https://us.download.nvidia.com/XFree86/Linux-x86/${version}/NVIDIA-Linux-x86-${version}${pkgSuffix}.run"
131 "https://download.nvidia.com/XFree86/Linux-x86/${version}/NVIDIA-Linux-x86-${version}${pkgSuffix}.run"
133 sha256 = sha256_32bit;
135 else if stdenv.hostPlatform.system == "aarch64-linux" && sha256_aarch64 != null then
138 urls = if args ? url then [ args.url ] else [
139 "https://us.download.nvidia.com/XFree86/aarch64/${version}/NVIDIA-Linux-aarch64-${version}${pkgSuffix}.run"
140 "https://download.nvidia.com/XFree86/Linux-aarch64/${version}/NVIDIA-Linux-aarch64-${version}${pkgSuffix}.run"
142 sha256 = sha256_aarch64;
144 else throw "nvidia-x11 does not support platform ${stdenv.hostPlatform.system}";
146 patches = if libsOnly then null else patches;
147 inherit prePatch postPatch patchFlags;
148 inherit preInstall postInstall;
149 inherit version useGLVND useProfiles;
150 inherit (stdenv.hostPlatform) system;
154 ++ lib.optional i686bundled "lib32"
155 ++ lib.optional (!libsOnly) "bin"
156 ++ lib.optional (!libsOnly && firmware) "firmware";
157 outputDev = if libsOnly then null else "bin";
159 kernel = if libsOnly then null else kernel.dev;
160 kernelVersion = if libsOnly then null else kernel.modDirVersion;
162 makeFlags = lib.optionals (!libsOnly) (kernel.makeFlags ++ [
163 "IGNORE_PREEMPT_RT_PRESENCE=1"
164 "NV_BUILD_SUPPORTS_HMM=1"
165 "SYSSRC=${kernel.dev}/lib/modules/${kernel.modDirVersion}/source"
166 "SYSOUT=${kernel.dev}/lib/modules/${kernel.modDirVersion}/build"
169 hardeningDisable = [ "pic" "format" ];
174 libPath = libPathFor pkgs;
175 libPath32 = lib.optionalString i686bundled (libPathFor pkgsi686Linux);
177 nativeBuildInputs = [ perl nukeReferences which libarchive jq ]
178 ++ lib.optionals (!libsOnly) kernel.moduleBuildDependencies;
180 disallowedReferences = lib.optionals (!libsOnly) [ kernel.dev ];
184 fetchFromGithubOrNvidia = { owner, repo, rev, ... }@args:
186 args' = builtins.removeAttrs args [ "owner" "repo" "rev" ];
187 baseUrl = "https://github.com/${owner}/${repo}";
191 "${baseUrl}/archive/${rev}.tar.gz"
192 "https://download.nvidia.com/XFree86/${repo}/${repo}-${rev}.tar.bz2"
194 # github and nvidia use different compression algorithms,
195 # use an invalid file extension to force detection.
196 extension = "tar.??";
200 open = lib.mapNullable
201 (hash: callPackage ./open.nix {
209 (if settings32Bit then pkgsi686Linux.callPackage else callPackage) (import ./settings.nix self settingsSha256)
211 withGtk2 = preferGtk2;
212 withGtk3 = !preferGtk2;
213 fetchFromGitHub = fetchFromGithubOrNvidia;
216 if usePersistenced then
218 (hash: callPackage (import ./persistenced.nix self hash) {
219 fetchFromGitHub = fetchFromGithubOrNvidia;
224 if useFabricmanager then
225 lib.mapNullable (hash: callPackage (import ./fabricmanager.nix self hash) { }) fabricmanagerSha256
227 inherit persistencedVersion settingsVersion;
228 compressFirmware = false;
229 ibtSupport = ibtSupport || (lib.versionAtLeast version "530");
230 } // lib.optionalAttrs (!i686bundled) {
235 homepage = "https://www.nvidia.com/object/unix.html";
236 description = "${if useFabricmanager then "Data Center" else "X.org"} driver and kernel module for NVIDIA cards";
237 license = licenses.unfreeRedistributable;
238 platforms = [ "x86_64-linux" ]
239 ++ lib.optionals (sha256_32bit != null) [ "i686-linux" ]
240 ++ lib.optionals (sha256_aarch64 != null) [ "aarch64-linux" ];
241 maintainers = with maintainers; [ kiskae edwtjo ];
242 priority = 4; # resolves collision with xorg-server's "lib/xorg/modules/extensions/libglx.so"