3 # Silvan (Tweag) covered some things on recursive attribute sets in the Nix Hour:
4 # https://www.youtube.com/watch?v=BgnUFtd1Ivs
6 # I (@connorbaker) highly recommend watching it.
8 # Most helpful comment regarding recursive attribute sets:
10 # https://github.com/NixOS/nixpkgs/pull/256324#issuecomment-1749935979
14 # - `prev` should only be used to access attributes which are going to be overriden.
15 # - `final` should only be used to access `callPackage` to build new packages.
16 # - Attribute names should be computable without relying on `final`.
17 # - Extensions should take arguments to build attribute names before relying on `final`.
19 # Silvan's recommendation then is to explicitly use `callPackage` to provide everything our
20 # extensions need to compute the attribute names, without relying on `final`.
22 # I've (@connorbaker) attempted to do that, though I'm unsure of how this will interact with overrides.
42 gpus = builtins.import ../development/cuda-modules/gpus.nix;
43 nvccCompatibilities = builtins.import ../development/cuda-modules/nvcc-compatibilities.nix;
44 flags = callPackage ../development/cuda-modules/flags.nix { inherit cudaVersion gpus; };
45 passthruFunction = final: ({
46 inherit cudaVersion lib pkgs;
47 inherit gpus nvccCompatibilities flags;
48 cudaMajorVersion = versions.major cudaVersion;
49 cudaMajorMinorVersion = versions.majorMinor cudaVersion;
50 cudaOlder = strings.versionOlder cudaVersion;
51 cudaAtLeast = strings.versionAtLeast cudaVersion;
53 # Maintain a reference to the final cudaPackages.
54 # Without this, if we use `final.callPackage` and a package accepts `cudaPackages` as an
55 # argument, it's provided with `cudaPackages` from the top-level scope, which is not what we
56 # want. We want to provide the `cudaPackages` from the final scope -- that is, the *current*
57 # scope. However, we also want to prevent `pkgs/top-level/release-attrpaths-superset.nix` from
58 # recursing more than one level here.
59 cudaPackages = final // {
60 __attrsFailEvaluation = true;
63 # TODO(@connorbaker): `cudaFlags` is an alias for `flags` which should be removed in the future.
66 # Exposed as cudaPackages.backendStdenv.
67 # This is what nvcc uses as a backend,
68 # and it has to be an officially supported one (e.g. gcc11 for cuda11).
70 # It, however, propagates current stdenv's libstdc++ to avoid "GLIBCXX_* not found errors"
71 # when linked with other C++ libraries.
72 # E.g. for cudaPackages_11_8 we use gcc11 with gcc12's libstdc++
73 # Cf. https://github.com/NixOS/nixpkgs/pull/218265 for context
74 backendStdenv = final.callPackage ../development/cuda-modules/backend-stdenv.nix { };
78 # TODO: Move to aliases.nix once all Nixpkgs has migrated to the splayed CUDA packages
79 cudatoolkit = final.callPackage ../development/cuda-modules/cudatoolkit/redist-wrapper.nix { };
80 cudatoolkit-legacy-runfile = final.callPackage ../development/cuda-modules/cudatoolkit { };
82 saxpy = final.callPackage ../development/cuda-modules/saxpy { };
83 nccl = final.callPackage ../development/cuda-modules/nccl { };
84 nccl-tests = final.callPackage ../development/cuda-modules/nccl-tests { };
94 useOpenCVDefaultCuda = bools;
95 useTorchDefaultCuda = bools;
100 useOpenCVDefaultCuda,
104 name = strings.concatStringsSep "-" (
107 (if openCVFirst then "opencv" else "torch")
109 ++ lists.optionals (if openCVFirst then useOpenCVDefaultCuda else useTorchDefaultCuda) [
114 (if openCVFirst then "torch" else "opencv")
116 ++ lists.optionals (if openCVFirst then useTorchDefaultCuda else useOpenCVDefaultCuda) [
120 value = final.callPackage ../development/cuda-modules/tests/opencv-and-torch config;
123 attrsets.listToAttrs (attrsets.mapCartesianProduct builder configs);
125 writeGpuTestPython = final.callPackage ../development/cuda-modules/write-gpu-test-python.nix { };
128 mkVersionedPackageName =
130 strings.concatStringsSep "_" [
132 (strings.replaceStrings [ "." ] [ "_" ] (versions.majorMinor version))
135 composedExtension = fixedPoints.composeManyExtensions (
137 (import ../development/cuda-modules/setup-hooks/extension.nix)
138 (callPackage ../development/cuda-modules/cuda/extension.nix { inherit cudaVersion; })
139 (import ../development/cuda-modules/cuda/overrides.nix)
140 (callPackage ../development/cuda-modules/generic-builders/multiplex.nix {
141 inherit cudaVersion flags mkVersionedPackageName;
143 releasesModule = ../development/cuda-modules/cudnn/releases.nix;
144 shimsFn = ../development/cuda-modules/cudnn/shims.nix;
145 fixupFn = ../development/cuda-modules/cudnn/fixup.nix;
147 (callPackage ../development/cuda-modules/cutensor/extension.nix {
148 inherit cudaVersion flags mkVersionedPackageName;
150 (callPackage ../development/cuda-modules/generic-builders/multiplex.nix {
151 inherit cudaVersion flags mkVersionedPackageName;
153 releasesModule = ../development/cuda-modules/tensorrt/releases.nix;
154 shimsFn = ../development/cuda-modules/tensorrt/shims.nix;
155 fixupFn = ../development/cuda-modules/tensorrt/fixup.nix;
157 (callPackage ../development/cuda-modules/cuda-samples/extension.nix { inherit cudaVersion; })
158 (callPackage ../development/cuda-modules/cuda-library-samples/extension.nix { })
160 ++ lib.optionals config.allowAliases [ (import ../development/cuda-modules/aliases.nix) ]
163 cudaPackages = customisation.makeScope newScope (
164 fixedPoints.extends composedExtension passthruFunction
167 # We want to warn users about the upcoming deprecation of old CUDA
168 # versions, without breaking Nixpkgs CI with evaluation warnings. This
169 # gross hack ensures that the warning only triggers if aliases are
170 # enabled, which is true by default, but not for ofborg.
171 lib.warnIf (cudaPackages.cudaOlder "12.0" && config.allowAliases)
172 "CUDA versions older than 12.0 will be removed in Nixpkgs 25.05; see the 24.11 release notes for more information"