Yeah that looks like it! The only difference is __GLX_VENDOR_LIBRARY_NAME will still use libglvnd and not require recompiling anything. That definitely looks like a better solution.
It definitely depends on what you are using GL for. But, for heavy duty usage, you definitely want a driver that utilizes your GPU. This is going to be different on every computer, so it needs to be provided by the system. Doing one of the above (either __GLX_VENDOR_LIBRARY_NAME or linking to libGLX_mesa) will override that auto detection.
But the experience right now is definitely not great. I think we can improve this by maybe falling back to __GLX_VENDOR_LIBRARY_NAME if no GL is found. In addition we could probably add /usr/lib to the RPATH like was done in https://github.com/NixOS/nixpkgs/pull/60985.