NixOS / nixpkgs

Nix Packages collection & NixOS
MIT License
17.6k stars 13.76k forks source link

Decoupling desktopManagers/displayManagers from xorg #102542

Open mkg20001 opened 3 years ago

mkg20001 commented 3 years ago

Currently desktopManagers and displayManagers are part of the serivces.xserver namespace.

This is problematic as there are greeters such as slimd and greetd that support wayland and can run independently of X11.

The same is true for some desktopManagers such as gnome

A solution must be found that allows the user to choose the display server (wayland, xorg) and have the displayManager/desktopManager use it

I propose:

kira-bruneau commented 3 years ago

I definitely think it's a good idea to rename services.xserver.displayManager & services.xserver.desktopManager, but I don't think we should introduce services.displayServer.

Mutter, KWin, Sway, Weston, etc... all implement the Wayland protocol in the same way that X11 implements the X protocol. There's no Wayland display server that's separate from the window manager like there's X11 for the X protocol.

We might also want to rename services.xserver.windowManager, but I can't find a single window manager under that set that supports Wayland. Sway is configured under programs.sway, while Mutter & KWin are packaged together with Gnome & Plasma.

kira-bruneau commented 3 years ago

I think we also need to create a common session wrapper for all display managers and then specialize Wayland & X session wrappers on top of it.

Currently, if you use SDDM + Sway, there's no session wrapper setup for Wayland, so /etc/profile doesn't get sourced before running sway and graphical-session.target doesn't start (which causes any service that depends on it to fail to start, eg. redshift).

We could also use a Wayland session wrapper to import WAYLAND_DISPLAY into systemd user services like we import DISPLAY in the xsession wrapper, which would be a more general fix than https://github.com/NixOS/nixpkgs/pull/122605/files#diff-7487308814d795880e5a469294284c9bc0c2d41c901546601645a00e94236904R124-R128. @primeos.

kira-bruneau commented 3 years ago

I also found a related issue: #53394.

primeos commented 3 years ago

I guess the renaming might be a bit difficult as Wayland compositors are different from X11 WMs/DEs. services.displayManagers (or services.loginManagers) sounds like a good idea as those can use and support X11, Wayland, or both (and there are even ones for virtual consoles). Not sure about the rest. Maybe there should be a services.wayland.$compositor (but that wouldn't work for big DEs like Gnome and KDE that support both X11 and Wayland sessions)?

We might also want to rename services.xserver.windowManager, but I can't find a single window manager under that set that supports Wayland.

Yeah, that shouldn't be necessary as WMs are X11 specific (though I guess there could be a Wayland compositor/library that supports implementing WMs).

I think we also need to create a common session wrapper for all display managers and then specialize Wayland & X session wrappers on top of it.

Yes, that would be great. See #109546.

kira-bruneau commented 3 years ago

services.displayManagers (or services.loginManagers) sounds like a good idea as those can use and support X11, Wayland, or both (and there are even ones for virtual consoles).

Oh, I like services.loginManager. It's much clearer and less tied to X.

Not sure about the rest. Maybe there should be a services.wayland.$compositor (but that wouldn't work for big DEs like Gnome and KDE that support both X11 and Wayland sessions)?

I think for those we should just use services.windowManager, and possibly keep services.xserver.windowManager for X11 specific window managers. I suppose we can also use services.wayland.$compositor for Wayland specific window managers, but any Wayland compositor is also a window manager and could fit in services.windowManager.

stale[bot] commented 2 years ago

I marked this as stale due to inactivity. → More info

SuperSamus commented 2 years ago

This issue is starting to get more and more important. https://www.phoronix.com/scan.php?page=news_item&px=GNOME-Mutter-Prep-X11-Free

SuperSandro2000 commented 1 month ago

We now have https://github.com/NixOS/nixpkgs/blob/master/nixos/modules/services/misc/graphical-desktop.nix and some desktop/session/graphical/etc manager need to properly opt into that but the overarching issue here should be solved.

RuRo commented 1 month ago

@SuperSandro2000 it's not immediately clear to me, how does the linked code solve the stated problem. It looks like a simple refactoring of some xserver-specific code. I don't see any mentions of wayland in that file. Is there any documentation for this?

For example, the original issue describes adding a new displayServer namespace, that would hypothetically provide a unified way to switch between X11 and Wayland for desktop/displayManagers that support both. Something along the lines of

# plasma6 and sddm support both X11 and Wayland
services.desktopManager.plasma6.enable = true;
services.displayManager.sddm.enable = true;

# Choose one
services.displayServer.xserver.enable = true;
# services.displayServer.wayland.enable = true;

I don't think that something like this is currently possible. Instead, you have to do something like this

services.desktopManager.plasma6.enable = true;
services.displayManager.sddm.enable = true;

# The following configuration is different for different desktop/displayManagers.

## Xserver
services.displayManager.defaultSession = "plasmax11";
services.displayManager.sddm.wayland.enable = false;

## Wayland
services.displayManager.defaultSession = "plasma";
services.displayManager.sddm.wayland.enable = true;
SuperSandro2000 commented 1 month ago

moving services.xserver.displayManagers and services.xserver.desktopManagers into services.displayManagers and services.desktopManagers

That should be done for anything that supports wayland like it was already done for sddm and plasma 6.

adding assertions to both displayManagers and desktopManagers that check if a supported displayServer is enabled

No. This cannot be done for Wayland and for xserver the modules should already enable it, requiring you to use lib.mkForce to turn it off and if we are at that point, we don't need to stop people because they hopefully know what they are doing.

adding the services.displayServer namespace which would include xorg and wayland

We already have that in https://github.com/NixOS/nixpkgs/blob/1eba13418b8434cc037707b1a62d9dbfe6caefa4/nixos/modules/services/misc/graphical-desktop.nix#L12 . The condition is based on the assumption that every user has xserver on or is using the systemd displayManager unit. If there rises the need for another condition we can probably turn that into a proper option.

so that services.displayServer.wayland.enable = true; would enable all required services that need to be enabled in order to make Wayland work for example

Lets take Plasma 6 as an example which uses kwin as the x11 window manager and wayland compositor. It is for wayland and x11 installed. It is also used as the wayland compositor for sddm to reduce incompatibilities by using weston if sddm is using wayland. And it has an optional security wrapper.

The 2nd and 3rd points are not required but should probably be on by default and they reduce closure size or are basically free.

So for Plasma 6 that option would be either very empty and basically not worth it to do.

What would be a better use case? I can't think of one.


It looks like a simple refactoring of some xserver-specific code.

The code wasn't xserver specific, hence it never really belonged into xserver. Those are generic bits that are also required for wayland things, basically anything that is a graphical desktop.

Is there any documentation for this?

There is as much documentation as there was before. Basically the module is a collection of random bits any desktop wants to enable all the time no matter if it is xorg, wayland, full fledged like gnome or plasma or bare bones like sway.

For example, the original issue describes adding a new displayServer namespace, that would hypothetically provide a unified way to switch between X11 and Wayland for desktop/displayManagers that support both. Something along the lines of

Most desktops have one recommended way to run and you should not really run the other. Gnome and Plasma 6 should be run with Wayland. Plasma 5 should be run with Xorg. i3 is xorg and sway is wayland. There is not really a demand to super duper abstract this and it would make things probably only more complicated as they are already.

Choose one services.displayServer.xserver.enable = true; services.displayServer.wayland.enable = true;

As one of the plasma maintainers, we only want people to choose wayland for 6 and xorg for 5.

Plasma 5's wayland support is incomplete and a bit buggy and upstream didn't recommend it and for Plasma 6 wayland is recommended way while you can switch back to xorg, we don't want to invest much of our limited time into that.

services.displayManager.defaultSession

Plasma 6 has a reasonable default for this https://github.com/NixOS/nixpkgs/blob/745bed037145214b3c1612fabbbe26a3758f1fcb/nixos/modules/services/desktop-managers/plasma6.nix#L250 and you are not forced to change this option, you can also change it with every login or let SDDM remember your last choice.

services.displayManager.sddm.wayland.enable

That is just about what SDDM itself uses and totally independent of what the actual desktop is using. Plasma 6 tells SDDM to use kwin for the compositor if sddm.wayland.enable is true. At some point we are probably going to switch that over.

RuRo commented 1 month ago

we only want people to choose wayland for 6 and xorg for 5

Afaik, Plasma 6 and Gnome both officially support running under X11 and Wayland. I remember it being a widely advertised feature that "X11 support is not going away" in both DEs. If running these DEs under X11 is an officially supported usage (even if it isn't the default), then it should be properly supported in the NixOS module system (imho).


Okay, so I am going to reveal my complete and utter lack of knowledge, but I feel that we need to take a look at some concrete examples of jank that is present in by the current system.

Here are a few examples:

1) If you only set

    services.displayManager.sddm.enable = true;
without any other options, you will get an error that `SDDM requires either services.xserver.enable or services.displayManager.sddm.wayland.enable to be true`.

In terms of UX, why is `xserver.enable` a global option, but `wayland.enable` is configured inside SDDM? And if the answer is "because wayland isn't a compositor", please explain why this doesn't apply to `services.displayManager.sddm.wayland`? Why is this an SDDM-specific option?

2) To enable X11 for Plasma 6 you need to set

    services.displayManager.defaultSession = "plasmax11";
but for Gnome its apparently done with
```nix
services.displayManager.gdm.wayland = false;
```

Why is the default gnome session configured inside GDM? What if I'm using SDDM with Gnome? SDDM will default to the Wayland version of Gnome even if `sddm.wayland.enable = false` and `xserver.enable = true`. What if I am using Plasma with GDM? (∀X ∈ displayManagers ∀Y ∈ desktopManagers "What if I am using X with Y?")

The list of possible session names that you can use as the `defaultSession` isn't very discoverable. How are you supposed to know to use the string `"plasmax11"` from reading the option docs, without reading the NixOS Wiki or the nixpkgs sources?

3) I am assuming that the fact that displayManager.gdm and desktopManager.gnome are located inside xserver and require setting xserver.enable = true despite using wayland by default is because they "need to properly opt into that" as you said, but this is quite jank nonetheless.

The current situation just doesn't feel all that elegant from the user's perspective. As a user, I don't want to learn/understand how to manually configure X11/Wayland support.

In my opinion, when it comes to graphical DEs, there are essentially three choices that the user has to make:

1) Which kind of graphical server do I want to use? (X11 or Wayland (or none/headless)) 2) Which display manager do I want to use? (SDDM or GDM or ...) 3) Which desktop manager do I want to use? (Plasma or Gnome or ...)

If steps 1 and/or 2 are skipped, it is okay to automatically enable the default/recommended value for the chosen DE (in the most common case where only a single DE was enabled). If incompatible options are chosen, an error should be reported (with the possibility to manually force mismatching options for advanced users, of course).

Of course, the devil is in the details and there is infinite bike shedding potential hidden in the specific structure, semantics and naming of the relevant NixOS module options. :shrug:

SuperSandro2000 commented 1 month ago

Afaik, Plasma 6 and Gnome both officially support running under X11 and Wayland. I remember it being a widely advertised feature that "X11 support is not going away" in both DEs. If running these DEs under X11 is an officially supported usage (even if it isn't the default), then it should be properly supported in the NixOS module system (imho).

Well, I don't think I ever tested Plasma 6 under xorg and I am one of the maintainers for it and I am opposed to make people big hopes that it is well tested. We are already pretty busy with testing the recommended way and fixing all the bugs that come up.

  1. In terms of UX, why is xserver.enable a global option, but wayland.enable is configured inside SDDM?

Because xserver is a service that runs globally and the wayland sddm option just sets some config options and then sddm itself starts the compositor. https://github.com/NixOS/nixpkgs/blob/c3aa7b8938b17aebd2deecf7be0636000d62a2b9/nixos/modules/services/display-managers/sddm.nix#L45

To enable X11 for Plasma 6 you need to set

IIRC you just need to enable xserver.

Why is the default gnome session configured inside GDM?

No idea, ask a Gnome maintainer 🤷🏼 Probably historically reasons.

What if I'm using SDDM with Gnome?

Then you are using custom things and tinkering which are hard to support and are not well tested.

SDDM will default to the Wayland version of Gnome even if sddm.wayland.enable = false and xserver.enable = true.

That option has nothing to do what software you are going to start but only influences if SDDM itself is running with xorg or wayland.

What if I am using Plasma with GDM? (∀X ∈ displayManagers ∀Y ∈ desktopManagers "What if I am using X with Y?")

Then you are on your own and tinkering and if things break you can't expect to much support from the maintainers of either because they don't test that scenario well and it is probably not just change one thing.

The list of possible session names that you can use as the defaultSession isn't very discoverable. How are you supposed to know to use the string "plasmax11" from reading the option docs, without reading the NixOS Wiki or the nixpkgs sources?

They are desktop files under /run/current-system/sw/share/xsessions/plasmax11.desktop or /run/current-system/sw/share/wayland-sessions/plasma.desktop.

The assertion for that option will list all possible values. #335208

We can't precompile a list because it depends on the enabled desktops.

I am assuming that the fact that displayManager.gdm and desktopManager.gnome are located inside xserver and require setting xserver.enable = true despite using wayland by default is because they "need to properly opt into that" as you said, but this is quite jank nonetheless.

Please get in touch with the gnome maintainers that they move those options. out of xserver.

The current situation just doesn't feel all that elegant from the user's perspective. As a user, I don't want to learn/understand how to manually configure X11/Wayland support.

If you want to customize those settings then you kinda need to understand what you are doing as those options are usually pretty complicated to debug.

  1. Which kind of graphical server do I want to use? (X11 or Wayland (or none/headless))

or they just stick to the default which are in the beginning probably most people are doing.

  1. Which display manager do I want to use? (SDDM or GDM or ...)

All beginners and probably many after that will just be using what works best with their DE.

  1. Which desktop manager do I want to use? (Plasma or Gnome or ...)

That's the decision that people really need to make. If they come from Windows I usually recommend Plasma and SDDM with that and if they come from Mac or want touch support then Gnome. If they have a pretty bad laptop then XFCE.

with the possibility to manually force mismatching options for advanced users, of course

No. An assertion should be so well written that when it triggers it is almost certainly correct. Having to add options to silence assertions just proves that the assertion is bad and should be made less verbose and if that can't be done, be removed and the options description needs to be expanded.

LunNova commented 1 month ago

As one of the plasma maintainers, we only want people to choose wayland for 6 and xorg for 5.

This is news to me! Haven't been maintaining much recently but I've been running 6 with X on one of my systems because kwin wayland's still unusably bad for windowed gaming where latency matters. If it breaks I would expect to try to fix it and I'd prefer not to intentionally remove support for it.

Treating it as off the beaten path/at your own risk seems reasonable.