Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nixos/sddm: enable Wayland support #242009

Merged
merged 2 commits into from
Oct 3, 2023
Merged

nixos/sddm: enable Wayland support #242009

merged 2 commits into from
Oct 3, 2023

Conversation

K900
Copy link
Contributor

@K900 K900 commented Jul 7, 2023

Description of changes

Split off from #239389.

Things done
  • Built on platform(s)
    • x86_64-linux
    • aarch64-linux
    • x86_64-darwin
    • aarch64-darwin
  • For non-Linux: Is sandbox = true set in nix.conf? (See Nix manual)
  • Tested, as applicable:
  • Tested compilation of all packages that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD". Note: all changes have to be committed, also see nixpkgs-review usage
  • Tested basic functionality of all binary files (usually in ./result/bin/)
  • 23.11 Release Notes (or backporting 23.05 Release notes)
    • (Package updates) Added a release notes entry if the change is major or breaking
    • (Module updates) Added a release notes entry if the change is significant
    • (Module addition) Added a release notes entry if adding a new NixOS module
  • Fits CONTRIBUTING.md.

@K900
Copy link
Contributor Author

K900 commented Jul 8, 2023

Split off the Plasma cleanups into #242224.

@alois31
Copy link
Contributor

alois31 commented Jul 8, 2023

I was not able to get the Wayland greeter working using KWin. Both KWin and the greeter itself seem to start, but I just see a black screen. However, I was able to get it working using Weston with the following configuration:

services.xserver.displayManager.sddm.settings = {
  General = {
    DisplayServer = "wayland";
    InputMethod = "";
  };
  Wayland.CompositorCommand = let
    xcfg = config.services.xserver;
    westonIni = (pkgs.formats.ini {}).generate "weston.ini" {
      libinput = {
        enable-tap = xcfg.libinput.mouse.tapping;
        left-handed = xcfg.libinput.mouse.leftHanded;
      };
      keyboard = {
        keymap_model = xcfg.xkbModel;
        keymap_layout = xcfg.layout;
        keymap_variant = xcfg.xkbVariant;
        keymap_options = xcfg.xkbOptions;
      };
    };
  in "${pkgs.weston}/bin/weston --shell=fullscreen-shell.so -c ${westonIni}";
};

Unfortunately, Weston does not read the keyboard/libinput settings from the usual locations itself, and needs a configuration file. However, this configuration file can be generated from the declarative configuration file, as shown above for what I thought are the most important options. The greeter for some reason still claims the keyboard layout is US English (lol), but typing confirms that the correct layout was picked up.

I did not get the virtual keyboard working even with Weston, so the configuration still has InputMethod = "".

@ilya-fedin
Copy link
Contributor

ilya-fedin commented Jul 8, 2023

I was not able to get the Wayland greeter working using KWin.

I was. And IMO it's worth the effort.

@ilya-fedin
Copy link
Contributor

ilya-fedin commented Jul 8, 2023

I did not get the virtual keyboard working even with Weston, so the configuration still has InputMethod = "".

it's the right value on Wayland, empty value means default which is the text-input protocol on Wayland. The compositor can then provide CJK, virtual keyboard or whatever else.

See sddm/sddm@07631f2

@alois31
Copy link
Contributor

alois31 commented Jul 8, 2023

I was. And IMO it's worth the effort.

Did it work with the configuration from this PR, or did you require extra changes?

@ilya-fedin
Copy link
Contributor

ilya-fedin commented Jul 8, 2023

Yes, with extra changes mentioned in the previous PR (getting rid of QT_PLUGIN_PATH from environment.profileRelativeSessionVariables)

@alois31
Copy link
Contributor

alois31 commented Jul 8, 2023

Yes, with extra changes mentioned in the previous PR (getting rid of QT_PLUGIN_PATH from environment.profileRelativeSessionVariables)

I managed to get it working now without this, by adding layer-shell-qt and kirigami2 to SDDMs build inputs, like oxalica suggested. Some things I noticed:
Good: Less glitches (e.g. the screen does not briefly turn completely black when the greeter starts and exits).
Neutral: Keyboard layout stuff works out of the box the same way as with my show Weston configuration (i.e. correct layout is applied, but US English is displayed).
Neutral: The greeter window appearing is animated. Some people may like it, some may not like it, but it's minor either way.
Bad: Tap-to-click does not work in the greeter. (I have not tried left-handed mode.)

@ilya-fedin
Copy link
Contributor

ilya-fedin commented Jul 8, 2023

I managed to get it working now without this,

Yeah, there are also likely other workarounds like adding layer-shell-qt to environment.sessionVariables

@ilya-fedin
Copy link
Contributor

ilya-fedin commented Jul 8, 2023

Adding environment variables via sddm-greeter.pam should also work theoretically

@ilya-fedin
Copy link
Contributor

With these changes it works like a charm!

diff --git a/nixos/modules/services/x11/display-managers/sddm.nix b/nixos/modules/services/x11/display-managers/sddm.nix
index 56ae3193895b..0757f7ce364f 100644
--- a/nixos/modules/services/x11/display-managers/sddm.nix
+++ b/nixos/modules/services/x11/display-managers/sddm.nix
@@ -33,6 +33,9 @@ let
 
       # Implementation is done via pkgs/applications/display-managers/sddm/sddm-default-session.patch
       DefaultSession = optionalString (dmcfg.defaultSession != null) "${dmcfg.defaultSession}.desktop";
+    } // lib.optionalAttrs cfg.enableKwinWayland {
+      DisplayServer = "wayland";
+      InputMethod = "";
     };
 
     Theme = {
@@ -62,6 +65,8 @@ let
     Wayland = {
       EnableHiDPI = cfg.enableHidpi;
       SessionDir = "${dmcfg.sessionData.desktops}/share/wayland-sessions";
+    } // lib.optionalAttrs cfg.enableKwinWayland {
+      CompositorCommand = "${pkgs.kwin}/bin/kwin_wayland --no-global-shortcuts --no-lockscreen --locale1";
     };
   } // lib.optionalAttrs dmcfg.autoLogin.enable {
     Autologin = {
@@ -69,13 +74,6 @@ let
       Session = autoLoginSessionName;
       Relogin = cfg.autoLogin.relogin;
     };
-  } // lib.optionalAttrs cfg.enableKwinWayland {
-    General = {
-      GreeterEnvironment = "QT_PLUGIN_PATH=${pkgs.plasma5Packages.layer-shell-qt}/${pkgs.plasma5Packages.qtbase.qtPluginPrefix},QT_WAYLAND_SHELL_INTEGRATION=layer-shell";
-      DisplayServer = "wayland";
-      InputMethod = "";
-    };
-    Wayland.CompositorCommand = "${pkgs.kwin}/bin/kwin_wayland --no-global-shortcuts --no-lockscreen --locale1";
   };
 
   cfgFile =
@@ -251,7 +249,14 @@ in
         session  optional       ${config.systemd.package}/lib/security/pam_systemd.so
         session  optional       pam_keyinit.so force revoke
         session  optional       pam_permit.so
-      '';
+      '' + lib.optionalString cfg.enableKwinWayland (let
+        environmentFile = pkgs.writeText "sddm-greeter-environment" ''
+          QT_PLUGIN_PATH DEFAULT="${pkgs.plasma5Packages.layer-shell-qt}/${pkgs.plasma5Packages.qtbase.qtPluginPrefix}"
+          QT_WAYLAND_SHELL_INTEGRATION DEFAULT="layer-shell"
+        '';
+      in ''
+        session  required       pam_env.so conffile=${environmentFile} readenv=0
+      '');
 
       sddm-autologin.text = ''
         auth     requisite pam_nologin.so

PS: while on it, I checked which tty it actually occupies: it's tty2.

@ilya-fedin
Copy link
Contributor

Oops, it was a mistest, forgot to set enableKwinWayland. It actually occupies tty7 so SDDM_INITIAL_VT seem to have effect. It still works like a charm.

@K900
Copy link
Contributor Author

K900 commented Jul 8, 2023

Maybe we should just wrap the greeter with layer-shell-qt, it's a tiny closure size change and it saves a lot of, well, this.

@alois31
Copy link
Contributor

alois31 commented Jul 8, 2023

Maybe we should just wrap the greeter with layer-shell-qt, it's a tiny closure size change and it saves a lot of, well, this.

That's basically what adding it to buildInputs does, right?

@K900
Copy link
Contributor Author

K900 commented Oct 3, 2023

Honestly, the more I think about it, the more convinced I am that forcing KWin here is not the way to go. It's missing support for things like DPMS, and it's just diverging from upstream for ... what exactly? A few megabytes of closure size?

@K900
Copy link
Contributor Author

K900 commented Oct 3, 2023

OK, I think I like the state of things now. I've cherry-picked the major fixes that should allow running other compositors should you want to, but the module only supports Weston, to match upstream.

@alois31
Copy link
Contributor

alois31 commented Oct 3, 2023

Without setting services.xserver.displayManager.sddm.settings.General.InputMethod = "", I still get a virtual keyboard followed by a black screen.

@K900
Copy link
Contributor Author

K900 commented Oct 3, 2023

This should be fixed with the last force push.

@alois31
Copy link
Contributor

alois31 commented Oct 3, 2023

I was already patching that one in, seems that it doesn't work properly.

@K900
Copy link
Contributor Author

K900 commented Oct 3, 2023

Just to make sure, you have sddm/sddm@07631f2 applied, correct?

@ilya-fedin
Copy link
Contributor

OK, so the KWin part just doesn't work, so I've tried to minimize the change to just be Weston.

How is that happened? I patch nixpkgs with the changes I proposed for this and sddm wayland works just fine with kwin.

It's missing support for things like DPMS

Is this a typo? KWin is advanced while Weston is basic.

and it's just diverging from upstream for ... what exactly?

For proper functionality. I bet there will be a lot of problems with Weston.

@alois31
Copy link
Contributor

alois31 commented Oct 3, 2023

Just to make sure, you have sddm/sddm@07631f2 applied, correct?

Yes, that one is applied (and I verified that the correct SDDM is put into my environment.systemPackages).

@K900
Copy link
Contributor Author

K900 commented Oct 3, 2023

How is that happened? I patch nixpkgs with the changes I proposed for this and sddm wayland works just fine with kwin.

That was me testing it without the patches. With the patches, it should work.

Is this a typo? KWin is advanced while Weston is basic.

No, it's not in fact a typo. KWin relies on KScreen for display power management, which does not run in the SDDM "session". Weston has it integrated.

For proper functionality. I bet there will be a lot of problems with Weston.

No but like, specifically? What functionality is required to run a greeter that Weston is missing?

@K900
Copy link
Contributor Author

K900 commented Oct 3, 2023

Yes, that one is applied (and I verified that the correct SDDM is put into my environment.systemPackages).

That's weird. Do you have InputMethod set at all right now?

@alois31
Copy link
Contributor

alois31 commented Oct 3, 2023

OK, so the KWin part just doesn't work, so I've tried to minimize the change to just be Weston.

How is that happened? I patch nixpkgs with the changes I proposed for this and sddm wayland works just fine with kwin.

After applying all the patches KWin works (not sure about the InputMethod stuff, I only tested with Weston).

It's missing support for things like DPMS

Is this a typo? KWin is advanced while Weston is basic.

and it's just diverging from upstream for ... what exactly?

For proper functionality. I bet there will be a lot of problems with Weston.

The only I have noticed with Weston that doesn't happen with KWin is the unnecessary modeset, which is purely cosmetic. Upstream default is Weston, and I guess that means it at least works somewhat properly.

@alois31
Copy link
Contributor

alois31 commented Oct 3, 2023

Yes, that one is applied (and I verified that the correct SDDM is put into my environment.systemPackages).

That's weird. Do you have InputMethod set at all right now?

Right now, yes, it's empty because I set it that way so that SDDM works. On the broken configuration there is no InputMethod entry in sddm.conf.

Copy link
Contributor

@alois31 alois31 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The InputMethod issue appears to have been caused by testing a stale SDDM on my end. Everything appears to work well (except for the known cosmetic issues), it's nice and simple, in line with upstream defaults, and people who really want to use KWin can do so without recompiling SDDM.

@ilya-fedin
Copy link
Contributor

No but like, specifically? What functionality is required to run a greeter that Weston is missing?

It's not a matter of required but a matter of nice to have I guess. WIth Weston it will work but with kwin it will work way more nicely I believe. E.g. Weston seem to not to support xdg-positioner (at least I have popups out of screen when running weston nested to test something).

@K900
Copy link
Contributor Author

K900 commented Oct 3, 2023

It's not a matter of required but a matter of nice to have I guess. WIth Weston it will work but with kwin it will work way more nicely I believe. E.g. Weston seem to not to support xdg-positioner (at least I have popups out of screen when running weston nested to test something).

Does the greeter actually use that? I'm pretty sure it's just rendering everything into one big fullscreen surface.

@ilya-fedin
Copy link
Contributor

ilya-fedin commented Oct 3, 2023

idk honestly. I only know my experience with Weston wasn't great.

@K900
Copy link
Contributor Author

K900 commented Oct 3, 2023

With Weston as a general desktop compositor or specifically when running a greeter? Like, the requirements are a lot lower here.

@K900 K900 merged commit 08751df into NixOS:master Oct 3, 2023
24 checks passed
@name-snrl
Copy link
Contributor

needs cleanup

Should I create a new issue about this? I'm not very familiar with xserver module, but to me (sway user) it looks like it does a bunch of things I don't really need. I just want to enable 2 options in my config and get sddm without any X-junk in my system.

@K900
Copy link
Contributor Author

K900 commented Oct 3, 2023

What do you mean by "a bunch of things you don't really need"? sddm.wayland.enable should be enough to make the greeter run on Wayland.

@name-snrl
Copy link
Contributor

should be enough

It requires xserver to be enabled.

assertions = [
{
assertion = xcfg.enable;
message = ''
SDDM requires services.xserver.enable to be true
'';
}

@K900
Copy link
Contributor Author

K900 commented Oct 3, 2023

It doesn't, that option is badly named. If you use sddm.wayland.enable and a Wayland session, no X server will run at any point (except maybe XWayland, if your session uses that).

@SuperSamus
Copy link
Contributor

Relevant: #94799

@name-snrl
Copy link
Contributor

no X server will run

Yes, I know, but it still install packages and creates configs

@K900
Copy link
Contributor Author

K900 commented Oct 3, 2023

That is tracked in #94799 and requires a serious refactoring of the services.xserver module itself, something which is very much out of scope for this PR.

@ilya-fedin
Copy link
Contributor

No but like, specifically? What functionality is required to run a greeter that Weston is missing?

I've accidentally found someone else enumerating
изображение

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants