Any LibGDX project does not work in Nixos

I was trying to use libGDX for one of my projects, but every time that i run the gdx-liftoff-1.13.1.3.jar it gives out this error:

[LWJGL] GLFW_PLATFORM_UNAVAILABLE error
        Description : Failed to detect any supported platform
        Stacktrace  :
                org.lwjgl.glfw.GLFW.glfwInit(GLFW.java:1079)
                com.badlogic.gdx.backends.lwjgl3.Lwjgl3Application.initializeGlfw(Lwjgl3Application.java:89)
                com.badlogic.gdx.backends.lwjgl3.Lwjgl3ApplicationConfiguration.getDisplayMode(Lwjgl3ApplicationConfiguration.java:239)
                gdx.liftoff.Main.main(Main.java:116)
Exception in thread "main" com.badlogic.gdx.utils.GdxRuntimeException: Unable to initialize GLFW
        at com.badlogic.gdx.backends.lwjgl3.Lwjgl3Application.initializeGlfw(Lwjgl3Application.java:90)
        at com.badlogic.gdx.backends.lwjgl3.Lwjgl3ApplicationConfiguration.getDisplayMode(Lwjgl3ApplicationConfiguration.java:239)
        at gdx.liftoff.Main.main(Main.java:116)

i have tried using some other options and none of them worked.

I’ve had good luck with adding -Dorg.lwjgl.glfw.libname=${glfw}/lib/libglfw.so to the Java command line. Have you tried that?

it still does not work. i may need to add a glfw package. i just dont know the name

I don’t know what you mean by ‘add a glfw package’. Can you post the Nix shell file or flake or whatever you’re using to prepare this project?

i did not make a shell or flake yet, for now i am just using this in my configuration.nix:

  programs.nix-ld = {
    enable = true;
    libraries = with pkgs; [
      glibc
      glfw
      glfw2
      glfw3
      zlib
      openssl
      xorg.libXtst
      xorg.libXrender
      xorg.libXrandr
      xorg.libXcursor
      xorg.libXext
      xorg.libX11
      xorg.libXi
      llvm_18
      libffi
      libxml2
      udev
      alsa-lib
      vulkan-loader
      libsForQt5.libopenshot
      libxkbcommon
      wayland
      pkg-config
    ];
  };

(it’s for other stuff too)

Oh, nix-ld setups are too fragile for me to get involved with. Good luck to you.

is there another option?

Yes, build a shell for your project. But a global nix-ld setup like what you have will affect even projects that you build a shell for, which is why I don’t want to get involved—helping people with Nix problems is only fun when I can be confident that I’m testing things in the same environment as they are.

2 Likes

That makes sense. I only use nix-ld because it makes some things run out of the box. The problem is that i have searched for why libGDX does not work and the only thing i found was this, but they don’t give me a shell or flake that i can use.
Since i am not a person who knows a lot about linking i did not understand what they meant.