Manually configuring desktop sessions (/usr/share/sessions/)

I am using greetd as my login manager, and I would like to configure different desktop sessions to launch the same compositor (sway), but with different flags/envvars:

  • Session A: Sway with iGPU
  • Session B: Sway with dedicated NVIDIA GPU (--unsupported-gpu flag).

Session files are normally located in /usr/share/sessions or usr/share/wayland-sessions, and in NixOS are properly generated upon enabling the desired desktop environment module.
On any other Linux distro, I’d simply create a file in /usr/share/wayland-sessions/ with something like:

[Desktop Entry]
Name=sway-nvidia
Comment=Launch sway with NVIDIA gpu
Exec=${pkgs.sway}/bin/sway --unsupported-gpu
[...]

I would then have access to the sway-nvidia session in tuigreet.
How can I achieve this on NixOS?

So, I tried adding this to my configuration:

  services.xserver.displayManager.sessionPackages = let
    sway-nvidia = pkgs.writeShellScriptBin "Sway-NVIDIA" ''
      ${pkgs.sway}/bin/sway --unsupported-gpu
    '';
    in
      [
        {
          manage = "window";
          name = "Sway-NVIDIA";
          start = "${sway-nvidia}/bin/sway-nvidia -ls && waitPID=$!";
        }
      ];

  services.greetd = let
    sway-igpu = pkgs.writeShellScriptBin "sway-igpu" ''
      export WLR_DRM_DEVICES=/dev/dri/card1:/dev/dri/card2 && exec ${pkgs.sway}/bin/sway
    '';
  in {
    enable = true;
    settings = {
      default_session = {
        command = "${pkgs.greetd.tuigreet}/bin/tuigreet --time --cmd ${sway-igpu}/bin/sway-igpu";
        user = "sh4k0";
      };
    };
  };

Which partially has the effect I want: I now see 2 session entries in tuigreet. The first one (sway-igpu, default session) works fine, whereas upon launching the the other one (sway-nvidia) I get the following error:

exec: startx: command not found

After some digging, I found this relevant post: Wayland sessions - #4 by zimbatm

The main issue is that the nixos module for the display managers is tied to the xserver, it hasn’t really been designed with wayland in mind. I don’t know all of the details so you would have to dig in there. The nixpkgs sway package has a share/wayland-sessions/sway.desktop, the issue is to patch the GDM3 / SDDM config for it to look in the right place.

Is the above true, and hence I am hopeless in achieving this? :frowning: