How to prevent RPATH being stripped for non-buildInputs

I have a bit of an unusual situation where I have a bridge-type building that accesses dependencies from two conflicting environments. From one environment, it uses CMAKE_PREFIX_PATH and CMake’s normal find_package mechanism, and the other is accessed using pkg-config, so the second set of packages go in the PKG_CONFIG_PATH.

If it’s relevant, there’s more information about this setup here: GitHub - ros2/ros1_bridge: ROS 2 package that provides bidirectional communication between ROS 1 and ROS 2

the issue I’m having is that the packages from the second environment are getting stripped out of the resulting binaries during the fixupPhase, such that ldd result/bin/thing shows not found for many entries. I’ve confirmed that adding one of these packages as a buildInput does cause its linker information to be retained. I tried:

  • naively mutating the value of the buildInput shell variable in a preFixup script
  • adding the extra items to a runtimeDependencies variable in the mkDerivation (based on examining the autopatchelf source)

But neither of these seemed to have any effect on what happened during the fixupPhase. Can anyone shed some light on how to achieve the desired effect here? Thanks!

Ahhh I was so close. Turns out it was just a matter of more closely reading the very file I linked to. The answer is to depend on autoPatchElf as an input, and then call addAutoPatchelfSearchPath at some point with the additional paths, with in the preFixup or before.

There are a handful of examples of this in nixpkgs: Search · addAutoPatchelfSearchPath · GitHub

1 Like

I’m actually un-answering this because although using patchelf does “fix” the problem in terms of achieving the desired end result, it means the binaries end up patched twice. The first patching actually occurs during CMake’s install phase, and can be disabled with -DCMAKE_SKIP_RPATH=ON, though that’s kind of the nuclear option; I wish it was clearer how to tell CMake which paths to strip and not-strip, since it clearly filters through the buildInputs somehow (but the answer appears not to be CMAKE_LIBRARY_PATH since I tried that briefly and a path added to there was still stripped by CMake from the resulting binaries.

Since this issue was just linked to from another thread, and since I pondered on a similar question recently, here’s an sitrep for future readers:

  • CMake strips all Runpaths before installation (unless you specifically modify the install rpath), by design
  • Nixpkgs has hooks to append runpaths from buildInputs based on DT_NEEDED

Both are expected, just have your dependencies in buildInputs