raylib-rs icon indicating copy to clipboard operation
raylib-rs copied to clipboard

GLX Error on NixOS

Open hanzy1110 opened this issue 1 year ago • 1 comments

Maybe a config error but couldn't find anything related I'm trying to build raylib-rs on my laptop running Wayland on NixOS. The program builds normally but when I try to run the executable I get the following error:

WARNING: GLFW: Error: 65542 Description: GLX: Failed to load GLX
WARNING: GLFW: Failed to initialize Window
thread 'main' panicked at /home/bm69/.cargo/registry/src/index.crates.io-6f17d22bba15001f/raylib-3.7.0/src/core/mod.rs:208:13:
Attempting to create window failed!
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

Note that the "wayland" feature is no longer recognized so the readme is outdated as of version 3.7. Here are the packages I'm installing in my flake.nix file:

    devShells = forEachSupportedSystem ({pkgs}: {
      default = pkgs.mkShell {
        packages = with pkgs; [
          rustToolchain
          openssl
          pkg-config
          cargo-deny
          cargo-edit
          cargo-watch
          rust-analyzer
          cmake
          gnumake
          pkg-config
          libGL
          xorg.libX11
          xorg.libX11.dev
          xorg.libXft
          xorg.libXrandr
          xorg.libXinerama
          xorg.libXcursor
          xorg.libXi
          libatomic_ops
          mesa
          alsa-lib
          glibc
          # [Wayland]
          wayland
          wayland-protocols
          libxkbcommon
          glfw-wayland
        ];
      };
    });

Some of the glfw packages listed on the readme weren't availble on nixpkgs. Any help is appreciated

hanzy1110 avatar May 09 '24 15:05 hanzy1110

For anyone searching the depths of the internet with this issue here's my nix-shell file that ended up working:

let
  nixpkgs = fetchTarball "https://github.com/NixOS/nixpkgs/tarball/nixos-24.11";
  pkgs = import nixpkgs { config = {}; overlays = []; };
in

pkgs.mkShell {
  stdenv = pkgs.clangStdenv;
  packages = with pkgs; [
    rustup
    glfw
    cmake
    clang
    wayland
  ];
  nativeBuildInputs = [
    pkgs.libGL

    # Web support (uncomment to enable)
    # pkgs.emscripten
  ];

  LD_LIBRARY_PATH = with pkgs; lib.makeLibraryPath [
    libGL
    xorg.libXrandr
    xorg.libXinerama
    xorg.libXcursor
    xorg.libXi
  ];
  LIBCLANG_PATH = "${pkgs.libclang.lib}/lib";
}

There's probably things not optimal about this, but it works (I haven't looked into audio yet I'll admit). Here's a helpful reference that was the final piece of the puzzle for me: https://discourse.nixos.org/t/problems-building-raylib-rs/45142

Also don't forget to add the "wayland" feature to your cargo.toml for raylib!

JamesKEbert avatar Feb 06 '25 22:02 JamesKEbert