Change:
fi done <del> for i in $(find ${toString cfg.modules} -type d | sort); do if test $(echo $i/*.so* | wc -w) -ne 0; then echo "  ModulePath "$i"" >> $out fi done </del> <ins> ${concatMapStrings (m: '' echo "  ModulePath "${m}/lib/xorg/modules"" >> "$out" '') cfg.modules} </ins> echo '${cfg.filesSection}' >> $out echo 'EndSection' >> $out

Discussion:
It seems that currently xorg will load wrong GLX extension when using with Nvidia Legacy Driver 390. It worked as it should on nixos-unstable as of 18.03.24, however currently it's broken on both 23.11 and unstable. When running a system with nvidia legacy driver 390, xorg needs to load nvidia's in order for nvidia driver to have working OpenGL. This, however, doesn't seem to be the case, as Xorg loads its own glx module: The loaded glx module is provided by xorg, while it should be picked from . After that, NVIDIA driver complains about the wrong glx module: This results in lack of OpenGL acceleration and glxinfo only reports software rasterizer. Inspecting further, I see that in my generated the ModulePath for xorg's own modules take precedence over nvidia: Xorg log also reports ModulePath in this order, with xorg being higher than nvidia: The script that generates "Files" section in appears to sort entries in so their order will vary, depending on their nix store paths (you can see entries are sorted alphabeticially) : Thus, sometimes it will work and sometimes it wont, between nix channel updates when nix store paths may change and nvidia-x11 will have a different store path that will be sorted higher than xorg. Trying to add needed paths manually with lib.mkBefore also has no effect since they will be sorted later anyway. Adding nvidia ModulePath manually via also doesn't work because the script will always put it after the generated paths: And even overriding won't work since config contents are generated independently of ModulePaths and appended by the said script: I did verify it by remounting my nix store as rw and editing the xorg config manually (just to test, this is a throwaway installation): I moved nvidia-x11 ModulePaths higher than xorg ones and after rebooting it worked as it should, glxinfo reported "Nvidia corporation" vendor and correct renderer instead of llvmpipe. Steps to reproduce the behavior: a bare minimum nixos installation Nvidia Legacy 390 drivers as explained in this guide into the system to observe lack of hardware acceleration Xorg loading nvidia's instead of its own one.

The manual on nixos wiki for installing legacy drivers is outdated: it says to specify legacy driver in : However it will have no effect and nvidia driver wont even be installed in this case. it was fixed in documentation in , but nixos wiki remains outdated. Also, I'm not sure if this bug also affects other driver versions, since I only tried Legacy 390. I also posted a thread on nixos forums about this issue before: Not sure who should I ping, since xorg.xorgserver listed as having no maintainers. Add a :+1: [reaction] to [issues you find important]. [reaction]: [issues you find important]:
Updated the wiki.
The code that generates the part of the config was last touched by in , and before that 15 years ago. That PR improved reproducibility by sorting the directories within a store path, but also reduced reproducibility by sorting the store paths themselves, making the order dependent on their hashes. It should be easy enough to keep the intended order of specified (note that drivers come before ) while listing the contents of each module reproducibly; I'll open a PR shortly. Another option would be to merge all the into a single with ; this would fix this specific issue since the nvidia packages have a than , but I don't know about other drivers.