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/plasma5: make it run using systemd and wayland #117102

Merged
merged 2 commits into from
Oct 22, 2021

Conversation

peterhoeg
Copy link
Member

@peterhoeg peterhoeg commented Mar 21, 2021

Motivation for this change

With nixos-unstable as of 2021-03-29, in order to activate the "run with systemd mode", you can either:

  1. execute this once as the user:

kwriteconfig5 --file startkderc --group General --key systemdBoot true

  1. or add this to your configuration.nix (when using this PR):
services.xserver.desktopManager.plasma5.runUsingSystemd = true;

If you want to try out wayland, you need to make the wayland session file available to sddm:

The nicer way:

services.xserver.displayManager.sessionPackages = [
  (pkgs.plasma-workspace.overrideAttrs
    (old: { passthru.providedSessions = [ "plasmawayland" ]; }))
];

Alternatively, override the path to the wayland sessions directory for sddm. This will make all other wayland sessions unavailable:

services.xserver.displayManager.sddm.settings.Wayland.SessionDir =
  "${pkgs.plasma5Packages.plasma-workspace}/share/wayland-sessions";

Please note that you probably want to run the session with systemd if you're trying out the wayland variant.

Things done
  • Tested using sandboxing (nix.useSandbox on NixOS, or option sandbox in nix.conf on non-NixOS linux)
  • Built on platform(s)
    • NixOS
    • macOS
    • other Linux distributions
  • Tested via one or more NixOS test(s) if existing and applicable for the change (look inside nixos/tests)
  • Tested compilation of all pkgs that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review wip"
  • Tested execution of all binary files (usually in ./result/bin/)
  • Determined the impact on package closure size (by running nix path-info -S before and after)
  • Ensured that relevant documentation is up to date
  • Fits CONTRIBUTING.md.

@github-actions github-actions bot added 6.topic: nixos Issues or PRs affecting NixOS modules, or package usability issues specific to NixOS 6.topic: qt/kde 8.has: module (update) This PR changes an existing module in `nixos/` labels Mar 21, 2021
@peterhoeg
Copy link
Member Author

peterhoeg commented Mar 21, 2021

Cc @ttuegel @samueldr @petabyteboy @ajs124

@nixos-discourse
Copy link

This pull request has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/plasma-and-systemd/12057/1

@ofborg ofborg bot added 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin 10.rebuild-linux: 1-10 labels Mar 21, 2021
@peterhoeg
Copy link
Member Author

I'm guessing that @eliasp is probably interested in this too.

@worldofpeace
Copy link
Contributor

Is it not possible to fix the systemd units in the package with substitution? Also, why doesn't the substitution that CMake does on the units not work https://github.com/KDE/plasma-workspace/blob/master/ksmserver/plasma-restoresession.service.in#L8?

@worldofpeace
Copy link
Contributor

807a6cb LGTM 👍

@Yarny0
Copy link
Contributor

Yarny0 commented Mar 21, 2021

Review per https://nixos.org/manual/nixpkgs/stable/#reviewing-contributions-module-updates

Reviewed points
  • changes are backward compatible
Comments
  • Tested branch as it currently is, in virtualbox, with xfce installed besides plasma5.

  • Tested with a fresh user account:

    1. login with plasma5
    2. execute kwriteconfig5 --file startkderc --group General --key systemdBoot true
    3. logout
    4. kill lingering session with loginctl kill-session (I don't know why this is needed), so that a fresh session can be initiated
    5. login with plasma5
  • Amazingly, plasma5 starts without any visible problems.

  • The following systemd user service fails to start

      user2@nixosb:~> systemctl --user status plasma-kcminit-phase1.service
      ● plasma-kcminit-phase1.service
           Loaded: loaded (/nix/store/m0dl46l9zb0axlym5cc23qn0aqx8g0ws-unit-plasma-kcminit-phase1.service/plasma-kcminit-phase1.service; linked-runtime; vendor preset: enabled)
           Active: failed (Result: exit-code) since Sun 2021-03-21 19:51:46 CET; 23min ago
          Process: 5844 ExecStart=/nix/store/2ijmr91zlf2rcggx9bp1q4mcdg6zcm4m-qttools-5.15.2-bin/bin/qdbus org.kde.kcminit /kcminit org.kde.KCMInit.runPhase1 (code=exited, status=2)
         Main PID: 5844 (code=exited, status=2)
              CPU: 50ms
    
      Mar 21 19:51:45 nixosb systemd[4835]: Started plasma-kcminit-phase1.service.
      Mar 21 19:51:45 nixosb qdbus[5844]: Service 'org.kde.kcminit' does not exist.
      Mar 21 19:51:46 nixosb systemd[4835]: plasma-kcminit-phase1.service: Main process exited, code=exited, status=2/INVALIDARGUMENT
      Mar 21 19:51:46 nixosb systemd[4835]: plasma-kcminit-phase1.service: Failed with result 'exit-code'.
    

    Before switching to systemdBoot, this service didn't even try to start.

@peterhoeg
Copy link
Member Author

Is it not possible to fix the systemd units in the package with substitution?

Yes, and as pointed out in the message, I will basically undo that commit when fixing the package properly - it was just to make it easy for people to test out without having to do any (re)compiling.

Also, why doesn't the substitution that CMake does on the units not work https://github.com/KDE/plasma-workspace/blob/master/ksmserver/plasma-restoresession.service.in#L8?

We have qdbus in qttools while the cmake scripts point at qtbase.

@peterhoeg
Copy link
Member Author

* The following systemd user service fails to start

What does systemctl --user status plasma-kcminit say?

@peterhoeg peterhoeg changed the title nixos/plasma5: make it run using systemd nixos/plasma5: make it run using systemd and wayland Mar 22, 2021
@peterhoeg peterhoeg requested a review from ttuegel March 22, 2021 12:46
@peterhoeg
Copy link
Member Author

I haven't tried without using systemd to manage the session, but with this PR and a single line of config, you can run a KDE wayland session:

services.xserver.displayManager.sddm.settings.Wayland.SessionDir =
  "${pkgs.plasma5Packages.plasma-workspace}/share/wayland-sessions";

I haven't looked at the proper way to add the session file so this is the quick and dirty. But it works.

Couple of things that don't:

  1. the pager is blank
  2. notifications steal focus (which is a pain...)
  3. and of course, I need to find alternatives to xmodmap and xcape

Otherwise it looks pretty solid.

@jansol
Copy link
Contributor

jansol commented Mar 22, 2021

Giving it a spin as I write this. Works fine¹ although a lot of polishing is clearly still needed. Without the kwriteconfig5 command pipewire wasn't working at all, after running that and rebooting pipewire is fine.

I have two monitors in the following arrangement:

  • a 24" 4K@60 screen on the top left, set to 200% scaling
  • a 48" 4K@120 screen with 100% scaling, meant to be the main display

Some problems I ran into straight away:

  • Plasmashell context menus flicker partially in and out of existence as the cursor moves over them (interestingly application context menus are fine), but only on the 2nd ("main") display and sometimes only when passing over an entry that opens a submenu
    • First I thought this would be caused by the refresh rate mismatch, but after setting both displays to 60Hz the problem still persists
  • Context menus aren't transparent although they should (System Settings -> Workspace Behavior -> Desktop Effects -> Translucency)
    • Firefox context menus (running in xwayland apparently) do have this
  • Context menu positioning is sometimes wonky (happens at least in cantata when the window is as tall as the screen and located on the unscaled monitor, possibly an application-specific bug)
  • Editing the panel is hard since half of the times it loses focus and exits edit mode for no good reason
    • plasmashell also frequently crashes when attempting this
  • Panel defaults to the 1st ("secondary") display
    • Like do many games from steam and the telegram-desktop image viewer. Some are fine with being dragged to the main display and will remember that on the next launch, some aren't (with various degrees of breakage from not remapping cursor positions correctly to locking up input).
  • Windows don't show up in the task manager in panels -- can't restore minimized windows (except by alt+tabbing, unless whatever handles that has crashed in which case good luck) Fixed by kwin: Unwrap executable name for desktop file search #116549.
  • Fcitx5 isn't working in wayland-native applications Fixed by kwin: Unwrap executable name for desktop file search #116549. IME popup positioning is wrong though
  • works in xwayland applications though, and also logs that it loads a wayland module
  • Flameshot launches but can't take screenshots
  • Font rendering sometimes looks corrupted in System Settings when the window opens on the main display. This goes away when dragging the window to the (200% scaled) secondary screen and back
  • Some window previews when hovering over an application in the pager flicker between correct and wrong size, possibly related to the refresh rate mismatch since it happens particularly with windows on the smaller, slower screen while the pager is on the bigger faster one.

¹for some value of "fine"

@Yarny0
Copy link
Contributor

Yarny0 commented Mar 22, 2021

What does systemctl --user status plasma-kcminit say?

The service started successfully, then stopped 5 min later:

user2@nixosb:~> systemctl --user status plasma-kcminit
● plasma-kcminit.service - KDE Config Module Initialization
     Loaded: loaded (/nix/store/82zx0kyyy8ch6h2yhhhpxya84cniap6y-plasma-workspace-5.21.1/share/systemd/user/plasma-kcminit.service; linked-runtime; vendor preset: enabled)
     Active: inactive (dead) since Mon 2021-03-22 18:51:06 CET; 1min 20s ago
    Process: 2050 ExecStart=/nix/store/82zx0kyyy8ch6h2yhhhpxya84cniap6y-plasma-workspace-5.21.1/bin/kcminit_startup (code=exited, status=0/SUCCESS)
   Main PID: 2058 (code=exited, status=0/SUCCESS)
        CPU: 11.219s

Mar 22 18:45:54 nixosb systemd[1933]: Starting KDE Config Module Initialization...
Mar 22 18:46:05 nixosb kcminit_startup[2058]: Initializing  "kcm_style" :  "kcminit_style"
Mar 22 18:46:05 nixosb kcminit_startup[2085]: /var/tmp/kcminit.XwgQhJ:0: warning: Unknown encoding: C.UTF-8
Mar 22 18:46:06 nixosb kcminit_startup[2085]:     
Mar 22 18:46:06 nixosb kcminit_startup[2058]: QDBusConnection: error: could not send signal to service "" path "//home/user2/.kde/share/config/kdeglobals" interface "org.kde.kconfig.notify" member "ConfigChanged": Invalid object path: //home/user2/.kde/share/config/kdeglobals
Mar 22 18:46:06 nixosb kcminit_startup[2058]: Initializing  "kcm_mouse" :  "kcminit_mouse"
Mar 22 18:46:06 nixosb systemd[1933]: Started KDE Config Module Initialization.
Mar 22 18:51:06 nixosb systemd[1933]: plasma-kcminit.service: Succeeded.
Mar 22 18:51:06 nixosb systemd[1933]: plasma-kcminit.service: Consumed 11.219s CPU time.

I got irritated by the "Unknown encoding" error. Note that the test system has the NixOS configuration i18n.defaultLocale = "C.UTF-8";. I changed that to en_US.UTF-8 and tried again (with a fresh user account). The waring disappears, everything else stays the same.

Regarding the PR's title change, I'd like to add that I didn't enable wayland for this tests.

@peterhoeg
Copy link
Member Author

First post has been updated with the current situation. You might find #100057 interesting as well.

@matrss
Copy link
Contributor

matrss commented Mar 27, 2021

I haven't looked at the proper way to add the session file so this is the quick and dirty. But it works.

I currently have the following in my config:

services.xserver.displayManager.sessionPackages = [
    (pkgs.plasma-workspace.overrideAttrs
      (old: { passthru.providedSessions = [ "plasmawayland" ]; }))
  ];

Still a bit hacky I guess, but it should not make any other sessions unavailable...

@pasqui23
Copy link
Contributor

@matrss it's how I'm testing #100057

@matrss
Copy link
Contributor

matrss commented Mar 27, 2021

@pasqui23 In that case I probably got the code from you at some point and should give you credit for it. Had it sitting around in my config for a while now and could not remember where I got it from, sorry about that.

@jakobrs
Copy link
Contributor

jakobrs commented Mar 28, 2021

Edit: This only seems to happen with the proprietary nvidia driver (with PRIME), so it's probably an nvidia bug (or upstream Plasma).


Using this, kwin_wayland just crashes when logging in. I've tried:

From journalctl -b:

Mar 28 11:29:23 girafarig kernel: show_signal_msg: 78 callbacks suppressed
Mar 28 11:29:23 girafarig kernel: kwin_wayland[1339]: segfault at 18 ip 00007f8ccfc6d6d0 sp 00007ffc2cf22dd8 error 6 in libgbm.so.1.0.0[7f8ccfc6d000+7000]
Mar 28 11:29:23 girafarig kernel: Code: 2e 0f 1f 84 00 00 00 00 00 90 ff a7 b8 00 00 00 66 2e 0f 1f 84 00 00 00 00 00 ff a7 c0 00 00 00 66 2e 0f 1f 84 00 00 00 00 00 <83> 6f 18 01 75 0a ff a7 b0 00 00 00 0f 1f>
Mar 28 11:29:23 girafarig systemd[1]: Created slice system-systemd\x2dcoredump.slice.
Mar 28 11:29:23 girafarig systemd[1]: Started Process Core Dump (PID 1343/UID 0).
Mar 28 11:29:23 girafarig systemd-coredump[1344]: Process 1339 (kwin_wayland) of user 1000 dumped core.
Mar 28 11:29:23 girafarig systemd[1]: systemd-coredump@0-1343-0.service: Succeeded.

The above is repeated a couple of times, and then I'm returned to SDDM.

However, kwin_wayland does not segfault when checkout out #100057 (and not rebasing onto nixos-unstable). Which was running Plasma 5.20, so it seems like the upgrade to 5.21 might be why this happens.

It unbreaks if I use nouveau instead.

The above segfault lies in gbm_device_destroy btw:

00000000000036d0 <gbm_device_destroy>:
    36d0:       83 6f 18 01             subl   $0x1,0x18(%rdi)
    36d4:       75 0a                   jne    36e0 <gbm_device_destroy+0x10>
    36d6:       ff a7 b0 00 00 00       jmpq   *0xb0(%rdi)
    36dc:       0f 1f 40 00             nopl   0x0(%rax)
    36e0:       c3                      retq   
    36e1:       66 2e 0f 1f 84 00 00    nopw   %cs:0x0(%rax,%rax,1)
    36e8:       00 00 00 
    36eb:       0f 1f 44 00 00          nopl   0x0(%rax,%rax,1)

@ttuegel
Copy link
Member

ttuegel commented Aug 6, 2021

I started trying this out today because I have a new multi-monitor setup that benefits from different scaling on each screen. Here are some problems I ran into:

  1. Notifications steal focus, as mentioned above. This basically makes it unsuitable for daily use.
  2. Window thumbnails are broken in the taskbar, but work in other places like the window switcher (aka Alt-Tab).
  3. Colors are weird in Firefox XWayland apps on one display. "Green" is now more of an "olive" color.
  4. VS Code is blurry under scaling. Workaround: Native wayland support with newest electron microsoft/vscode#109176 (comment)
  5. The taskbar shows a generic icon for X11 applications.
  6. Context menus sometimes disappear.
  7. GTK applications are not themed correctly. Instead of getting Breeze, they fall back to Adwaita and have the wrong window decorations and cursors. This also affects the file chooser in Electron applications.
  8. The clock widget is missing from the lock screen.

Despite these flaws, I think the situation is definitely good enough that we can consider merging this pull request as long as X11 is still the default Plasma session.

@ttuegel
Copy link
Member

ttuegel commented Aug 6, 2021

Also worth noting: The "Plasma (X11)" session works just fine with systemd, too!

@ttuegel
Copy link
Member

ttuegel commented Aug 10, 2021

7\. GTK applications are not themed correctly.

Actually, I think this is due to using systemd and not Wayland. systemd will not run our custom scripts for setting the default theme. Plasma should use the corresponding NixOS options to set the default theme instead.

@jansol
Copy link
Contributor

jansol commented Sep 16, 2021

Found an interesting bit in logs, might explain why pipewire screen capturing, screenshots and fcitx5 are currently not working on my system:

Sep 16 10:17:09 isildur .kded5-wrapped[7560]: failed to commit changes to dconf: GDBus.Error:org.freedesktop.DBus.Error.ServiceUnknown: The name ca.desrt.dconf was not provided by any .service files
Sep 16 10:17:09 isildur .kded5-wrapped[7560]: failed to commit changes to dconf: GDBus.Error:org.freedesktop.DBus.Error.ServiceUnknown: The name ca.desrt.dconf was not provided by any .service files
Sep 16 10:17:09 isildur .kded5-wrapped[7560]: failed to commit changes to dconf: GDBus.Error:org.freedesktop.DBus.Error.ServiceUnknown: The name ca.desrt.dconf was not provided by any .service files
Sep 16 10:17:09 isildur .kded5-wrapped[7560]: failed to commit changes to dconf: GDBus.Error:org.freedesktop.DBus.Error.ServiceUnknown: The name ca.desrt.dconf was not provided by any .service files
Sep 16 10:17:09 isildur dbus-daemon[7108]: [session uid=XXXX pid=7108] Activating via systemd: service name='org.kde.ActivityManager' unit='plasma-kactivitymanagerd.service' requested by ':1.20' (uid=XXXX pid=8053 comm="/nix/store/www6xnf>
Sep 16 10:17:09 isildur systemd[7090]: Starting KActivityManager Activity manager Service...
Sep 16 10:17:09 isildur plasmashell[8053]: Aborting shell load: The activity manager daemon (kactivitymanagerd) is not running.
Sep 16 10:17:09 isildur plasmashell[8053]: If this Plasma has been installed into a custom prefix, verify that its D-Bus services dir is known to the system for the daemon to be activatable.

@Artturin
Copy link
Member

sorry about that i had remembered that it after using gh pr checkout it would prompt me for where i want to push

@peterhoeg
Copy link
Member Author

To whoever is tracking this - Plasma with Wayland works wonderfully here with latest unstable and this PR applied. There are a few minor glitches (those are upstream issues) as well as a few non-KDE applications not behaving properly but that's neither our nor KDE's fault. I really want to get this cleaned up properly and submitted for 21.11.

@bhankas
Copy link
Contributor

bhankas commented Oct 7, 2021 via email

@nixos-discourse
Copy link

This pull request has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/how-to-try-a-pr/15410/1

@haizaar
Copy link

haizaar commented Oct 9, 2021

Tried this today and so far so good - Wayland session has appeared and it's been working for the last several hours.

How to make it happen into 21.11? Whom do we need to ping to review?

P.S. If you are new to Nix and want to try the fix, here are the instructions: https://discourse.nixos.org/t/how-to-try-a-pr/15410/6?u=haizaar

@peterhoeg peterhoeg force-pushed the m/plasma_systemd branch 2 times, most recently from 904a34b to 5941db1 Compare October 11, 2021 03:15
@peterhoeg
Copy link
Member Author

It's been rebased - I'd like to do a final test when #100057 hits unstable and then go ahead and get this merged.

@nixos-discourse
Copy link

This pull request has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/kde-plasma-wayland-still-does-not-behave-correctly/15526/2

@peterhoeg
Copy link
Member Author

Looks like we're good to go.

Any thoughts on making the "run with systemd" default to true?

@bhankas
Copy link
Contributor

bhankas commented Oct 21, 2021

Looks like we're good to go.

Any thoughts on making the "run with systemd" default to true?

I vote yes.

@haizaar
Copy link

haizaar commented Oct 21, 2021

@CertainLach is there anything in your powers to get it approved/merged? (apologies if I'm pinging a wrong person)

@pasqui23
Copy link
Contributor

Looks like we're good to go.

Any thoughts on making the "run with systemd" default to true?

Yes, default to true. In fact, I would not mind if it is the only option, as it is only a implementation detail after all

@peterhoeg
Copy link
Member Author

I'll go ahead and merge this. The "systemd by default" shouldn't be too controversial, but we can always flick that switch.

@peterhoeg peterhoeg merged commit d2ed9e4 into NixOS:master Oct 22, 2021
@peterhoeg peterhoeg deleted the m/plasma_systemd branch October 22, 2021 04:44
@oxalica oxalica mentioned this pull request Oct 24, 2021
12 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
6.topic: nixos Issues or PRs affecting NixOS modules, or package usability issues specific to NixOS 6.topic: qt/kde 8.has: module (update) This PR changes an existing module in `nixos/` 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin 10.rebuild-linux: 1-10
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.