Minecraft development environment (both Fabric/Forge) unable to find libraries at runtime

I am currently trying to get development environment working for developing Minecraft mods.
Previously, it worked “out of the box” except for broken audio (Java failed to find OpenAL library), but now it’s broken completely as Java fails to find GLFW library (I described the issue here because I thought it was connected to other issues I got recently).
I managed to work around this by setting LD_LIBRARY_PATH as described in linked topic, but it’s in no way a proper solution, so what would be a better one?
(UPD: I made it work by making an empty directory with single flake.nix that specifices LD_LIBRARY_PATH like this then just using nix develop path/to/directory but I’m still not sure if this is a proper way. It seems weird to make folders for each situation like this, and I don’t wanna add flake.nix to my projects yet as it would mean duplicating my project files to the nix store)

To anyone who wants to replicate this, you can grab mod template here with default settings, then just run ./gradlew runClient to start Minecraft with empty template mod. It should fail with the error GLFW error 65542: GLX: Failed to load GLX.

I think that’s the solution if you want to not litter your system with dev libraries. Or rather, you should be adding a dev shell to each project - this is how NixOS is intended to be used, dev libraries are never installed by default. If they were, you could easily have spurious dependencies in projects you develop that you’re not aware of.

In fact, buildInputs and packages are aliases, and by default adding dev libraries to packages should make them available for linking (I forget if this involves LD_LIBRARY_PATH, but I believe it does), so you could probably write a better shell that doesn’t break with certain edge cases.

Other solutions include nix-ld, and you can play with extraOutputsToInstall, but I’m not certain that’s enough.

Use the traditional shell.nix with nix-shell then, it includes no evaluation caching or anything.

Cool that you’ve figured this out though, I’ve considered doing some minecraft modding to get some practical experience with kotlin/gradle, this will definitely help!

shell.nix does the trick! Though I didn’t want to use it at first, since I’m on flake-enabled system I don’t have the channels set and I have to supply nixpkgs via nix-shell -I nixpkgs=...
Also just found a similar issue, I also tried to have flake.nix in the root of my projects directory but it also had bunch of build artifacts: flakes: avoid copying local flake to the store when `self` arg is omitted · Issue #5551 · NixOS/nix · GitHub, linking it here just in case someone finds this topic useful.

You can permanently set the nix path to link to your flake inputs: Do flakes also set the system channel? - #16 by peterhoeg