How to package a binary that loads a `.so` file at runtime?

Hi there,

I’m trying to package RustDesk. I failed building it from source because it needs vcpkg and I was unable to build it :frowning_face:

So I decided to try to package the pre-built binary first and maybe come back later and compile it when I know more about Nix.

I managed to unpack the .deb file and also added all dependencies so that autoPatchElfHook can do it’s magic. But when I try to run it, I get a runtime panic:

thread 'main' panicked at 'error: '' was not found neither in PATH nor near the current executable.
  Please verify that Sciter SDK is installed and its binaries (from bin.lnx) are available in PATH.', libs/rust-sciter/src/
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Aborted (core dumped)

The .deb contains a file usr/lib/rustdesk/ which, as far as I can tell, should be loaded at runtime.

I tried adding it using patchelf in the postFixup script but without luck (I tried both lines separately and together):

patchelf --add-needed $out/lib/rustdesk/ $out/bin/rustdesk
patchelf --set-soname $out/lib/rustdesk/ $out/bin/rustdesk

Does anyone know how to fix this?

Current state of the default.nix (at the time of writing this):

Have you tried this tutorial? Packaging/Binaries - NixOS Wiki

That one is pretty much all I have needed so far, but when that’s not enough, you can pull the buildFHSUserEnv trick as well