diff options
author | Connor Baker <connor.baker@tweag.io> | 2023-12-14 22:19:02 +0000 |
---|---|---|
committer | Connor Baker <connor.baker@tweag.io> | 2024-01-10 01:15:01 +0000 |
commit | 9bebd9e72d6b552fcfd3d1e6716eca6563944f42 (patch) | |
tree | d0b45b861d0d47be9e43c26481f68ce53a3d6987 /pkgs/development/cuda-modules/generic-builders | |
parent | 501a1af970ca54cb300474a00aacfbd01f8a5b24 (diff) |
tree-wide: cudaPackages should not break default eval
cudaPackages: guard expressions against null values
Diffstat (limited to 'pkgs/development/cuda-modules/generic-builders')
-rw-r--r-- | pkgs/development/cuda-modules/generic-builders/manifest.nix | 62 | ||||
-rw-r--r-- | pkgs/development/cuda-modules/generic-builders/multiplex.nix | 18 |
2 files changed, 46 insertions, 34 deletions
diff --git a/pkgs/development/cuda-modules/generic-builders/manifest.nix b/pkgs/development/cuda-modules/generic-builders/manifest.nix index 5a4c5280d7dbd..64204346791a8 100644 --- a/pkgs/development/cuda-modules/generic-builders/manifest.nix +++ b/pkgs/development/cuda-modules/generic-builders/manifest.nix @@ -42,6 +42,9 @@ let # Get the redist architectures for which package provides distributables. # These are used by meta.platforms. supportedRedistArchs = builtins.attrNames featureRelease; + # redistArch :: String + # The redistArch is the name of the architecture for which the redistributable is built. + # It is `"unsupported"` if the redistributable is not supported on the target platform. redistArch = flags.getRedistArch hostPlatform.system; in backendStdenv.mkDerivation ( @@ -86,8 +89,18 @@ backendStdenv.mkDerivation ( "sample" "python" ]; + # Filter out outputs that don't exist in the redistributable. + # NOTE: In the case the redistributable isn't supported on the target platform, + # we will have `outputs = [ "out" ] ++ possibleOutputs`. This is of note because platforms which + # aren't supported would otherwise have evaluation errors when trying to access outputs other than `out`. + # The alternative would be to have `outputs = [ "out" ]` when`redistArch = "unsupported"`, but that would + # require adding guards throughout the entirety of the CUDA package set to ensure `cudaSupport` is true -- + # recall that OfBorg will evaluate packages marked as broken and that `cudaPackages` will be evaluated with + # `cudaSupport = false`! additionalOutputs = - if redistArch == "unsupported" then possibleOutputs else builtins.filter hasOutput possibleOutputs; + if redistArch == "unsupported" + then possibleOutputs + else builtins.filter hasOutput possibleOutputs; # The out output is special -- it's the default output and we always include it. outputs = [ "out" ] ++ additionalOutputs; in @@ -114,19 +127,28 @@ backendStdenv.mkDerivation ( # Useful for introspecting why something went wrong. # Maps descriptions of why the derivation would be marked broken to # booleans indicating whether that description is true. - brokenConditions = {}; - - src = fetchurl { - url = - if (builtins.hasAttr redistArch redistribRelease) then - "https://developer.download.nvidia.com/compute/${redistName}/redist/${ - redistribRelease.${redistArch}.relative_path - }" - else - "cannot-construct-an-url-for-the-${redistArch}-platform"; - sha256 = redistribRelease.${redistArch}.sha256 or lib.fakeHash; + # brokenConditions :: AttrSet Bool + brokenConditions = { + # Using an unrecognized redistArch + "Unrecognized NixOS platform ${hostPlatform.system}" = redistArch == "unsupported"; + # Trying to build for a platform that doesn't have a redistributable + "Unsupported NixOS platform (or configuration) ${hostPlatform.system}" = finalAttrs.src == null; }; + # src :: Optional Derivation + src = trivial.pipe redistArch [ + # If redistArch doesn't exist in redistribRelease, return null. + (redistArch: redistribRelease.${redistArch} or null) + # If the release is non-null, fetch the source; otherwise, return null. + (trivial.mapNullable ( + { relative_path, sha256, ... }: + fetchurl { + url = "https://developer.download.nvidia.com/compute/${redistName}/redist/${relative_path}"; + inherit sha256; + } + )) + ]; + postPatch = '' if [[ -d pkg-config ]] ; then mkdir -p share/pkg-config @@ -284,16 +306,12 @@ backendStdenv.mkDerivation ( meta = { description = "${redistribRelease.name}. By downloading and using the packages you accept the terms and conditions of the ${finalAttrs.meta.license.shortName}"; sourceProvenance = [sourceTypes.binaryNativeCode]; - platforms = - lists.concatMap - ( - redistArch: - let - nixSystem = flags.getNixSystem redistArch; - in - lists.optionals (!(strings.hasPrefix "unsupported-" nixSystem)) [ nixSystem ] - ) - supportedRedistArchs; + platforms = trivial.pipe supportedRedistArchs [ + # Map each redist arch to the equivalent nix system or null if there is no equivalent. + (builtins.map flags.getNixSystem) + # Filter out unsupported systems + (builtins.filter (nixSystem: !(strings.hasPrefix "unsupported-" nixSystem))) + ]; broken = lists.any trivial.id (attrsets.attrValues finalAttrs.brokenConditions); license = licenses.unfree; maintainers = teams.cuda.members; diff --git a/pkgs/development/cuda-modules/generic-builders/multiplex.nix b/pkgs/development/cuda-modules/generic-builders/multiplex.nix index 5480da7307261..6353b07545a4a 100644 --- a/pkgs/development/cuda-modules/generic-builders/multiplex.nix +++ b/pkgs/development/cuda-modules/generic-builders/multiplex.nix @@ -20,7 +20,7 @@ # The featureRelease is used to populate meta.platforms (by way of looking at the attribute names) # and to determine the outputs of the package. # shimFn :: {package, redistArch} -> AttrSet - shimsFn ? ({package, redistArch}: throw "shimsFn must be provided"), + shimsFn ? (throw "shimsFn must be provided"), # fixupFn :: Path # A path (or nix expression) to be evaluated with callPackage and then # provided to the package's overrideAttrs function. @@ -29,16 +29,8 @@ # - cudaVersion # - mkVersionedPackageName # - package - fixupFn ? ( - { - final, - cudaVersion, - mkVersionedPackageName, - package, - ... - }: - throw "fixupFn must be provided" - ), + # - ... + fixupFn ? (throw "fixupFn must be provided"), }: let inherit (lib) @@ -80,9 +72,11 @@ let && strings.versionAtLeast package.maxCudaVersion cudaVersion; # Get all of the packages for our given platform. + # redistArch :: String + # Value is `"unsupported"` if the platform is not supported. redistArch = flags.getRedistArch hostPlatform.system; - allReleases = builtins.concatMap (xs: xs) (builtins.attrValues releaseSets); + allReleases = lists.flatten (builtins.attrValues releaseSets); # All the supported packages we can build for our platform. # perSystemReleases :: List Package |