about summary refs log tree commit diff
path: root/nixpkgs/pkgs/development/cuda-modules
diff options
context:
space:
mode:
authorAlyssa Ross <hi@alyssa.is>2024-03-24 11:04:41 +0100
committerAlyssa Ross <hi@alyssa.is>2024-03-24 11:04:41 +0100
commit5423cabbbf2b6dec5568f1ecabd288d5d9a642ec (patch)
treef316a6a921bfefd3a63bd4502c2eb50ff1644f67 /nixpkgs/pkgs/development/cuda-modules
parent46a88117a05c3469af5d99433af140c3de8ca088 (diff)
parent8aa81f34981add12aecada6c702ddbbd0375ca36 (diff)
downloadnixlib-5423cabbbf2b6dec5568f1ecabd288d5d9a642ec.tar
nixlib-5423cabbbf2b6dec5568f1ecabd288d5d9a642ec.tar.gz
nixlib-5423cabbbf2b6dec5568f1ecabd288d5d9a642ec.tar.bz2
nixlib-5423cabbbf2b6dec5568f1ecabd288d5d9a642ec.tar.lz
nixlib-5423cabbbf2b6dec5568f1ecabd288d5d9a642ec.tar.xz
nixlib-5423cabbbf2b6dec5568f1ecabd288d5d9a642ec.tar.zst
nixlib-5423cabbbf2b6dec5568f1ecabd288d5d9a642ec.zip
Merge branch 'nixos-unstable-small' of https://github.com/NixOS/nixpkgs
Diffstat (limited to 'nixpkgs/pkgs/development/cuda-modules')
-rw-r--r--nixpkgs/pkgs/development/cuda-modules/cuda-samples/generic.nix4
-rw-r--r--nixpkgs/pkgs/development/cuda-modules/cudatoolkit/default.nix4
-rw-r--r--nixpkgs/pkgs/development/cuda-modules/generic-builders/manifest.nix12
-rw-r--r--nixpkgs/pkgs/development/cuda-modules/nccl/default.nix4
-rw-r--r--nixpkgs/pkgs/development/cuda-modules/saxpy/default.nix4
-rw-r--r--nixpkgs/pkgs/development/cuda-modules/setup-hooks/auto-add-cuda-compat-runpath.sh40
-rw-r--r--nixpkgs/pkgs/development/cuda-modules/setup-hooks/auto-add-driver-runpath-hook.sh8
-rw-r--r--nixpkgs/pkgs/development/cuda-modules/setup-hooks/auto-add-opengl-runpath-hook.sh28
-rw-r--r--nixpkgs/pkgs/development/cuda-modules/setup-hooks/auto-fix-elf-files.sh64
-rw-r--r--nixpkgs/pkgs/development/cuda-modules/setup-hooks/extension.nix34
10 files changed, 133 insertions, 69 deletions
diff --git a/nixpkgs/pkgs/development/cuda-modules/cuda-samples/generic.nix b/nixpkgs/pkgs/development/cuda-modules/cuda-samples/generic.nix
index fb3d7cc99da9..3d1dac015e16 100644
--- a/nixpkgs/pkgs/development/cuda-modules/cuda-samples/generic.nix
+++ b/nixpkgs/pkgs/development/cuda-modules/cuda-samples/generic.nix
@@ -1,5 +1,5 @@
 {
-  autoAddOpenGLRunpathHook,
+  autoAddDriverRunpath,
   backendStdenv,
   cmake,
   cudatoolkit,
@@ -31,7 +31,7 @@ backendStdenv.mkDerivation (
 
     nativeBuildInputs =
       [
-        autoAddOpenGLRunpathHook
+        autoAddDriverRunpath
         pkg-config
       ]
       # CMake has to run as a native, build-time dependency for libNVVM samples.
diff --git a/nixpkgs/pkgs/development/cuda-modules/cudatoolkit/default.nix b/nixpkgs/pkgs/development/cuda-modules/cudatoolkit/default.nix
index aca0c7ad0b78..231a153bf7e6 100644
--- a/nixpkgs/pkgs/development/cuda-modules/cudatoolkit/default.nix
+++ b/nixpkgs/pkgs/development/cuda-modules/cudatoolkit/default.nix
@@ -2,7 +2,7 @@
   cudaVersion,
   runPatches ? [],
   autoPatchelfHook,
-  autoAddOpenGLRunpathHook,
+  autoAddDriverRunpath,
   addOpenGLRunpath,
   alsa-lib,
   curlMinimal,
@@ -76,7 +76,7 @@ backendStdenv.mkDerivation rec {
       rsync
       addOpenGLRunpath
       autoPatchelfHook
-      autoAddOpenGLRunpathHook
+      autoAddDriverRunpath
       markForCudatoolkitRootHook
     ]
     ++ lib.optionals (lib.versionOlder version "11") [libsForQt5.wrapQtAppsHook]
diff --git a/nixpkgs/pkgs/development/cuda-modules/generic-builders/manifest.nix b/nixpkgs/pkgs/development/cuda-modules/generic-builders/manifest.nix
index 5e837fa36b5e..4f40b7f01dc2 100644
--- a/nixpkgs/pkgs/development/cuda-modules/generic-builders/manifest.nix
+++ b/nixpkgs/pkgs/development/cuda-modules/generic-builders/manifest.nix
@@ -1,7 +1,7 @@
 {
   # General callPackage-supplied arguments
-  autoAddOpenGLRunpathHook,
-  autoAddCudaCompatRunpathHook,
+  autoAddDriverRunpath,
+  autoAddCudaCompatRunpath,
   autoPatchelfHook,
   backendStdenv,
   fetchurl,
@@ -193,16 +193,16 @@ backendStdenv.mkDerivation (
       # in typically /lib/opengl-driver by adding that
       # directory to the rpath of all ELF binaries.
       # Check e.g. with `patchelf --print-rpath path/to/my/binary
-      autoAddOpenGLRunpathHook
+      autoAddDriverRunpath
       markForCudatoolkitRootHook
     ]
-    # autoAddCudaCompatRunpathHook depends on cuda_compat and would cause
+    # autoAddCudaCompatRunpath depends on cuda_compat and would cause
     # infinite recursion if applied to `cuda_compat` itself (beside the fact
     # that it doesn't make sense in the first place)
     ++ lib.optionals (pname != "cuda_compat" && flags.isJetsonBuild) [
-      # autoAddCudaCompatRunpathHook must appear AFTER autoAddOpenGLRunpathHook.
+      # autoAddCudaCompatRunpath must appear AFTER autoAddDriverRunpath.
       # See its documentation in ./setup-hooks/extension.nix.
-      autoAddCudaCompatRunpathHook
+      autoAddCudaCompatRunpath
     ];
 
     buildInputs =
diff --git a/nixpkgs/pkgs/development/cuda-modules/nccl/default.nix b/nixpkgs/pkgs/development/cuda-modules/nccl/default.nix
index 25296c21365d..b8bdc69bba4f 100644
--- a/nixpkgs/pkgs/development/cuda-modules/nccl/default.nix
+++ b/nixpkgs/pkgs/development/cuda-modules/nccl/default.nix
@@ -12,7 +12,7 @@
 }:
 let
   inherit (cudaPackages)
-    autoAddOpenGLRunpathHook
+    autoAddDriverRunpath
     backendStdenv
     cuda_cccl
     cuda_cudart
@@ -44,7 +44,7 @@ backendStdenv.mkDerivation (
     nativeBuildInputs =
       [
         which
-        autoAddOpenGLRunpathHook
+        autoAddDriverRunpath
         python3
       ]
       ++ lib.optionals (lib.versionOlder cudaVersion "11.4") [cudatoolkit]
diff --git a/nixpkgs/pkgs/development/cuda-modules/saxpy/default.nix b/nixpkgs/pkgs/development/cuda-modules/saxpy/default.nix
index 68c60e2d8446..bc299dea006f 100644
--- a/nixpkgs/pkgs/development/cuda-modules/saxpy/default.nix
+++ b/nixpkgs/pkgs/development/cuda-modules/saxpy/default.nix
@@ -5,7 +5,7 @@
 }:
 let
   inherit (cudaPackages)
-    autoAddOpenGLRunpathHook
+    autoAddDriverRunpath
     backendStdenv
     cuda_cccl
     cuda_cudart
@@ -29,7 +29,7 @@ backendStdenv.mkDerivation {
   nativeBuildInputs =
     [
       cmake
-      autoAddOpenGLRunpathHook
+      autoAddDriverRunpath
     ]
     ++ lib.optionals (lib.versionOlder cudaVersion "11.4") [cudatoolkit]
     ++ lib.optionals (lib.versionAtLeast cudaVersion "11.4") [cuda_nvcc];
diff --git a/nixpkgs/pkgs/development/cuda-modules/setup-hooks/auto-add-cuda-compat-runpath.sh b/nixpkgs/pkgs/development/cuda-modules/setup-hooks/auto-add-cuda-compat-runpath.sh
index ae25cebaca6f..fc41024f1551 100644
--- a/nixpkgs/pkgs/development/cuda-modules/setup-hooks/auto-add-cuda-compat-runpath.sh
+++ b/nixpkgs/pkgs/development/cuda-modules/setup-hooks/auto-add-cuda-compat-runpath.sh
@@ -3,25 +3,25 @@
 # coming from the cuda_compat package by adding it to the RUNPATH.
 echo "Sourcing auto-add-cuda-compat-runpath-hook"
 
-elfHasDynamicSection() {
-    patchelf --print-rpath "$1" >& /dev/null
-}
+addCudaCompatRunpath() {
+  local libPath
+  local origRpath
+
+  if [[ $# -eq 0 ]]; then
+    echo "addCudaCompatRunpath: no library path provided" >&2
+    exit 1
+  elif [[ $# -gt 1 ]]; then
+    echo "addCudaCompatRunpath: too many arguments" >&2
+    exit 1
+  elif [[ "$1" == "" ]]; then
+    echo "addCudaCompatRunpath: empty library path" >&2
+    exit 1
+  else
+    libPath="$1"
+  fi
 
-autoAddCudaCompatRunpathPhase() (
-  local outputPaths
-  mapfile -t outputPaths < <(for o in $(getAllOutputNames); do echo "${!o}"; done)
-  find "${outputPaths[@]}" -type f -print0  | while IFS= read -rd "" f; do
-    if isELF "$f"; then
-      # patchelf returns an error on statically linked ELF files
-      if elfHasDynamicSection "$f" ; then
-        echo "autoAddCudaCompatRunpathHook: patching $f"
-        local origRpath="$(patchelf --print-rpath "$f")"
-        patchelf --set-rpath "@libcudaPath@:$origRpath" "$f"
-      elif (( "${NIX_DEBUG:-0}" >= 1 )) ; then
-        echo "autoAddCudaCompatRunpathHook: skipping a statically-linked ELF file $f"
-      fi
-    fi
-  done
-)
+  origRpath="$(patchelf --print-rpath "$libPath")"
+  patchelf --set-rpath "@libcudaPath@:$origRpath" "$libPath"
+}
 
-postFixupHooks+=(autoAddCudaCompatRunpathPhase)
+postFixupHooks+=("autoFixElfFiles addCudaCompatRunpath")
diff --git a/nixpkgs/pkgs/development/cuda-modules/setup-hooks/auto-add-driver-runpath-hook.sh b/nixpkgs/pkgs/development/cuda-modules/setup-hooks/auto-add-driver-runpath-hook.sh
new file mode 100644
index 000000000000..ecff2a032d64
--- /dev/null
+++ b/nixpkgs/pkgs/development/cuda-modules/setup-hooks/auto-add-driver-runpath-hook.sh
@@ -0,0 +1,8 @@
+# shellcheck shell=bash
+# Run addDriverRunpath on all dynamically linked ELF files
+echo "Sourcing auto-add-driver-runpath-hook"
+
+if [ -z "${dontUseAutoAddDriverRunpath-}" ]; then
+  echo "Using autoAddDriverRunpath"
+  postFixupHooks+=("autoFixElfFiles addDriverRunpath")
+fi
diff --git a/nixpkgs/pkgs/development/cuda-modules/setup-hooks/auto-add-opengl-runpath-hook.sh b/nixpkgs/pkgs/development/cuda-modules/setup-hooks/auto-add-opengl-runpath-hook.sh
deleted file mode 100644
index a6eeef7c7699..000000000000
--- a/nixpkgs/pkgs/development/cuda-modules/setup-hooks/auto-add-opengl-runpath-hook.sh
+++ /dev/null
@@ -1,28 +0,0 @@
-# shellcheck shell=bash
-# Run addOpenGLRunpath on all dynamically linked, ELF files
-echo "Sourcing auto-add-opengl-runpath-hook"
-
-elfHasDynamicSection() {
-    patchelf --print-rpath "$1" >& /dev/null
-}
-
-autoAddOpenGLRunpathPhase() (
-  local outputPaths
-  mapfile -t outputPaths < <(for o in $(getAllOutputNames); do echo "${!o}"; done)
-  find "${outputPaths[@]}" -type f -print0  | while IFS= read -rd "" f; do
-    if isELF "$f"; then
-      # patchelf returns an error on statically linked ELF files
-      if elfHasDynamicSection "$f" ; then
-        echo "autoAddOpenGLRunpathHook: patching $f"
-        addOpenGLRunpath "$f"
-      elif (( "${NIX_DEBUG:-0}" >= 1 )) ; then
-        echo "autoAddOpenGLRunpathHook: skipping a statically-linked ELF file $f"
-      fi
-    fi
-  done
-)
-
-if [ -z "${dontUseAutoAddOpenGLRunpath-}" ]; then
-  echo "Using autoAddOpenGLRunpathPhase"
-  postFixupHooks+=(autoAddOpenGLRunpathPhase)
-fi
diff --git a/nixpkgs/pkgs/development/cuda-modules/setup-hooks/auto-fix-elf-files.sh b/nixpkgs/pkgs/development/cuda-modules/setup-hooks/auto-fix-elf-files.sh
new file mode 100644
index 000000000000..1d57dfb17a66
--- /dev/null
+++ b/nixpkgs/pkgs/development/cuda-modules/setup-hooks/auto-fix-elf-files.sh
@@ -0,0 +1,64 @@
+# shellcheck shell=bash
+# List all dynamically linked ELF files in the outputs and apply a generic fix
+# action provided as a parameter (currently used to add the CUDA or the
+# cuda_compat driver to the runpath of binaries)
+echo "Sourcing cuda/fix-elf-files.sh"
+
+# Returns the exit code of patchelf --print-rpath.
+# A return code of 0 (success) means the ELF file has a dynamic section, while
+# a non-zero return code means the ELF file is statically linked (or is not an
+# ELF file).
+elfHasDynamicSection() {
+  local libPath
+
+  if [[ $# -eq 0 ]]; then
+    echo "elfHasDynamicSection: no library path provided" >&2
+    exit 1
+  elif [[ $# -gt 1 ]]; then
+    echo "elfHasDynamicSection: too many arguments" >&2
+    exit 1
+  elif [[ "$1" == "" ]]; then
+    echo "elfHasDynamicSection: empty library path" >&2
+    exit 1
+  else
+    libPath="$1"
+    shift 1
+  fi
+
+  patchelf --print-rpath "$libPath" >& /dev/null
+  return $?
+}
+
+# Run a fix action on all dynamically linked ELF files in the outputs.
+autoFixElfFiles() {
+  local fixAction
+  local outputPaths
+
+  if [[ $# -eq 0 ]]; then
+    echo "autoFixElfFiles: no fix action provided" >&2
+    exit 1
+  elif [[ $# -gt 1 ]]; then
+    echo "autoFixElfFiles: too many arguments" >&2
+    exit 1
+  elif [[ "$1" == "" ]]; then
+    echo "autoFixElfFiles: empty fix action" >&2
+    exit 1
+  else
+    fixAction="$1"
+  fi
+
+  mapfile -t outputPaths < <(for o in $(getAllOutputNames); do echo "${!o}"; done)
+
+  find "${outputPaths[@]}" -type f -print0  | while IFS= read -rd "" f; do
+    if ! isELF "$f"; then
+      continue
+    elif elfHasDynamicSection "$f"; then
+      # patchelf returns an error on statically linked ELF files, and in
+      # practice fixing actions all involve patchelf
+      echo "autoFixElfFiles: using $fixAction to fix $f" >&2
+      $fixAction "$f"
+    elif (( "${NIX_DEBUG:-0}" >= 1 )); then
+      echo "autoFixElfFiles: skipping a statically-linked ELF file $f"
+    fi
+  done
+}
diff --git a/nixpkgs/pkgs/development/cuda-modules/setup-hooks/extension.nix b/nixpkgs/pkgs/development/cuda-modules/setup-hooks/extension.nix
index 9e352bd5b3af..ece70da52b02 100644
--- a/nixpkgs/pkgs/development/cuda-modules/setup-hooks/extension.nix
+++ b/nixpkgs/pkgs/development/cuda-modules/setup-hooks/extension.nix
@@ -1,4 +1,19 @@
 final: _: {
+  # Helper hook used in both autoAddCudaCompatRunpath and
+  # autoAddDriverRunpath that applies a generic patching action to all elf
+  # files with a dynamic linking section.
+  autoFixElfFiles =
+    final.callPackage
+      (
+        {makeSetupHook}:
+         makeSetupHook
+          {
+            name = "auto-fix-elf-files";
+          }
+          ./auto-fix-elf-files.sh
+      )
+      {};
+
   # Internal hook, used by cudatoolkit and cuda redist packages
   # to accommodate automatic CUDAToolkit_ROOT construction
   markForCudatoolkitRootHook =
@@ -32,31 +47,36 @@ final: _: {
       {}
     );
 
-  autoAddOpenGLRunpathHook =
+  autoAddDriverRunpath =
     final.callPackage
       (
-        {addOpenGLRunpath, makeSetupHook}:
+        {addDriverRunpath, autoFixElfFiles, makeSetupHook}:
         makeSetupHook
           {
             name = "auto-add-opengl-runpath-hook";
-            propagatedBuildInputs = [addOpenGLRunpath];
+            propagatedBuildInputs = [addDriverRunpath autoFixElfFiles];
           }
-          ./auto-add-opengl-runpath-hook.sh
+          ./auto-add-driver-runpath-hook.sh
       )
       {};
 
-  # autoAddCudaCompatRunpathHook hook must be added AFTER `setupCudaHook`. Both
+  # Deprecated: an alias kept for compatibility. Consider removing after 24.11
+  autoAddOpenGLRunpathHook = final.autoAddDriverRunpath;
+
+  # autoAddCudaCompatRunpath hook must be added AFTER `setupCudaHook`. Both
   # hooks prepend a path with `libcuda.so` to the `DT_RUNPATH` section of
   # patched elf files, but `cuda_compat` path must take precedence (otherwise,
   # it doesn't have any effect) and thus appear first. Meaning this hook must be
   # executed last.
-  autoAddCudaCompatRunpathHook =
+  autoAddCudaCompatRunpath =
     final.callPackage
       (
-        {makeSetupHook, cuda_compat ? null }:
+        {makeSetupHook, autoFixElfFiles, cuda_compat ? null }:
         makeSetupHook
           {
             name = "auto-add-cuda-compat-runpath-hook";
+            propagatedBuildInputs = [autoFixElfFiles];
+
             substitutions = {
               # Hotfix Ofborg evaluation
               libcudaPath = if final.flags.isJetsonBuild then "${cuda_compat}/compat" else null;