Running a Rust application that needs EGL with shell.nix

Hi, I am trying to run smallvil with on a X11 session by using a shell.nix looking like this:

{pkgs ? import <nixpkgs> {} }:
  pkgs.mkShell {
    nativeBuildInputs = with pkgs; [
      pkg-config
    ];
    buildInputs = with pkgs; [
      wayland
      libxkbcommon
      xorg.libX11
      xorg.libXcursor
      xorg.libXrandr
      xorg.libXi
      libGL
    ];
}

But the program is unable to find the EGL library:

2023-09-20T14:39:42.162488Z  INFO input_seat{name="winit"}:add_keyboard{xkb_config=XkbConfig { rules: "", model: "", layout: "", variant: "", options: None } repeat_delay=200 repeat_rate=25}:input_keyboard: smithay::input::keyboard: Initializing a xkbcommon handler with keymap query
2023-09-20T14:39:42.165233Z  INFO input_seat{name="winit"}:add_keyboard{xkb_config=XkbConfig { rules: "", model: "", layout: "", variant: "", options: None } repeat_delay=200 repeat_rate=25}:input_keyboard: smithay::input::keyboard: Loaded Keymap name="English (US)"
2023-09-20T14:39:42.166026Z  INFO smithay::wayland::socket: Created new socket name=Some("wayland-1")
2023-09-20T14:39:42.166150Z  INFO backend_winit: smithay::backend::winit: Initializing a winit backend
2023-09-20T14:39:42.171831Z  INFO backend_winit: winit::platform_impl::platform::x11::window: Guessed window scale factor: 1.25    
thread 'main' panicked at 'Failed to load LibEGL: DlOpen { desc: "libEGL.so.1: cannot open shared object file: No such file or directory" }', src/backend/egl/ffi.rs:148:78
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

Is there a solution to this, without packaging the application in nix itself.

You probably want libglvnd, and you likely want it in the LD_LIBRARY_PATH seeing how your app uses dlopen

Thanks alot this works! I tried setting LD_LIBRARY_PATH with libGL before, but libGL doesn’t seem to actually contain the so, so libglvnd + LD_LIBRARY_PATH did it!

1 Like

Can you be more explicit? Are you setting it in the shell.nix or imperatively after you start the shell? Curious, I’ve bumped into this and so far keep resorting to hacking the build into my nixpkgs, which isn’t very sustainable or fun.

My working shell.nix now looks like this:

{pkgs ? import <nixpkgs> {} }:
  pkgs.mkShell {
    nativeBuildInputs = with pkgs; [
      pkg-config
    ];
    buildInputs = with pkgs; [
      wayland
      libxkbcommon
      xorg.libX11
      xorg.libXcursor
      xorg.libXrandr
      xorg.libXi
      libglvnd
    ];

    LD_LIBRARY_PATH="${pkgs.libglvnd}/lib";
}
2 Likes