Then home-manager generates an ~/.xsession file. But to actually use this from gdm, which I’m using, I need a custom session file for that as well, don’t I? I tried stitching one together using xserver.windowManager.session = [ ... ] (in /etc/nixos/configuration.nix, mind you) but that isn’t recognized by gdm, apparently.
What’s the most “idiomatic” way to connect home-manager and NixOS with a custom X session, then?
Did you make any progress with this? I think I have the same or a related problem, but it seems to bite only in very specific circumstances (which makes me suspect a bug).
I have two machines, both running nixos. In one, I am using home-manager to run xmonad on login. On the other, I am using home-manager to run kodi.
On the kodi machine, I have a config very similar to yours above. The xsession file is generated in the users home directory, and it looks fine. It works correctly if I use lightdm, but the xsession is ignored and I get logged in to Gnome if I use gdm. (This is only a partial fix for me - I need gdm, as lightdm is missing a bunch of features I make use of.)
On the xmonad machine, everything works as expected - I get xmonad regardless of whether I use gdm or lightdm. The config here is a little different, in that I don’t set xsession.windowManager.command directly - it’s set for me automatically by setting xsession.windowManager.xmonad.enable = true;, but I’m not sure if that is significant.
The other major difference between the two setups is that the kodi machine calls home-manager as a module from configuration.nix, whereas on the xmonad machine home-manager is being managed by the user in their home directory. Again, unsure if that’s significant. There are a bunch of other small differences but nothing that strikes me as an obvious cause for this behaviour - seems weird that gdm works as expected in one place, but not the other.
Lot of probably irrelevant information there! Adding it on the off chance that something useful comes from us comparing notes.
To more directly answer one of your questions, I don’t think this is the case. Looking at the source, it appears that the intended behaviour is that an xsession file should override choice of xsession made by the display manager.