nix: Fix screen-casting when building Zed with nix (#52690)

Jakub Konka created

Release Notes:

- Fixed screen-casting when building Zed with Nix.

Change summary

nix/build.nix                     | 8 ++++----
nix/livekit-libwebrtc/package.nix | 9 +++++++++
2 files changed, 13 insertions(+), 4 deletions(-)

Detailed changes

nix/build.nix 🔗

@@ -77,6 +77,7 @@ let
     builtins.elem firstComp topLevelIncludes;
 
   craneLib = crane.overrideToolchain rustToolchain;
+  gpu-lib = if withGLES then libglvnd else vulkan-loader;
   commonArgs =
     let
       zedCargoLock = builtins.fromTOML (builtins.readFile ../crates/zed/Cargo.toml);
@@ -178,8 +179,8 @@ let
         libva
         libxkbcommon
         wayland
+        gpu-lib
         libglvnd
-        vulkan-loader
         xorg.libX11
         xorg.libxcb
         libdrm
@@ -236,8 +237,7 @@ let
         # about them that's special is that they're manually dlopened at runtime
         NIX_LDFLAGS = lib.optionalString stdenv'.hostPlatform.isLinux "-rpath ${
           lib.makeLibraryPath [
-            libglvnd
-            vulkan-loader
+            gpu-lib
             wayland
             libva
           ]
@@ -246,7 +246,7 @@ let
         NIX_OUTPATH_USED_AS_RANDOM_SEED = "norebuilds";
       };
 
-      # prevent nix from removing the "unused" wayland rpaths
+      # prevent nix from removing the "unused" wayland/gpu-lib rpaths
       dontPatchELF = stdenv'.hostPlatform.isLinux;
 
       # TODO: try craneLib.cargoNextest separate output

nix/livekit-libwebrtc/package.nix 🔗

@@ -81,6 +81,15 @@ stdenv.mkDerivation {
   pname = "livekit-libwebrtc";
   version = "137-unstable-2025-11-24";
 
+  # libwebrtc loads libEGL/libGL at runtime via dlopen() in the Wayland
+  # screencast path, so they are not visible as ordinary DT_NEEDED edges.
+  # Keep an explicit rpath so the shared object can resolve them at runtime.
+  NIX_LDFLAGS = lib.optionalString stdenv.hostPlatform.isLinux
+    "-rpath ${lib.makeLibraryPath [ libGL ]}";
+
+  # Prevent fixup from stripping the rpath above as "unused".
+  dontPatchELF = stdenv.hostPlatform.isLinux;
+
   gclientDeps = gclient2nix.importGclientDeps ./sources.json;
   sourceRoot = "src";