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
48 , # Whether to build the libraries only (i.e. not the kernel module or
49 # nvidia-settings). Used to support 32-bit binaries on 64-bit
52 , # don't include the bundled 32-bit libraries on 64-bit platforms,
53 # even if it’s in downloaded binary
54 disable32Bit ? stdenv.hostPlatform.system == "aarch64-linux"
55 # 32 bit libs only version of this package
57 # Whether to extract the GSP firmware, datacenter drivers needs to extract the
59 , firmware ? openSha256 != null || useFabricmanager
60 # Whether the user accepts the NVIDIA Software License
62 , acceptLicense ? config.nvidia.acceptLicense or false
65 assert !libsOnly -> kernel != null;
66 assert lib.versionOlder version "391" -> sha256_32bit != null;
67 assert useSettings -> settingsSha256 != null;
68 assert usePersistenced -> persistencedSha256 != null;
69 assert useFabricmanager -> fabricmanagerSha256 != null;
70 assert useFabricmanager -> !useSettings;
73 # Rewrites patches meant for the kernel/* folder structure to kernel-open/*
77 runCommandLocal (builtins.baseNameOf patch)
80 nativeBuildInputs = [ patchutils ];
86 | sort -u | sed -e 's/[*?]/\\&/g' \
91 --addoldprefix=a/${to}/ \
92 --addnewprefix=b/${to}/ \
93 --clean "$patch" > "$out"
96 nameSuffix = lib.optionalString (!libsOnly) "-${kernel.version}";
97 pkgSuffix = lib.optionalString (lib.versionOlder version "304") "-pkg0";
98 i686bundled = lib.versionAtLeast version "391" && !disable32Bit;
100 libPathFor = pkgs: lib.makeLibraryPath (with pkgs; [
113 dbus # for nvidia-powerd
116 # maybe silly since we've ignored this previously and just unfree..
117 throwLicense = throw ''
118 Use of NVIDIA Software requires license acceptance of the license:
120 - License For Customer Use of NVIDIA Software [1]
122 You can express acceptance by setting acceptLicense to true your nixpkgs.config.
126 nixpkgs.config.allowUnfree = true;
127 nixpkgs.config.nvidia.acceptLicense = true;
131 nvidia.acceptLicense = true;
133 [1]: https://www.nvidia.com/content/DriverDownloads/licence.php?lang=us
136 self = stdenv.mkDerivation {
137 name = "nvidia-${if useFabricmanager then "dc" else "x11"}-${version}${nameSuffix}";
139 builder = ./builder.sh;
142 if !acceptLicense && (openSha256 == null) then throwLicense else
143 if stdenv.hostPlatform.system == "x86_64-linux" then
146 urls = if args ? url then [ args.url ] else [
147 "https://us.download.nvidia.com/XFree86/Linux-x86_64/${version}/NVIDIA-Linux-x86_64-${version}${pkgSuffix}.run"
148 "https://download.nvidia.com/XFree86/Linux-x86_64/${version}/NVIDIA-Linux-x86_64-${version}${pkgSuffix}.run"
150 sha256 = sha256_64bit;
152 else if stdenv.hostPlatform.system == "i686-linux" then
155 urls = if args ? url then [ args.url ] else [
156 "https://us.download.nvidia.com/XFree86/Linux-x86/${version}/NVIDIA-Linux-x86-${version}${pkgSuffix}.run"
157 "https://download.nvidia.com/XFree86/Linux-x86/${version}/NVIDIA-Linux-x86-${version}${pkgSuffix}.run"
159 sha256 = sha256_32bit;
161 else if stdenv.hostPlatform.system == "aarch64-linux" && sha256_aarch64 != null then
164 urls = if args ? url then [ args.url ] else [
165 "https://us.download.nvidia.com/XFree86/aarch64/${version}/NVIDIA-Linux-aarch64-${version}${pkgSuffix}.run"
166 "https://download.nvidia.com/XFree86/Linux-aarch64/${version}/NVIDIA-Linux-aarch64-${version}${pkgSuffix}.run"
168 sha256 = sha256_aarch64;
170 else throw "nvidia-x11 does not support platform ${stdenv.hostPlatform.system}";
178 ++ (builtins.map (rewritePatch {
179 from = "kernel-open";
183 inherit prePatch postPatch patchFlags;
184 inherit preInstall postInstall;
185 inherit version useGLVND useProfiles;
186 inherit (stdenv.hostPlatform) system;
190 ++ lib.optional i686bundled "lib32"
191 ++ lib.optional (!libsOnly) "bin"
192 ++ lib.optional (!libsOnly && firmware) "firmware";
193 outputDev = if libsOnly then null else "bin";
195 kernel = if libsOnly then null else kernel.dev;
196 kernelVersion = if libsOnly then null else kernel.modDirVersion;
198 makeFlags = lib.optionals (!libsOnly) (kernel.makeFlags ++ [
199 "IGNORE_PREEMPT_RT_PRESENCE=1"
200 "NV_BUILD_SUPPORTS_HMM=1"
201 "SYSSRC=${kernel.dev}/lib/modules/${kernel.modDirVersion}/source"
202 "SYSOUT=${kernel.dev}/lib/modules/${kernel.modDirVersion}/build"
205 hardeningDisable = [ "pic" "format" ];
210 libPath = libPathFor pkgs;
211 libPath32 = lib.optionalString i686bundled (libPathFor pkgsi686Linux);
213 nativeBuildInputs = [ perl nukeReferences which libarchive jq ]
214 ++ lib.optionals (!libsOnly) kernel.moduleBuildDependencies;
216 disallowedReferences = lib.optionals (!libsOnly) [ kernel.dev ];
220 fetchFromGithubOrNvidia = { owner, repo, rev, ... }@args:
222 args' = builtins.removeAttrs args [ "owner" "repo" "rev" ];
223 baseUrl = "https://github.com/${owner}/${repo}";
227 "${baseUrl}/archive/${rev}.tar.gz"
228 "https://download.nvidia.com/XFree86/${repo}/${repo}-${rev}.tar.bz2"
230 # github and nvidia use different compression algorithms,
231 # use an invalid file extension to force detection.
232 extension = "tar.??";
236 open = lib.mapNullable
237 (hash: callPackage ./open.nix {
241 (builtins.map (rewritePatch {
251 (if settings32Bit then pkgsi686Linux.callPackage else callPackage) (import ./settings.nix self settingsSha256)
253 withGtk2 = preferGtk2;
254 withGtk3 = !preferGtk2;
255 fetchFromGitHub = fetchFromGithubOrNvidia;
258 if usePersistenced then
260 (hash: callPackage (import ./persistenced.nix self hash) {
261 fetchFromGitHub = fetchFromGithubOrNvidia;
266 if useFabricmanager then
267 lib.mapNullable (hash: callPackage (import ./fabricmanager.nix self hash) { }) fabricmanagerSha256
269 inherit persistencedVersion settingsVersion;
270 compressFirmware = false;
271 ibtSupport = ibtSupport || (lib.versionAtLeast version "530");
272 } // lib.optionalAttrs (!i686bundled) {
277 homepage = "https://www.nvidia.com/object/unix.html";
278 description = "${if useFabricmanager then "Data Center" else "X.org"} driver and kernel module for NVIDIA cards";
279 license = licenses.unfreeRedistributable;
280 platforms = [ "x86_64-linux" ]
281 ++ lib.optionals (sha256_32bit != null) [ "i686-linux" ]
282 ++ lib.optionals (sha256_aarch64 != null) [ "aarch64-linux" ];
283 maintainers = with maintainers; [ kiskae edwtjo ];
284 priority = 4; # resolves collision with xorg-server's "lib/xorg/modules/extensions/libglx.so"