Skip to content

Record your screen, ship a demo. Free and open-source, GPU-accelerated, no watermarks, no subscriptions. Windows, macOS, Linux. Actively maintained.

fix(nix): let the renamed ffmpeg copies resolve only against each other

EtienneLescot66e06faa933c
diff --git a/nix/compositor-view.nix b/nix/compositor-view.nix
index 13b759784..6a71a2bfa 100644
--- a/nix/compositor-view.nix
+++ b/nix/compositor-view.nix
@@ -186,6 +186,23 @@ rustPlatform.buildRustPackage {
# defines osff_-prefixed symbols, so they have to sit beside it and be found
# from there rather than through any system path.
cp "$NIX_BUILD_TOP"/ffmpeg-renamed/lib/*.so.* "$out/lib/"
+
+ # Each copy still carries the RUNPATH it inherited from the original ffmpeg
+ # output, which is where the UN-renamed libraries live -- so libavcodec's own
+ # osff_swr_init would resolve against a libswresample that defines swr_init.
+ # It only works today because all five happen to be direct DT_NEEDED of the
+ # addon, so $ORIGIN is searched first; the day --as-needed drops one the
+ # loader falls through to the store copy and dlopen fails on an undefined
+ # osff_ symbol. Put $ORIGIN in front so the renamed set can only resolve
+ # against itself, and keep what was there for their non-ffmpeg deps (zlib,
+ # openh264) -- the same reason the addon below gets --add-rpath rather than a
+ # replacement.
+ for so in "$out"/lib/*.so.*; do
+ chmod u+w "$so"
+ prev=$(patchelf --print-rpath "$so")
+ patchelf --set-rpath '$ORIGIN'"''${prev:+:$prev}" "$so"
+ done
+
chmod u+w "$out/lib/compositor_view.node"
# --add-rpath, not --set-rpath: the latter replaces what nixpkgs' ld-wrapper