From 03e72e46cbbde146046bbc85fca41e90bcebad57 Mon Sep 17 00:00:00 2001 From: Elliot Cameron Date: Thu, 27 Jul 2023 16:57:22 -0400 Subject: [PATCH 1/3] cudaPackages.autoAddOpenGLRunpathHook: fix to skip unsupported/unneed --- .../auto-add-opengl-runpath-hook.sh | 28 +++++++++++++------ 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/pkgs/development/compilers/cudatoolkit/auto-add-opengl-runpath-hook.sh b/pkgs/development/compilers/cudatoolkit/auto-add-opengl-runpath-hook.sh index 0b0da336514a1..395229ca79b70 100644 --- a/pkgs/development/compilers/cudatoolkit/auto-add-opengl-runpath-hook.sh +++ b/pkgs/development/compilers/cudatoolkit/auto-add-opengl-runpath-hook.sh @@ -1,14 +1,24 @@ -# Run autoOpenGLRunpath on all files +# shellcheck shell=bash +# Run addOpenGLRunpath on all dynamically linked, ELF files echo "Sourcing auto-add-opengl-runpath-hook" -autoAddOpenGLRunpathPhase () { - # TODO: support multiple outputs - for file in $(find ${out,lib,bin} -type f); do - addOpenGLRunpath $file - done -} +autoAddOpenGLRunpathPhase() ( + local outputPaths + mapfile -t outputPaths < <(for o in $(getAllOutputNames); do echo "${!o}"; done) + find "${outputPaths[@]}" -type f -executable -print0 | while IFS= read -rd "" f; do + if isELF "$f"; then + # patchelf returns an error on statically linked ELF files + if patchelf --print-interpreter "$f" >/dev/null 2>&1; then + echo "autoAddOpenGLRunpathHook: patching $f" + addOpenGLRunpath "$f" + elif [ -n "${DEBUG-}" ]; then + echo "autoAddOpenGLRunpathHook: skipping ELF file $f" + fi + fi + done +) if [ -z "${dontUseAutoAddOpenGLRunpath-}" ]; then - echo "Using autoAddOpenGLRunpathPhase" - postFixupHooks+=(autoAddOpenGLRunpathPhase) + echo "Using autoAddOpenGLRunpathPhase" + postFixupHooks+=(autoAddOpenGLRunpathPhase) fi From 9a3dcd025ab44b5f230430c30b89606f2da5c8c7 Mon Sep 17 00:00:00 2001 From: Elliot Cameron Date: Thu, 27 Jul 2023 16:58:23 -0400 Subject: [PATCH 2/3] dcgm: switch to fixed autoAddOpenGLRunpathHook --- pkgs/os-specific/linux/dcgm/default.nix | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/pkgs/os-specific/linux/dcgm/default.nix b/pkgs/os-specific/linux/dcgm/default.nix index 36c7e3ca6880b..97d95760e94ae 100644 --- a/pkgs/os-specific/linux/dcgm/default.nix +++ b/pkgs/os-specific/linux/dcgm/default.nix @@ -105,7 +105,11 @@ in gcc11Stdenv.mkDerivation rec { hardeningDisable = [ "all" ]; nativeBuildInputs = [ - addOpenGLRunpath + # autoAddOpenGLRunpathHook does not actually depend on or incur any dependency + # of cudaPackages. It merely adds an impure, non-Nix PATH to the RPATHs of + # executables that need to use cuda at runtime. + cudaPackages_12.autoAddOpenGLRunpathHook + cmake git python3 @@ -124,16 +128,6 @@ in gcc11Stdenv.mkDerivation rec { yaml-cpp ]; - # libcuda.so must be found at runtime because it is supplied by the NVIDIA - # driver. autoAddOpenGLRunpathHook breaks on the statically linked exes. - postFixup = '' - find "$out/bin" "$out/lib" -type f -executable -print0 | while IFS= read -r -d "" f; do - if isELF "$f" && [[ $(patchelf --print-needed "$f" || true) == *libcuda.so* ]]; then - addOpenGLRunpath "$f" - fi - done - ''; - disallowedReferences = lib.concatMap (x: x.pkgSet) cudaPackageSetByVersion; meta = with lib; { From 8b4275f955c7226c278c6501b067d1d236733fa2 Mon Sep 17 00:00:00 2001 From: Elliot Cameron Date: Fri, 4 Aug 2023 20:58:03 -0400 Subject: [PATCH 3/3] dcgm: use strictDeps --- pkgs/os-specific/linux/dcgm/default.nix | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/pkgs/os-specific/linux/dcgm/default.nix b/pkgs/os-specific/linux/dcgm/default.nix index 97d95760e94ae..32842a8eea0ed 100644 --- a/pkgs/os-specific/linux/dcgm/default.nix +++ b/pkgs/os-specific/linux/dcgm/default.nix @@ -104,6 +104,8 @@ in gcc11Stdenv.mkDerivation rec { hardeningDisable = [ "all" ]; + strictDeps = true; + nativeBuildInputs = [ # autoAddOpenGLRunpathHook does not actually depend on or incur any dependency # of cudaPackages. It merely adds an impure, non-Nix PATH to the RPATHs of @@ -113,18 +115,16 @@ in gcc11Stdenv.mkDerivation rec { cmake git python3 + ]; - jsoncpp-static - jsoncpp-static.dev - libevent-nossl-static - libevent-nossl-static.dev + buildInputs = [ plog.dev # header-only tclap_1_4 # header-only - ]; - buildInputs = [ catch2 fmt_9 + jsoncpp-static + libevent-nossl-static yaml-cpp ];