From 143898cad89f23fab3742de03330e120be2b678e Mon Sep 17 00:00:00 2001 From: Connor Baker Date: Sun, 11 May 2025 15:52:09 +0000 Subject: [PATCH 1/2] cudaPackages: multiplex builder provides broken attributes rather than no attributes Signed-off-by: Connor Baker --- pkgs/development/cuda-modules/cudnn/shims.nix | 3 +- .../generic-builders/multiplex.nix | 40 ++++++++++++++----- .../cuda-modules/tensorrt/shims.nix | 3 +- 3 files changed, 32 insertions(+), 14 deletions(-) diff --git a/pkgs/development/cuda-modules/cudnn/shims.nix b/pkgs/development/cuda-modules/cudnn/shims.nix index 9cb879b363bf..0a7f09bc9f0f 100644 --- a/pkgs/development/cuda-modules/cudnn/shims.nix +++ b/pkgs/development/cuda-modules/cudnn/shims.nix @@ -1,13 +1,12 @@ # Shims to mimic the shape of ../modules/generic/manifests/{feature,redistrib}/release.nix { - lib, package, # redistArch :: String # String is "unsupported" if the given architecture is unsupported. redistArch, }: { - featureRelease = lib.optionalAttrs (redistArch != "unsupported") { + featureRelease = { inherit (package) minCudaVersion maxCudaVersion; ${redistArch}.outputs = { lib = true; diff --git a/pkgs/development/cuda-modules/generic-builders/multiplex.nix b/pkgs/development/cuda-modules/generic-builders/multiplex.nix index 3e2958449dc0..8d5c7c1e359d 100644 --- a/pkgs/development/cuda-modules/generic-builders/multiplex.nix +++ b/pkgs/development/cuda-modules/generic-builders/multiplex.nix @@ -52,12 +52,27 @@ let lib.versionAtLeast cudaMajorMinorVersion package.minCudaVersion && lib.versionAtLeast package.maxCudaVersion cudaMajorMinorVersion; - # Releases for our platform and CUDA version. + # Releases for our CUDA version. + # Collapses the releases into a single list of packages, filtering out packages for unsupported CUDA versions and + # augmenting those supporting the current CUDA version with the redistArch to which the package belongs. # See ../modules/${pname}/releases/releases.nix - # allPackages :: List Package - allPackages = lib.filter satisfiesCudaVersion ( - evaluatedModules.config.${pname}.releases.${redistArch} or [ ] - ); + # allPackages :: List (Package + { redistArch: String }) + allPackages = + let + redistArchs = lib.attrNames evaluatedModules.config.${pname}.releases; + in + lib.concatMap ( + redistArch: + let + packages = evaluatedModules.config.${pname}.releases.${redistArch}; + in + lib.concatMap ( + package: lib.optionals (satisfiesCudaVersion package) [ ({ inherit redistArch; } // package) ] + ) packages + ) redistArchs; + + packageOlder = p1: p2: lib.versionOlder p1.version p2.version; + packageSupportedPlatform = p: p.redistArch == redistArch; # Compute versioned attribute name to be used in this package set # Patch version changes should not break the build, so we only use major and minor @@ -77,8 +92,15 @@ let newestPackages // { ${majorMinorVersion} = - # Only keep the existing package if it is newer than the one we are considering. - if existingPackage != null && lib.versionOlder package.version existingPackage.version then + # Only keep the existing package if it is newer than the one we are considering or it is supported on the + # current platform and the one we are considering is not. + if + existingPackage != null + && ( + packageOlder package existingPackage + || (!packageSupportedPlatform package && packageSupportedPlatform existingPackage) + ) + then existingPackage else package; @@ -87,9 +109,7 @@ let in # Sort the packages by version so the newest is first. # NOTE: builtins.sort requires a strict weak ordering, so we must use versionOlder rather than versionAtLeast. - lib.sort (p1: p2: lib.versionOlder p2.version p1.version) ( - lib.attrValues newestForEachMajorMinorVersion - ); + lib.sort (lib.flip packageOlder) (lib.attrValues newestForEachMajorMinorVersion); extension = final: _: diff --git a/pkgs/development/cuda-modules/tensorrt/shims.nix b/pkgs/development/cuda-modules/tensorrt/shims.nix index 7832f8e97c51..d347ef7e294c 100644 --- a/pkgs/development/cuda-modules/tensorrt/shims.nix +++ b/pkgs/development/cuda-modules/tensorrt/shims.nix @@ -1,13 +1,12 @@ # Shims to mimic the shape of ../modules/generic/manifests/{feature,redistrib}/release.nix { - lib, package, # redistArch :: String # String is `"unsupported"` if the given architecture is unsupported. redistArch, }: { - featureRelease = lib.optionalAttrs (redistArch != "unsupported") { + featureRelease = { inherit (package) cudnnVersion minCudaVersion maxCudaVersion; ${redistArch}.outputs = { bin = true; From 19d4f53b72f8526f1aa27712d40fdc77f2262839 Mon Sep 17 00:00:00 2001 From: Connor Baker Date: Sun, 11 May 2025 17:27:19 +0000 Subject: [PATCH 2/2] fixup! cudaPackages: multiplex builder provides broken attributes rather than no attributes fixup! cudaPackages: simplify multiplex builder's allPackages Signed-off-by: Connor Baker --- .../generic-builders/multiplex.nix | 30 ++++++++----------- 1 file changed, 12 insertions(+), 18 deletions(-) diff --git a/pkgs/development/cuda-modules/generic-builders/multiplex.nix b/pkgs/development/cuda-modules/generic-builders/multiplex.nix index 8d5c7c1e359d..816a375e620f 100644 --- a/pkgs/development/cuda-modules/generic-builders/multiplex.nix +++ b/pkgs/development/cuda-modules/generic-builders/multiplex.nix @@ -52,24 +52,17 @@ let lib.versionAtLeast cudaMajorMinorVersion package.minCudaVersion && lib.versionAtLeast package.maxCudaVersion cudaMajorMinorVersion; - # Releases for our CUDA version. - # Collapses the releases into a single list of packages, filtering out packages for unsupported CUDA versions and - # augmenting those supporting the current CUDA version with the redistArch to which the package belongs. - # See ../modules/${pname}/releases/releases.nix - # allPackages :: List (Package + { redistArch: String }) - allPackages = - let - redistArchs = lib.attrNames evaluatedModules.config.${pname}.releases; - in - lib.concatMap ( - redistArch: - let - packages = evaluatedModules.config.${pname}.releases.${redistArch}; - in - lib.concatMap ( - package: lib.optionals (satisfiesCudaVersion package) [ ({ inherit redistArch; } // package) ] - ) packages - ) redistArchs; + # FIXME: do this at the module system level + propagatePlatforms = lib.mapAttrs (redistArch: lib.map (p: { inherit redistArch; } // p)); + + # Releases for all platforms and all CUDA versions. + allReleases = propagatePlatforms evaluatedModules.config.${pname}.releases; + + # Releases for all platforms and our CUDA version. + allReleases' = lib.mapAttrs (_: lib.filter satisfiesCudaVersion) allReleases; + + # Packages for all platforms and our CUDA versions. + allPackages = lib.concatLists (lib.attrValues allReleases'); packageOlder = p1: p2: lib.versionOlder p1.version p2.version; packageSupportedPlatform = p: p.redistArch == redistArch; @@ -109,6 +102,7 @@ let in # Sort the packages by version so the newest is first. # NOTE: builtins.sort requires a strict weak ordering, so we must use versionOlder rather than versionAtLeast. + # See https://github.com/NixOS/nixpkgs/commit/9fd753ea84e5035b357a275324e7fd7ccfb1fc77. lib.sort (lib.flip packageOlder) (lib.attrValues newestForEachMajorMinorVersion); extension =