Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GLX Error on NixOS #187

Open
hanzy1110 opened this issue May 9, 2024 · 1 comment
Open

GLX Error on NixOS #187

hanzy1110 opened this issue May 9, 2024 · 1 comment

Comments

@hanzy1110
Copy link

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

@JamesKEbert
Copy link

JamesKEbert commented Feb 6, 2025

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants