@@ -961,4 +961,14 @@ self: super: {
961961 sha256 = "0xa5b7i9wx32ji0zzlh1a1pws677iffby3bg39kv3c9srdb4by1g";
962962 })];
963963 });
964+
965+ # GLUT uses `dlopen` to link to freeglut, so we need to set the RUNPATH correctly for
966+ # it to find `libglut.so` from the nix store. We do this by patching GLUT.cabal to pkg-config
967+ # depend on freeglut, which provides GHC to necessary information to generate a correct RPATH.
968+ #
969+ # Note: Simply patching the dynamic library (.so) of the GLUT build will *not* work, since the
970+ # RPATH also needs to be propagated when using static linking. GHC automatically handles this for
971+ # us when we patch the cabal file (Link options will be recored in the ghc package registry).
972+ GLUT = addPkgconfigDepend (appendPatch super.GLUT ./patches/GLUT.patch) pkgs.freeglut;
973+
964974}