···30 shimsFn ? (throw "shimsFn must be provided"),
31}:
32let
33- inherit (lib)
34- attrsets
35- lists
36- modules
37- strings
38- ;
39-40- inherit (stdenv) hostPlatform;
41-42- evaluatedModules = modules.evalModules {
43 modules = [
44 ../modules
45 releasesModule
···50 # - Releases: ../modules/${pname}/releases/releases.nix
51 # - Package: ../modules/${pname}/releases/package.nix
5253- # FIXME: do this at the module system level
54- propagatePlatforms = lib.mapAttrs (
55- redistArch: packages: map (p: { inherit redistArch; } // p) packages
56- );
0000005758- # All releases across all platforms
59 # See ../modules/${pname}/releases/releases.nix
60- releaseSets = propagatePlatforms evaluatedModules.config.${pname}.releases;
0006162 # Compute versioned attribute name to be used in this package set
63 # Patch version changes should not break the build, so we only use major and minor
64 # computeName :: Package -> String
65- computeName = { version, ... }: mkVersionedPackageName pname version;
66-67- # Check whether a package supports our CUDA version and platform.
68- # isSupported :: Package -> Bool
69- isSupported =
70- package:
71- redistArch == package.redistArch
72- && strings.versionAtLeast cudaMajorMinorVersion package.minCudaVersion
73- && strings.versionAtLeast package.maxCudaVersion cudaMajorMinorVersion;
74-75- # Get all of the packages for our given platform.
76- # redistArch :: String
77- # Value is `"unsupported"` if the platform is not supported.
78- redistArch = flags.getRedistArch hostPlatform.system;
79-80- preferable =
81- p1: p2: (isSupported p2 -> isSupported p1) && (strings.versionOlder p2.version p1.version);
82-83- # All the supported packages we can build for our platform.
84- # perSystemReleases :: List Package
85- allReleases = lib.pipe releaseSets [
86- (lib.attrValues)
87- (lists.flatten)
88- (lib.groupBy (p: lib.versions.majorMinor p.version))
89- (lib.mapAttrs (_: builtins.sort preferable))
90- (lib.mapAttrs (_: lib.take 1))
91- (lib.attrValues)
92- (lib.concatMap lib.trivial.id)
93- ];
9495- newest = builtins.head (builtins.sort preferable allReleases);
00000000000000000000000009697 extension =
98 final: _:
···102 buildPackage =
103 package:
104 let
105- shims = final.callPackage shimsFn {
106- inherit package;
107- inherit (package) redistArch;
108- };
109 name = computeName package;
110 drv = final.callPackage ./manifest.nix {
111 inherit pname redistName;
112 inherit (shims) redistribRelease featureRelease;
113 };
114 in
115- attrsets.nameValuePair name drv;
116117 # versionedDerivations :: AttrSet Derivation
118- versionedDerivations = builtins.listToAttrs (lists.map buildPackage allReleases);
119120 defaultDerivation = {
121- ${pname} = (buildPackage newest).value;
122 };
123 in
124- versionedDerivations // defaultDerivation;
00125in
126extension
···30 shimsFn ? (throw "shimsFn must be provided"),
31}:
32let
33+ evaluatedModules = lib.modules.evalModules {
00000000034 modules = [
35 ../modules
36 releasesModule
···41 # - Releases: ../modules/${pname}/releases/releases.nix
42 # - Package: ../modules/${pname}/releases/package.nix
4344+ # redistArch :: String
45+ # Value is `"unsupported"` if the platform is not supported.
46+ redistArch = flags.getRedistArch stdenv.hostPlatform.system;
47+48+ # Check whether a package supports our CUDA version.
49+ # satisfiesCudaVersion :: Package -> Bool
50+ satisfiesCudaVersion =
51+ package:
52+ lib.versionAtLeast cudaMajorMinorVersion package.minCudaVersion
53+ && lib.versionAtLeast package.maxCudaVersion cudaMajorMinorVersion;
5455+ # Releases for our platform and CUDA version.
56 # See ../modules/${pname}/releases/releases.nix
57+ # allPackages :: List Package
58+ allPackages = lib.filter satisfiesCudaVersion (
59+ evaluatedModules.config.${pname}.releases.${redistArch} or [ ]
60+ );
6162 # Compute versioned attribute name to be used in this package set
63 # Patch version changes should not break the build, so we only use major and minor
64 # computeName :: Package -> String
65+ computeName = package: mkVersionedPackageName pname package.version;
00000000000000000000000000006667+ # The newest package for each major-minor version, with newest first.
68+ # newestPackages :: List Package
69+ newestPackages =
70+ let
71+ newestForEachMajorMinorVersion = lib.foldl' (
72+ newestPackages: package:
73+ let
74+ majorMinorVersion = lib.versions.majorMinor package.version;
75+ existingPackage = newestPackages.${majorMinorVersion} or null;
76+ in
77+ newestPackages
78+ // {
79+ ${majorMinorVersion} =
80+ # Only keep the existing package if it is newer than the one we are considering.
81+ if existingPackage != null && lib.versionOlder package.version existingPackage.version then
82+ existingPackage
83+ else
84+ package;
85+ }
86+ ) { } allPackages;
87+ in
88+ # Sort the packages by version so the newest is first.
89+ # NOTE: builtins.sort requires a strict weak ordering, so we must use versionOlder rather than versionAtLeast.
90+ lib.sort (p1: p2: lib.versionOlder p2.version p1.version) (
91+ lib.attrValues newestForEachMajorMinorVersion
92+ );
9394 extension =
95 final: _:
···99 buildPackage =
100 package:
101 let
102+ shims = final.callPackage shimsFn { inherit package redistArch; };
000103 name = computeName package;
104 drv = final.callPackage ./manifest.nix {
105 inherit pname redistName;
106 inherit (shims) redistribRelease featureRelease;
107 };
108 in
109+ lib.nameValuePair name drv;
110111 # versionedDerivations :: AttrSet Derivation
112+ versionedDerivations = builtins.listToAttrs (lib.map buildPackage newestPackages);
113114 defaultDerivation = {
115+ ${pname} = (buildPackage (lib.head newestPackages)).value;
116 };
117 in
118+ # NOTE: Must condition on the length of newestPackages to avoid non-total function lib.head aborting if
119+ # newestPackages is empty.
120+ lib.optionalAttrs (lib.length newestPackages > 0) (versionedDerivations // defaultDerivation);
121in
122extension