Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)
at devShellTools-shell 345 lines 9.9 kB view raw
1{ 2 version, 3 url ? null, 4 sha256_32bit ? null, 5 sha256_64bit, 6 sha256_aarch64 ? null, 7 openSha256 ? null, 8 settingsSha256 ? null, 9 settingsVersion ? null, 10 persistencedSha256 ? null, 11 persistencedVersion ? null, 12 fabricmanagerSha256 ? null, 13 fabricmanagerVersion ? null, 14 useGLVND ? true, 15 useProfiles ? true, 16 preferGtk2 ? false, 17 settings32Bit ? false, 18 useSettings ? true, 19 usePersistenced ? true, 20 useFabricmanager ? false, 21 ibtSupport ? false, 22 23 prePatch ? null, 24 postPatch ? null, 25 patchFlags ? null, 26 patches ? [ ], 27 patchesOpen ? [ ], 28 preInstall ? null, 29 postInstall ? null, 30 broken ? false, 31 brokenOpen ? broken, 32}@args: 33 34{ 35 lib, 36 stdenv, 37 runCommandLocal, 38 patchutils, 39 callPackage, 40 pkgs, 41 pkgsi686Linux, 42 fetchurl, 43 fetchzip, 44 kernel ? null, 45 kernelModuleMakeFlags ? [ ], 46 perl, 47 nukeReferences, 48 which, 49 libarchive, 50 jq, 51 # Whether to build the libraries only (i.e. not the kernel module or 52 # nvidia-settings). Used to support 32-bit binaries on 64-bit 53 # Linux. 54 libsOnly ? false, 55 # don't include the bundled 32-bit libraries on 64-bit platforms, 56 # even if it’s in downloaded binary 57 disable32Bit ? stdenv.hostPlatform.system == "aarch64-linux", 58 # 32 bit libs only version of this package 59 lib32 ? null, 60 # Whether to extract the GSP firmware, datacenter drivers needs to extract the 61 # firmware 62 firmware ? openSha256 != null || useFabricmanager, 63 # Whether the user accepts the NVIDIA Software License 64 config, 65 acceptLicense ? config.nvidia.acceptLicense or false, 66}: 67 68assert !libsOnly -> kernel != null; 69assert lib.versionOlder version "391" -> sha256_32bit != null; 70assert useSettings -> settingsSha256 != null; 71assert usePersistenced -> persistencedSha256 != null; 72assert useFabricmanager -> fabricmanagerSha256 != null; 73assert useFabricmanager -> !useSettings; 74 75let 76 # Rewrites patches meant for the kernel/* folder structure to kernel-open/* 77 rewritePatch = 78 { from, to }: 79 patch: 80 runCommandLocal (builtins.baseNameOf patch) 81 { 82 inherit patch; 83 nativeBuildInputs = [ patchutils ]; 84 } 85 '' 86 lsdiff \ 87 -p1 -i ${from}/'*' \ 88 "$patch" \ 89 | sort -u | sed -e 's/[*?]/\\&/g' \ 90 | xargs -I{} \ 91 filterdiff \ 92 --include={} \ 93 --strip=2 \ 94 --addoldprefix=a/${to}/ \ 95 --addnewprefix=b/${to}/ \ 96 --clean "$patch" > "$out" 97 ''; 98 99 nameSuffix = lib.optionalString (!libsOnly) "-${kernel.version}"; 100 pkgSuffix = lib.optionalString (lib.versionOlder version "304") "-pkg0"; 101 i686bundled = lib.versionAtLeast version "391" && !disable32Bit; 102 103 libPathFor = 104 pkgs: 105 lib.makeLibraryPath ( 106 with pkgs; 107 [ 108 libdrm 109 xorg.libXext 110 xorg.libX11 111 xorg.libXv 112 xorg.libXrandr 113 xorg.libxcb 114 zlib 115 stdenv.cc.cc 116 wayland 117 libgbm 118 libGL 119 openssl 120 dbus # for nvidia-powerd 121 ] 122 ); 123 124 # maybe silly since we've ignored this previously and just unfree.. 125 throwLicense = throw '' 126 Use of NVIDIA Software requires license acceptance of the license: 127 128 - License For Customer Use of NVIDIA Software [1] 129 130 You can express acceptance by setting acceptLicense to true your nixpkgs.config. 131 Example: 132 133 configuration.nix: 134 nixpkgs.config.allowUnfree = true; 135 nixpkgs.config.nvidia.acceptLicense = true; 136 137 config.nix: 138 allowUnfree = true; 139 nvidia.acceptLicense = true; 140 141 [1]: https://www.nvidia.com/content/DriverDownloads/licence.php?lang=us 142 ''; 143in 144 145stdenv.mkDerivation (finalAttrs: { 146 name = "nvidia-${if useFabricmanager then "dc" else "x11"}-${version}${nameSuffix}"; 147 148 builder = ./builder.sh; 149 150 src = 151 if !acceptLicense && (openSha256 == null) then 152 throwLicense 153 else if stdenv.hostPlatform.system == "x86_64-linux" then 154 fetchurl { 155 urls = 156 if args ? url then 157 [ args.url ] 158 else 159 [ 160 "https://us.download.nvidia.com/XFree86/Linux-x86_64/${version}/NVIDIA-Linux-x86_64-${version}${pkgSuffix}.run" 161 "https://download.nvidia.com/XFree86/Linux-x86_64/${version}/NVIDIA-Linux-x86_64-${version}${pkgSuffix}.run" 162 ]; 163 sha256 = sha256_64bit; 164 } 165 else if stdenv.hostPlatform.system == "i686-linux" then 166 fetchurl { 167 urls = 168 if args ? url then 169 [ args.url ] 170 else 171 [ 172 "https://us.download.nvidia.com/XFree86/Linux-x86/${version}/NVIDIA-Linux-x86-${version}${pkgSuffix}.run" 173 "https://download.nvidia.com/XFree86/Linux-x86/${version}/NVIDIA-Linux-x86-${version}${pkgSuffix}.run" 174 ]; 175 sha256 = sha256_32bit; 176 } 177 else if stdenv.hostPlatform.system == "aarch64-linux" && sha256_aarch64 != null then 178 fetchurl { 179 urls = 180 if args ? url then 181 [ args.url ] 182 else 183 [ 184 "https://us.download.nvidia.com/XFree86/aarch64/${version}/NVIDIA-Linux-aarch64-${version}${pkgSuffix}.run" 185 "https://download.nvidia.com/XFree86/Linux-aarch64/${version}/NVIDIA-Linux-aarch64-${version}${pkgSuffix}.run" 186 ]; 187 sha256 = sha256_aarch64; 188 } 189 else 190 throw "nvidia-x11 does not support platform ${stdenv.hostPlatform.system}"; 191 192 patches = if libsOnly then null else patches; 193 inherit prePatch postPatch patchFlags; 194 inherit preInstall postInstall; 195 inherit version useGLVND useProfiles; 196 inherit (stdenv.hostPlatform) system; 197 inherit i686bundled; 198 199 outputs = [ 200 "out" 201 ] 202 ++ lib.optional i686bundled "lib32" 203 ++ lib.optional (!libsOnly) "bin" 204 ++ lib.optional (!libsOnly && firmware) "firmware"; 205 outputDev = if libsOnly then null else "bin"; 206 207 kernel = if libsOnly then null else kernel.dev; 208 kernelVersion = if libsOnly then null else kernel.modDirVersion; 209 210 makeFlags = lib.optionals (!libsOnly) ( 211 kernelModuleMakeFlags 212 ++ [ 213 "IGNORE_PREEMPT_RT_PRESENCE=1" 214 "NV_BUILD_SUPPORTS_HMM=1" 215 "SYSSRC=${kernel.dev}/lib/modules/${kernel.modDirVersion}/source" 216 "SYSOUT=${kernel.dev}/lib/modules/${kernel.modDirVersion}/build" 217 ] 218 ); 219 220 hardeningDisable = [ 221 "pic" 222 "format" 223 ]; 224 225 dontStrip = true; 226 dontPatchELF = true; 227 228 libPath = libPathFor pkgs; 229 libPath32 = lib.optionalString i686bundled (libPathFor pkgsi686Linux); 230 231 nativeBuildInputs = [ 232 perl 233 nukeReferences 234 which 235 libarchive 236 jq 237 ] 238 ++ lib.optionals (!libsOnly) kernel.moduleBuildDependencies; 239 240 disallowedReferences = lib.optionals (!libsOnly) [ kernel.dev ]; 241 242 passthru = 243 let 244 fetchFromGithubOrNvidia = 245 { 246 owner, 247 repo, 248 rev, 249 ... 250 }@args: 251 let 252 args' = builtins.removeAttrs args [ 253 "owner" 254 "repo" 255 "rev" 256 ]; 257 baseUrl = "https://github.com/${owner}/${repo}"; 258 in 259 fetchzip ( 260 args' 261 // { 262 urls = [ 263 "${baseUrl}/archive/${rev}.tar.gz" 264 "https://download.nvidia.com/XFree86/${repo}/${repo}-${rev}.tar.bz2" 265 ]; 266 # github and nvidia use different compression algorithms, 267 # use an invalid file extension to force detection. 268 extension = "tar.??"; 269 } 270 ); 271 in 272 { 273 open = lib.mapNullable ( 274 hash: 275 callPackage ./open.nix { 276 inherit hash; 277 nvidia_x11 = finalAttrs.finalPackage; 278 patches = 279 (builtins.map (rewritePatch { 280 from = "kernel"; 281 to = "kernel-open"; 282 }) patches) 283 ++ patchesOpen; 284 broken = brokenOpen; 285 } 286 ) openSha256; 287 settings = 288 if useSettings then 289 (if settings32Bit then pkgsi686Linux.callPackage else callPackage) 290 (import ./settings.nix finalAttrs.finalPackage settingsSha256) 291 { 292 withGtk2 = preferGtk2; 293 withGtk3 = !preferGtk2; 294 fetchFromGitHub = fetchFromGithubOrNvidia; 295 } 296 else 297 { }; 298 persistenced = 299 if usePersistenced then 300 lib.mapNullable ( 301 hash: 302 callPackage (import ./persistenced.nix finalAttrs.finalPackage hash) { 303 fetchFromGitHub = fetchFromGithubOrNvidia; 304 } 305 ) persistencedSha256 306 else 307 { }; 308 fabricmanager = 309 if useFabricmanager then 310 lib.mapNullable ( 311 hash: callPackage (import ./fabricmanager.nix finalAttrs.finalPackage hash) { } 312 ) fabricmanagerSha256 313 else 314 { }; 315 settingsVersion = if settingsVersion != null then settingsVersion else finalAttrs.version; 316 persistencedVersion = 317 if persistencedVersion != null then persistencedVersion else finalAttrs.version; 318 fabricmanagerVersion = 319 if fabricmanagerVersion != null then fabricmanagerVersion else finalAttrs.version; 320 compressFirmware = false; 321 ibtSupport = ibtSupport || (lib.versionAtLeast version "530"); 322 } 323 // lib.optionalAttrs (!i686bundled) { 324 inherit lib32; 325 }; 326 327 meta = with lib; { 328 homepage = "https://www.nvidia.com/object/unix.html"; 329 description = "${ 330 if useFabricmanager then "Data Center" else "X.org" 331 } driver and kernel module for NVIDIA cards"; 332 license = licenses.unfreeRedistributable; 333 platforms = [ 334 "x86_64-linux" 335 ] 336 ++ lib.optionals (sha256_32bit != null) [ "i686-linux" ] 337 ++ lib.optionals (sha256_aarch64 != null) [ "aarch64-linux" ]; 338 maintainers = with maintainers; [ 339 kiskae 340 edwtjo 341 ]; 342 priority = 4; # resolves collision with xorg-server's "lib/xorg/modules/extensions/libglx.so" 343 inherit broken; 344 }; 345})