OpenGL on NixOS running nvidia optimus

I have a laptop with RTX4080 and an intel integrated “gpu” running NixOS. I have set up nvidia optimus according to the manual. All my vulkan applications run on the discrete GPU as I expect them to, however, all my opengl applications run on the integrated one. I can force an opengl program to run on the discrete gpu by running nvidia-offload glxgears, but I don’t understand what’s supposed to control this decision automatically. As in, what’s the parameter that’s supposed to decide what runs where in the config?

There is no automatic offloading to speak of on Linux. At least on X11. The reason why Vulkan works is because Vulkan supports multiple GPUs natively so DXVK will do the sensible thing and pick the dGPU as will for example DOOM 2016/Eternal. But that only works for Vulkan and OpenGL itself (without extensions and loader magic) has no concept of multiple GPUs.

Then how come the same opengl applications run on the discrete gpu under PopOS? What’s the difference?

PopOS might be doing something funky. It’s possible but nonstandard. And it also might be different wayland. But on NixOS and Arch I haven’t seen such a feature.