···
+
filterAndCreateOverrides =
+
createOverrideAttrs: final: prev:
+
# It is imperative that we use `final.callPackage` to perform overrides,
+
# so the final package set is available to the override functions.
+
inherit (final) callPackage;
+
# NOTE(@connorbaker): We MUST use `lib` from `prev` because the attribute
+
# names CAN NOT depend on `final`.
+
inherit (prev.lib.attrsets) filterAttrs mapAttrs;
+
inherit (prev.lib.trivial) pipe;
+
# NOTE: Filter out attributes that are not present in the previous version of
+
# the package set. This is necessary to prevent the appearance of attributes
+
# like `cuda_nvcc` in `cudaPackages_10_0, which predates redistributables.
+
filterOutNewAttrs = filterAttrs (name: _: prev ? ${name});
+
# Apply callPackage to each attribute value, yielding a value to be passed
+
callPackageThenOverrideAttrs = mapAttrs (
+
name: value: prev.${name}.overrideAttrs (callPackage value { })
+
pipe createOverrideAttrs [
+
callPackageThenOverrideAttrs
+
# Each attribute name is the name of an existing package in the previous version
+
# The value is a function (to be provided to callPackage), which yields a value
+
# to be provided to overrideAttrs. This allows us to override the attributes of
+
# a package without losing access to the fixed point of the package set --
+
# especially useful given that some packages may depend on each other!
+
filterAndCreateOverrides {
+
buildInputs = prevAttrs.buildInputs ++ [
+
# Before 11.7 libcufile depends on itself for some reason.
+
autoPatchelfIgnoreMissingDeps =
+
prevAttrs.autoPatchelfIgnoreMissingDeps
+
++ lib.lists.optionals (cudaOlder "11.7") [ "libcufile.so.0" ];
+
# Always depends on this
+
# Dependency from 12.0 and on
+
++ lib.lists.optionals (cudaAtLeast "12.0") [ libnvjitlink.lib ]
+
# Dependency from 12.1 and on
+
++ lib.lists.optionals (cudaAtLeast "12.1") [ libcusparse.lib ];
+
brokenConditions = prevAttrs.brokenConditions // {
+
"libnvjitlink missing (CUDA >= 12.0)" =
+
!(cudaAtLeast "12.0" -> (libnvjitlink != null && libnvjitlink.lib != null));
+
"libcusparse missing (CUDA >= 12.1)" =
+
!(cudaAtLeast "12.1" -> (libcusparse != null && libcusparse.lib != null));
+
# Dependency from 12.0 and on
+
++ lib.lists.optionals (cudaAtLeast "12.0") [ libnvjitlink.lib ];
+
brokenConditions = prevAttrs.brokenConditions // {
+
"libnvjitlink missing (CUDA >= 12.0)" =
+
!(cudaAtLeast "12.0" -> (libnvjitlink != null && libnvjitlink.lib != null));
+
# TODO(@connorbaker): cuda_cudart.dev depends on crt/host_config.h, which is from
+
# cuda_nvcc.dev. It would be nice to be able to encode that.
+
{ addDriverRunpath, lib }:
+
# Remove once cuda-find-redist-features has a special case for libcuda
+
++ lib.lists.optionals (!(builtins.elem "stubs" prevAttrs.outputs)) [ "stubs" ];
+
allowFHSReferences = false;
+
# The libcuda stub's pkg-config doesn't follow the general pattern:
+
prevAttrs.postPatch or ""
+
while IFS= read -r -d $'\0' path; do
+
-e "s|^libdir\s*=.*/lib\$|libdir=''${!outputLib}/lib/stubs|" \
+
-e "s|^Libs\s*:\(.*\)\$|Libs: \1 -Wl,-rpath,${addDriverRunpath.driverLink}/lib|" \
+
done < <(find -iname 'cuda-*.pc' -print0)
# Namelink may not be enough, add a soname.
# Cf. https://gitlab.kitware.com/cmake/cmake/-/issues/25536
+
if [[ -f lib/stubs/libcuda.so && ! -f lib/stubs/libcuda.so.1 ]]; then
+
ln -s libcuda.so lib/stubs/libcuda.so.1
+
prevAttrs.postFixup or ""
+
moveToOutput lib/stubs "$stubs"
+
ln -s "$stubs"/lib/stubs/* "$stubs"/lib/
+
ln -s "$stubs"/lib/stubs "''${!outputLib}/lib/stubs"
+
autoPatchelfIgnoreMissingDeps = prevAttrs.autoPatchelfIgnoreMissingDeps ++ [
+
# `cuda_compat` only works on aarch64-linux, and only when building for Jetson devices.
+
badPlatformsConditions = prevAttrs.badPlatformsConditions // {
+
"Trying to use cuda_compat on aarch64-linux targeting non-Jetson devices" = !flags.isJetsonBuild;
+
# x86_64 only needs gmp from 12.0 and on
+
++ lib.lists.optionals (cudaAtLeast "12.0") [ gmp ];
# Patch the nvcc.profile.
···
+
(prevAttrs.postPatch or "")
substituteInPlace bin/nvcc.profile \
'$(TOP)/$(_NVVM_BRANCH_)' \
···
cat << EOF >> bin/nvcc.profile
# Fix a compatible backend compiler
+
PATH += "${backendStdenv.cc}/bin":
# Expose the split-out nvvm
+
LIBRARIES =+ "-L''${!outputBin}/nvvm/lib"
+
INCLUDES =+ "-I''${!outputBin}/nvvm/include"
+
# Though it might seem odd or counter-intuitive to add the setup hook to `propagatedBuildInputs` instead of
+
# `propagatedNativeBuildInputs`, it is necessary! If you move the setup hook from `propagatedBuildInputs` to
+
# `propagatedNativeBuildInputs`, it stops being propagated to downstream packages during their build because
+
# setup hooks in `propagatedNativeBuildInputs` are not designed to affect the runtime or build environment of
+
# dependencies; they are only meant to affect the build environment of the package that directly includes them.
+
propagatedBuildInputs = (prevAttrs.propagatedBuildInputs or [ ]) ++ [ setupCudaHook ];
+
(prevAttrs.postInstall or "")
moveToOutput "nvvm" "''${!outputBin}"
···
# The nvcc and cicc binaries contain hard-coded references to /usr
allowFHSReferences = true;
+
meta = (prevAttrs.meta or { }) // {
+
{ cuda_cupti }: prevAttrs: { buildInputs = prevAttrs.buildInputs ++ [ cuda_cupti.lib ]; };
+
buildInputs = prevAttrs.buildInputs ++ [
+
inherit (lib.strings) versionOlder versionAtLeast;
+
inherit (prevAttrs) version;
+
qt = if versionOlder version "2022.2.0" then qt5 else qt6;
+
inherit (qt) wrapQtAppsHook qtwebview;
+
nativeBuildInputs = prevAttrs.nativeBuildInputs ++ [ wrapQtAppsHook ];
+
buildInputs = prevAttrs.buildInputs ++ [ qtwebview ];
+
brokenConditions = prevAttrs.brokenConditions // {
+
"Qt 5 missing (<2022.2.0)" = !(versionOlder version "2022.2.0" -> qt5 != null);
+
"Qt 6 missing (>=2022.2.0)" = !(versionAtLeast version "2022.2.0" -> qt6 != null);
+
inherit (lib.strings) versionOlder versionAtLeast;
+
inherit (prevAttrs) version;
+
qt = if lib.strings.versionOlder prevAttrs.version "2022.4.2.1" then qt5 else qt6;
if lib.versions.major qt.qtbase.version == "5" then
···
# An ad hoc replacement for
# https://github.com/ConnorBaker/cuda-redist-find-features/issues/11
env.rmPatterns = toString [
+
"nsight-systems/*/*/lib{arrow,jpeg}*"
+
"nsight-systems/*/*/lib{ssl,ssh,crypto}*"
+
"nsight-systems/*/*/libboost*"
+
"nsight-systems/*/*/libexec"
"nsight-systems/*/*/libQt*"
"nsight-systems/*/*/libstdc*"
"nsight-systems/*/*/Mesa"
+
"nsight-systems/*/*/Plugins"
"nsight-systems/*/*/python/bin/python"
prevAttrs.postPatch or ""
+
for path in $rmPatterns; do
nativeBuildInputs = prevAttrs.nativeBuildInputs ++ [ qt.wrapQtAppsHook ];
buildInputs = prevAttrs.buildInputs ++ [
(qt.qtdeclarative or qt.full)
+
gst_all_1.gst-plugins-base
+
brokenConditions = prevAttrs.brokenConditions // {
+
# Older releases require boost 1.70, which is deprecated in Nixpkgs
+
"CUDA too old (<11.8)" = cudaOlder "11.8";
+
"Qt 5 missing (<2022.4.2.1)" = !(versionOlder version "2022.4.2.1" -> qt5 != null);
+
"Qt 6 missing (>=2022.4.2.1)" = !(versionAtLeast version "2022.4.2.1" -> qt6 != null);
+
brokenConditions = prevAttrs.brokenConditions // {
+
"Package is not supported; use drivers from linuxPackages" = true;