2 # callPackage-provided arguments
7 # Expected to be passed by the caller
8 mkVersionedPackageName,
11 # releasesModule :: Path
12 # A path to a module which provides a `releases` attribute
15 # A path to a module which provides a `shims` attribute
16 # The redistribRelease is only used in ./manifest.nix for the package version
17 # and the package description (which NVIDIA's manifest calls the "name").
18 # It's also used for fetching the source, but we override that since we can't
19 # re-use that portion of the functionality (different URLs, etc.).
20 # The featureRelease is used to populate meta.platforms (by way of looking at the attribute names)
21 # and to determine the outputs of the package.
22 # shimFn :: {package, redistArch} -> AttrSet
23 shimsFn ? (throw "shimsFn must be provided"),
25 # A path (or nix expression) to be evaluated with callPackage and then
26 # provided to the package's overrideAttrs function.
27 # It must accept at least the following arguments:
30 # - mkVersionedPackageName
33 fixupFn ? (throw "fixupFn must be provided"),
43 inherit (stdenv) hostPlatform;
45 evaluatedModules = modules.evalModules {
52 # NOTE: Important types:
53 # - Releases: ../modules/${pname}/releases/releases.nix
54 # - Package: ../modules/${pname}/releases/package.nix
56 # FIXME: do this at the module system level
57 propagatePlatforms = lib.mapAttrs (
58 redistArch: packages: map (p: { inherit redistArch; } // p) packages
61 # All releases across all platforms
62 # See ../modules/${pname}/releases/releases.nix
63 releaseSets = propagatePlatforms evaluatedModules.config.${pname}.releases;
65 # Compute versioned attribute name to be used in this package set
66 # Patch version changes should not break the build, so we only use major and minor
67 # computeName :: Package -> String
68 computeName = { version, ... }: mkVersionedPackageName pname version;
70 # Check whether a package supports our CUDA version and platform.
71 # isSupported :: Package -> Bool
74 redistArch == package.redistArch
75 && strings.versionAtLeast cudaVersion package.minCudaVersion
76 && strings.versionAtLeast package.maxCudaVersion cudaVersion;
78 # Get all of the packages for our given platform.
79 # redistArch :: String
80 # Value is `"unsupported"` if the platform is not supported.
81 redistArch = flags.getRedistArch hostPlatform.system;
84 p1: p2: (isSupported p2 -> isSupported p1) && (strings.versionAtLeast p1.version p2.version);
86 # All the supported packages we can build for our platform.
87 # perSystemReleases :: List Package
88 allReleases = lib.pipe releaseSets [
91 (lib.groupBy (p: lib.versions.majorMinor p.version))
92 (lib.mapAttrs (_: builtins.sort preferable))
93 (lib.mapAttrs (_: lib.take 1))
95 (lib.concatMap lib.trivial.id)
98 newest = builtins.head (builtins.sort preferable allReleases);
100 # A function which takes the `final` overlay and the `package` being built and returns
101 # a function to be consumed via `overrideAttrs`.
102 overrideAttrsFixupFn =
104 final.callPackage fixupFn {
108 mkVersionedPackageName
116 # Builds our package into derivation and wraps it in a nameValuePair, where the name is the versioned name
121 shims = final.callPackage shimsFn {
123 inherit (package) redistArch;
125 name = computeName package;
126 drv = final.callPackage ./manifest.nix {
129 inherit (shims) redistribRelease featureRelease;
131 fixedDrv = drv.overrideAttrs (overrideAttrsFixupFn final package);
133 attrsets.nameValuePair name fixedDrv;
135 # versionedDerivations :: AttrSet Derivation
136 versionedDerivations = builtins.listToAttrs (lists.map buildPackage allReleases);
138 defaultDerivation = {
139 ${pname} = (buildPackage newest).value;
142 versionedDerivations // defaultDerivation;