push sheeet
Some checks failed
Periodic Merges (6h) / master → staging-nixos (push) Failing after 12m50s
Periodic Merges (6h) / master → staging-next (push) Failing after 12m54s
Periodic Merges (24h) / merge-base(master,staging) → haskell-updates (push) Failing after 11m54s
Periodic Merges (6h) / staging-next → staging (push) Failing after 12m13s
Periodic Merges (24h) / staging-next-25.05 → staging-25.05 (push) Failing after 13m24s
Periodic Merges (24h) / release-25.05 → staging-next-25.05 (push) Failing after 14m28s

This commit is contained in:
Dark Steveneq
2025-10-09 14:15:47 +02:00
commit 646b892680
49168 changed files with 5897842 additions and 0 deletions

View File

@@ -0,0 +1,139 @@
{ _cuda, lib }:
{
/**
Evaluate assertions and add error context to return value.
NOTE: No guarantees are made about this function's stability. You may use it at your own risk.
# Type
```
_evaluateAssertions
:: (assertions :: List { assertion :: Bool, message :: String })
-> Bool
```
*/
_evaluateAssertions =
assertions:
let
failedAssertionsString = _cuda.lib._mkFailedAssertionsString assertions;
in
if failedAssertionsString == "" then
true
else
lib.addErrorContext "with failed assertions:${failedAssertionsString}" false;
/**
Function to generate a string of failed assertions.
NOTE: No guarantees are made about this function's stability. You may use it at your own risk.
# Type
```
_mkFailedAssertionsString
:: (assertions :: List { assertion :: Bool, message :: String })
-> String
```
# Inputs
`assertions`
: A list of assertions to evaluate
# Examples
:::{.example}
## `_cuda.lib._mkFailedAssertionsString` usage examples
```nix
_mkFailedAssertionsString [
{ assertion = false; message = "Assertion 1 failed"; }
{ assertion = true; message = "Assertion 2 failed"; }
]
=> "\n- Assertion 1 failed"
```
```nix
_mkFailedAssertionsString [
{ assertion = false; message = "Assertion 1 failed"; }
{ assertion = false; message = "Assertion 2 failed"; }
]
=> "\n- Assertion 1 failed\n- Assertion 2 failed"
```
:::
*/
_mkFailedAssertionsString = lib.foldl' (
failedAssertionsString:
{ assertion, message }:
failedAssertionsString + lib.optionalString (!assertion) ("\n- " + message)
) "";
/**
Utility function to generate assertions for missing packages.
Used to mark a package as unsupported if any of its required packages are missing (null).
Expects a set of attributes.
Most commonly used in overrides files on a callPackage-provided attribute set of packages.
NOTE: We typically use platfromAssertions instead of brokenAssertions because the presence of packages set to null
means evaluation will fail if package attributes are accessed without checking for null first. OfBorg evaluation
sets allowBroken to true, which means we can't rely on brokenAssertions to prevent evaluation of a package with
missing dependencies.
NOTE: No guarantees are made about this function's stability. You may use it at your own risk.
# Type
```
_mkMissingPackagesAssertions
:: (attrs :: AttrSet)
-> (assertions :: List { assertion :: Bool, message :: String })
```
# Inputs
`attrs`
: The attributes to check for null
# Examples
:::{.example}
## `_cuda.lib._mkMissingPackagesAssertions` usage examples
```nix
{
lib,
libcal ? null,
libcublas,
utils,
}:
let
inherit (lib.attrsets) recursiveUpdate;
inherit (_cuda.lib) _mkMissingPackagesAssertions;
in
prevAttrs: {
passthru = prevAttrs.passthru or { } // {
platformAssertions =
prevAttrs.passthru.platformAssertions or [ ]
++ _mkMissingPackagesAssertions { inherit libcal; };
};
}
```
:::
*/
_mkMissingPackagesAssertions = lib.flip lib.pipe [
# Take the attributes that are null.
(lib.filterAttrs (_: value: value == null))
lib.attrNames
# Map them to assertions.
(lib.map (name: {
message = "${name} is available";
assertion = false;
}))
];
}

View File

@@ -0,0 +1,129 @@
{ lib }:
{
/**
Returns whether a capability should be built by default for a particular CUDA version.
Capabilities built by default are baseline, non-Jetson capabilities with relatively recent CUDA support.
NOTE: No guarantees are made about this function's stability. You may use it at your own risk.
# Type
```
_cudaCapabilityIsDefault
:: (cudaMajorMinorVersion :: Version)
-> (cudaCapabilityInfo :: CudaCapabilityInfo)
-> Bool
```
# Inputs
`cudaMajorMinorVersion`
: The CUDA version to check
`cudaCapabilityInfo`
: The capability information to check
*/
_cudaCapabilityIsDefault =
cudaMajorMinorVersion: cudaCapabilityInfo:
let
recentCapability =
cudaCapabilityInfo.dontDefaultAfterCudaMajorMinorVersion == null
|| lib.versionAtLeast cudaCapabilityInfo.dontDefaultAfterCudaMajorMinorVersion cudaMajorMinorVersion;
in
recentCapability
&& !cudaCapabilityInfo.isJetson
&& !cudaCapabilityInfo.isArchitectureSpecific
&& !cudaCapabilityInfo.isFamilySpecific;
/**
Returns whether a capability is supported for a particular CUDA version.
NOTE: No guarantees are made about this function's stability. You may use it at your own risk.
# Type
```
_cudaCapabilityIsSupported
:: (cudaMajorMinorVersion :: Version)
-> (cudaCapabilityInfo :: CudaCapabilityInfo)
-> Bool
```
# Inputs
`cudaMajorMinorVersion`
: The CUDA version to check
`cudaCapabilityInfo`
: The capability information to check
*/
_cudaCapabilityIsSupported =
cudaMajorMinorVersion: cudaCapabilityInfo:
let
lowerBoundSatisfied = lib.versionAtLeast cudaMajorMinorVersion cudaCapabilityInfo.minCudaMajorMinorVersion;
upperBoundSatisfied =
cudaCapabilityInfo.maxCudaMajorMinorVersion == null
|| lib.versionAtLeast cudaCapabilityInfo.maxCudaMajorMinorVersion cudaMajorMinorVersion;
in
lowerBoundSatisfied && upperBoundSatisfied;
/**
Generates a CUDA variant name from a version.
NOTE: No guarantees are made about this function's stability. You may use it at your own risk.
# Type
```
_mkCudaVariant :: (version :: String) -> String
```
# Inputs
`version`
: The version string
# Examples
:::{.example}
## `_cuda.lib._mkCudaVariant` usage examples
```nix
_mkCudaVariant "11.0"
=> "cuda11"
```
:::
*/
_mkCudaVariant = version: "cuda${lib.versions.major version}";
/**
A predicate which, given a package, returns true if the package has a free license or one of NVIDIA's licenses.
This function is intended to be provided as `config.allowUnfreePredicate` when `import`-ing Nixpkgs.
# Type
```
allowUnfreeCudaPredicate :: (package :: Package) -> Bool
```
*/
allowUnfreeCudaPredicate =
package:
lib.all (
license:
license.free
|| lib.elem license.shortName [
"CUDA EULA"
"cuDNN EULA"
"cuSPARSELt EULA"
"cuTENSOR EULA"
"NVidia OptiX EULA"
]
) (lib.toList package.meta.license);
}

View File

@@ -0,0 +1,52 @@
{
_cuda,
lib,
}:
{
# See ./assertions.nix for documentation.
inherit (import ./assertions.nix { inherit _cuda lib; })
_evaluateAssertions
_mkFailedAssertionsString
_mkMissingPackagesAssertions
;
# See ./cuda.nix for documentation.
inherit (import ./cuda.nix { inherit lib; })
_cudaCapabilityIsDefault
_cudaCapabilityIsSupported
_mkCudaVariant
allowUnfreeCudaPredicate
;
# See ./meta.nix for documentation.
inherit (import ./meta.nix { inherit _cuda lib; })
_mkMetaBadPlatforms
_mkMetaBroken
;
# See ./redist.nix for documentation.
inherit (import ./redist.nix { inherit _cuda lib; })
_redistSystemIsSupported
getNixSystems
getRedistSystem
mkRedistUrl
;
# See ./strings.nix for documentation.
inherit (import ./strings.nix { inherit _cuda lib; })
dotsToUnderscores
dropDots
formatCapabilities
mkCmakeCudaArchitecturesString
mkGencodeFlag
mkRealArchitecture
mkVersionedName
mkVirtualArchitecture
;
# See ./versions.nix for documentation.
inherit (import ./versions.nix { inherit _cuda lib; })
majorMinorPatch
trimComponents
;
}

View File

@@ -0,0 +1,71 @@
{ _cuda, lib }:
{
/**
Returns a list of bad platforms for a given package if assertsions in `finalAttrs.passthru.platformAssertions`
fail, optionally logging evaluation warnings for each reason.
NOTE: No guarantees are made about this function's stability. You may use it at your own risk.
NOTE: This function requires `finalAttrs.passthru.platformAssertions` to be a list of assertions and
`finalAttrs.finalPackage.name` and `finalAttrs.finalPackage.stdenv` to be available.
# Type
```
_mkMetaBadPlatforms :: (warn :: Bool) -> (finalAttrs :: AttrSet) -> List String
```
*/
_mkMetaBadPlatforms =
warn: finalAttrs:
let
failedAssertionsString = _cuda.lib._mkFailedAssertionsString finalAttrs.passthru.platformAssertions;
hasFailedAssertions = failedAssertionsString != "";
finalStdenv = finalAttrs.finalPackage.stdenv;
in
lib.warnIf (warn && hasFailedAssertions)
"Package ${finalAttrs.finalPackage.name} is unsupported on this platform due to the following failed assertions:${failedAssertionsString}"
(
lib.optionals hasFailedAssertions (
lib.unique [
finalStdenv.buildPlatform.system
finalStdenv.hostPlatform.system
finalStdenv.targetPlatform.system
]
)
);
/**
Returns a boolean indicating whether the package is broken as a result of `finalAttrs.passthru.brokenAssertions`,
optionally logging evaluation warnings for each reason.
NOTE: No guarantees are made about this function's stability. You may use it at your own risk.
NOTE: This function requires `finalAttrs.passthru.brokenAssertions` to be a list of assertions and
`finalAttrs.finalPackage.name` to be available.
# Type
```
_mkMetaBroken :: (warn :: Bool) -> (finalAttrs :: AttrSet) -> Bool
```
# Inputs
`warn`
: A boolean indicating whether to log warnings
`finalAttrs`
: The final attributes of the package
*/
_mkMetaBroken =
warn: finalAttrs:
let
failedAssertionsString = _cuda.lib._mkFailedAssertionsString finalAttrs.passthru.brokenAssertions;
hasFailedAssertions = failedAssertionsString != "";
in
lib.warnIf (warn && hasFailedAssertions)
"Package ${finalAttrs.finalPackage.name} is marked as broken due to the following failed assertions:${failedAssertionsString}"
hasFailedAssertions;
}

View File

@@ -0,0 +1,196 @@
{ _cuda, lib }:
{
/**
Returns a boolean indicating whether the provided redist system is supported by any of the provided redist systems.
NOTE: No guarantees are made about this function's stability. You may use it at your own risk.
# Type
```
_redistSystemIsSupported
:: (redistSystem :: RedistSystem)
-> (redistSystems :: List RedistSystem)
-> Bool
```
# Inputs
`redistSystem`
: The redist system to check
`redistSystems`
: The list of redist systems to check against
# Examples
:::{.example}
## `cudaLib._redistSystemIsSupported` usage examples
```nix
_redistSystemIsSupported "linux-x86_64" [ "linux-x86_64" ]
=> true
```
```nix
_redistSystemIsSupported "linux-x86_64" [ "linux-aarch64" ]
=> false
```
```nix
_redistSystemIsSupported "linux-x86_64" [ "linux-aarch64" "linux-x86_64" ]
=> true
```
```nix
_redistSystemIsSupported "linux-x86_64" [ "linux-aarch64" "linux-all" ]
=> true
```
:::
*/
_redistSystemIsSupported =
redistSystem: redistSystems:
lib.findFirst (
redistSystem':
redistSystem' == redistSystem || redistSystem' == "linux-all" || redistSystem' == "source"
) null redistSystems != null;
/**
Maps a NVIDIA redistributable system to Nix systems.
NOTE: This function returns a list of systems because the redistributable systems `"linux-all"` and `"source"` can
be built on multiple systems.
NOTE: This function *will* be called by unsupported systems because `cudaPackages` is evaluated on all systems. As
such, we need to handle unsupported systems gracefully.
# Type
```
getNixSystems :: (redistSystem :: RedistSystem) -> [String]
```
# Inputs
`redistSystem`
: The NVIDIA redistributable system
# Examples
:::{.example}
## `cudaLib.getNixSystems` usage examples
```nix
getNixSystems "linux-sbsa"
=> [ "aarch64-linux" ]
```
```nix
getNixSystems "linux-aarch64"
=> [ "aarch64-linux" ]
```
:::
*/
getNixSystems =
redistSystem:
if redistSystem == "linux-x86_64" then
[ "x86_64-linux" ]
else if redistSystem == "linux-sbsa" || redistSystem == "linux-aarch64" then
[ "aarch64-linux" ]
else if redistSystem == "linux-all" || redistSystem == "source" then
[
"aarch64-linux"
"x86_64-linux"
]
else
[ ];
/**
Maps a Nix system to a NVIDIA redistributable system.
NOTE: We swap out the default `linux-sbsa` redist (for server-grade ARM chips) with the `linux-aarch64` redist
(which is for Jetson devices) if we're building any Jetson devices. Since both are based on aarch64, we can only
have one or the other, otherwise there's an ambiguity as to which should be used.
NOTE: This function *will* be called by unsupported systems because `cudaPackages` is evaluated on all systems. As
such, we need to handle unsupported systems gracefully.
# Type
```
getRedistSystem :: (hasJetsonCudaCapability :: Bool) -> (nixSystem :: String) -> String
```
# Inputs
`hasJetsonCudaCapability`
: If configured for a Jetson device
`nixSystem`
: The Nix system
# Examples
:::{.example}
## `cudaLib.getRedistSystem` usage examples
```nix
getRedistSystem true "aarch64-linux"
=> "linux-aarch64"
```
```nix
getRedistSystem false "aarch64-linux"
=> "linux-sbsa"
```
:::
*/
getRedistSystem =
hasJetsonCudaCapability: nixSystem:
if nixSystem == "x86_64-linux" then
"linux-x86_64"
else if nixSystem == "aarch64-linux" then
if hasJetsonCudaCapability then "linux-aarch64" else "linux-sbsa"
else
"unsupported";
/**
Function to generate a URL for something in the redistributable tree.
# Type
```
mkRedistUrl :: (redistName :: RedistName) -> (relativePath :: NonEmptyStr) -> RedistUrl
```
# Inputs
`redistName`
: The name of the redistributable
`relativePath`
: The relative path to a file in the redistributable tree
*/
mkRedistUrl =
redistName: relativePath:
lib.concatStringsSep "/" (
[ _cuda.db.redistUrlPrefix ]
++ (
if redistName != "tensorrt" then
[
redistName
"redist"
]
else
[ "machine-learning" ]
)
++ [ relativePath ]
);
}

View File

@@ -0,0 +1,382 @@
{ _cuda, lib }:
let
cudaLib = _cuda.lib;
in
{
/**
Replaces dots in a string with underscores.
# Type
```
dotsToUnderscores :: (str :: String) -> String
```
# Inputs
`str`
: The string for which dots shall be replaced by underscores
# Examples
:::{.example}
## `cudaLib.dotsToUnderscores` usage examples
```nix
dotsToUnderscores "1.2.3"
=> "1_2_3"
```
:::
*/
dotsToUnderscores = lib.replaceStrings [ "." ] [ "_" ];
/**
Removes the dots from a string.
# Type
```
dropDots :: (str :: String) -> String
```
# Inputs
`str`
: The string to remove dots from
# Examples
:::{.example}
## `cudaLib.dropDots` usage examples
```nix
dropDots "1.2.3"
=> "123"
```
:::
*/
dropDots = lib.replaceStrings [ "." ] [ "" ];
/**
Produces an attribute set of useful data and functionality for packaging CUDA software within Nixpkgs.
# Type
```
formatCapabilities
:: { cudaCapabilityToInfo :: AttrSet CudaCapability CudaCapabilityInfo
, cudaCapabilities :: List CudaCapability
, cudaForwardCompat :: Bool
}
-> { cudaCapabilities :: List CudaCapability
, cudaForwardCompat :: Bool
, gencode :: List String
, realArches :: List String
, virtualArches :: List String
, archNames :: List String
, arches :: List String
, gencodeString :: String
, cmakeCudaArchitecturesString :: String
}
```
# Inputs
`cudaCapabilityToInfo`
: A mapping of CUDA capabilities to their information
`cudaCapabilities`
: A list of CUDA capabilities to use
`cudaForwardCompat`
: A boolean indicating whether to include the forward compatibility gencode (+PTX) to support future GPU
generations
*/
formatCapabilities =
{
cudaCapabilityToInfo,
cudaCapabilities,
cudaForwardCompat,
}:
let
/**
The real architectures for the given CUDA capabilities.
# Type
```
realArches :: List String
```
*/
realArches = lib.map cudaLib.mkRealArchitecture cudaCapabilities;
/**
The virtual architectures for the given CUDA capabilities.
These are typically used for forward compatibility, when trying to support an architecture newer than the CUDA
version allows.
# Type
```
virtualArches :: List String
```
*/
virtualArches = lib.map cudaLib.mkVirtualArchitecture cudaCapabilities;
/**
The gencode flags for the given CUDA capabilities.
# Type
```
gencode :: List String
```
*/
gencode =
let
base = lib.map (cudaLib.mkGencodeFlag "sm") cudaCapabilities;
forward = cudaLib.mkGencodeFlag "compute" (lib.last cudaCapabilities);
in
base ++ lib.optionals cudaForwardCompat [ forward ];
in
{
inherit
cudaCapabilities
cudaForwardCompat
gencode
realArches
virtualArches
;
/**
The architecture names for the given CUDA capabilities.
# Type
```
archNames :: List String
```
*/
# E.g. [ "Ampere" "Turing" ]
archNames = lib.pipe cudaCapabilities [
(lib.map (cudaCapability: cudaCapabilityToInfo.${cudaCapability}.archName))
lib.unique
lib.naturalSort
];
/**
The architectures for the given CUDA capabilities, including both real and virtual architectures.
When `cudaForwardCompat` is enabled, the last architecture in the list is used as the forward compatibility architecture.
# Type
```
arches :: List String
```
*/
# E.g. [ "sm_75" "sm_86" "compute_86" ]
arches = realArches ++ lib.optionals cudaForwardCompat [ (lib.last virtualArches) ];
/**
The CMake-compatible CUDA architectures string for the given CUDA capabilities.
# Type
```
cmakeCudaArchitecturesString :: String
```
*/
cmakeCudaArchitecturesString = cudaLib.mkCmakeCudaArchitecturesString cudaCapabilities;
/**
The gencode string for the given CUDA capabilities.
# Type
```
gencodeString :: String
```
*/
gencodeString = lib.concatStringsSep " " gencode;
};
/**
Produces a CMake-compatible CUDA architecture string from a list of CUDA capabilities.
# Type
```
mkCmakeCudaArchitecturesString :: (cudaCapabilities :: List String) -> String
```
# Inputs
`cudaCapabilities`
: The CUDA capabilities to convert
# Examples
:::{.example}
## `cudaLib.mkCmakeCudaArchitecturesString` usage examples
```nix
mkCmakeCudaArchitecturesString [ "8.9" "10.0a" ]
=> "89;100a"
```
:::
*/
mkCmakeCudaArchitecturesString = lib.concatMapStringsSep ";" cudaLib.dropDots;
/**
Produces a gencode flag from a CUDA capability.
# Type
```
mkGencodeFlag :: (archPrefix :: String) -> (cudaCapability :: String) -> String
```
# Inputs
`archPrefix`
: The architecture prefix to use for the `code` field
`cudaCapability`
: The CUDA capability to convert
# Examples
:::{.example}
## `cudaLib.mkGencodeFlag` usage examples
```nix
mkGencodeFlag "sm" "8.9"
=> "-gencode=arch=compute_89,code=sm_89"
```
```nix
mkGencodeFlag "compute" "10.0a"
=> "-gencode=arch=compute_100a,code=compute_100a"
```
:::
*/
mkGencodeFlag =
archPrefix: cudaCapability:
let
cap = cudaLib.dropDots cudaCapability;
in
"-gencode=arch=compute_${cap},code=${archPrefix}_${cap}";
/**
Produces a real architecture string from a CUDA capability.
# Type
```
mkRealArchitecture :: (cudaCapability :: String) -> String
```
# Inputs
`cudaCapability`
: The CUDA capability to convert
# Examples
:::{.example}
## `cudaLib.mkRealArchitecture` usage examples
```nix
mkRealArchitecture "8.9"
=> "sm_89"
```
```nix
mkRealArchitecture "10.0a"
=> "sm_100a"
```
:::
*/
mkRealArchitecture = cudaCapability: "sm_" + cudaLib.dropDots cudaCapability;
/**
Create a versioned attribute name from a version by replacing dots with underscores.
# Type
```
mkVersionedName :: (name :: String) -> (version :: Version) -> String
```
# Inputs
`name`
: The name to use
`version`
: The version to use
# Examples
:::{.example}
## `cudaLib.mkVersionedName` usage examples
```nix
mkVersionedName "hello" "1.2.3"
=> "hello_1_2_3"
```
```nix
mkVersionedName "cudaPackages" "12.8"
=> "cudaPackages_12_8"
```
:::
*/
mkVersionedName = name: version: "${name}_${cudaLib.dotsToUnderscores version}";
/**
Produces a virtual architecture string from a CUDA capability.
# Type
```
mkVirtualArchitecture :: (cudaCapability :: String) -> String
```
# Inputs
`cudaCapability`
: The CUDA capability to convert
# Examples
:::{.example}
## `cudaLib.mkVirtualArchitecture` usage examples
```nix
mkVirtualArchitecture "8.9"
=> "compute_89"
```
```nix
mkVirtualArchitecture "10.0a"
=> "compute_100a"
```
:::
*/
mkVirtualArchitecture = cudaCapability: "compute_" + cudaLib.dropDots cudaCapability;
}

View File

@@ -0,0 +1,79 @@
{ _cuda, lib }:
let
cudaLib = _cuda.lib;
in
{
/**
Extracts the major, minor, and patch version from a string.
# Type
```
majorMinorPatch :: (version :: String) -> String
```
# Inputs
`version`
: The version string
# Examples
:::{.example}
## `_cuda.lib.majorMinorPatch` usage examples
```nix
majorMinorPatch "11.0.3.4"
=> "11.0.3"
```
:::
*/
majorMinorPatch = cudaLib.trimComponents 3;
/**
Get a version string with no more than than the specified number of components.
# Type
```
trimComponents :: (numComponents :: Integer) -> (version :: String) -> String
```
# Inputs
`numComponents`
: A positive integer corresponding to the maximum number of components to keep
`version`
: A version string
# Examples
:::{.example}
## `_cuda.lib.trimComponents` usage examples
```nix
trimComponents 1 "1.2.3.4"
=> "1"
```
```nix
trimComponents 3 "1.2.3.4"
=> "1.2.3"
```
```nix
trimComponents 9 "1.2.3.4"
=> "1.2.3.4"
```
:::
*/
trimComponents =
n: v:
lib.pipe v [
lib.splitVersion
(lib.take n)
(lib.concatStringsSep ".")
];
}