kde: fix plasma cli tools in activation
KDE theming uses CLI tools which require D-Bus and Plasma session. Instead of breaking home-manager activation, this PR allows it to fail and introduces optional systemd unit to run after login.
Fixes #422, #350 and #340
Please note that the service (if enabled) is suboptimal, as it will continually restart even if not in KDE session. I am not good enough with systemd to fix this with confidence in my solution. Should be a non-issue though, given that it has to be explicitly enabled. Restarting is mandatory (in my opinion), because first activation fails with The name is not activable when loading wallpaper by id stylix and I don't want to resort to hacks like sleep 5s && set-wallpaper.
@danth is there anything to change or is this fit for merge?
Hello @trueNAHO, I looked at other PRs and saw you were quite active. Is there anything more to do? I saw the push for decoupling wallpaper from other settings, but I would rather fix this before going into more refactoring.
Is there anything more to do?
Unfortunately, I am unfamiliar with the KDE internals and what exactly is required on the Nix level. Consider waiting on @danth's review or pinging anyone who last touched the KDE module.
I saw the push for decoupling wallpaper from other settings
What push are you referring to?
but I would rather fix this before going into more refactoring.
I agree that it would be good to merge this PR prior to further refactoring.
I saw the push for decoupling wallpaper from other settings
What push are you referring to?
Roadmap in #534 lists support for multiple and/or optional wallpaper as goals for future. I didn't mean push in the PR sense.
@danth is there anything I should change?
@rkuklik This unfortunately does not always work. On my system, waiting for plasma-plasmashell.service was not sufficient.
Besides the improper timing, the service does however work wonderfully, amazing work~
I'm new to systemd and NixOS in general, but one such service that worked to wait on for me was my user's home-manager-<user> service. It likely is not optimal however.
https://github.com/hiibolt/stylix/commit/abcd2036a1420779f6925f0db5aea86b86ae3ac6
Thank you for review. For me, home-manager-<user> didn't work, as it starts before user even logs in. No idea what to target though.
Hm, I just realized that waiting for home-manager-<user>.service is not going to work anyway, since not everyone runs (or can run) home-manager activation using the home-manager NixOS module.
When calling home-manager switch ... you won't have a corresponding service unit to wait on.
Maybe you can run this using some KDE Plasma mechanic, like autostart? Create a "hidden" .desktop file and have it run the missing stylix bits? Or maybe there's some other plasma thing I just don't know about that can be used for this.
Hm, I just realized that waiting for
home-manager-<user>.serviceis not going to work anyway, since not everyone runs (or can run) home-manager activation using the home-manager NixOS module. When callinghome-manager switch ...you won't have a corresponding service unit to wait on.Maybe you can run this using some KDE Plasma mechanic, like autostart? Create a "hidden" .desktop file and have it run the missing stylix bits? Or maybe there's some other plasma thing I just don't know about that can be used for this.
Agreed, I do not think what worked on my system works on all systems by any means.
I am new to NixOS and Linux in general, but is there a way to programmatically start the service on the condition that the background services fails?
Maybe you can run this using some KDE Plasma mechanic, like autostart? Create a "hidden" .desktop file and have it run the missing stylix bits? Or maybe there's some other plasma thing I just don't know about that can be used for this.
I finally got around to implement this, using what Plasma calls an "AutostartScript". It's basically a desktop entry in the autostart directory which has a special tag X-KDE-AutostartScript that tells Plasma to start it early. The X-KDE-AutostartScript is probably not required, since I noticed that plasma-manager is doing something similar without it.
I hope that this should work for all scenarios since it doesn't depend on the activation method. I have tested it on NixOS 24.11 beta (with Plasma 6.2.3).
@rkuklik @hiibolt Would you be willing to try out my change and see if it works for your setups too? Here's my change https://github.com/lordkekz/stylix/commit/88fb76933824c2cd0fdeaf837d0b3ce4d4d2ed71 (I rebased onto the current master btw)
Hey, sorry for the delay, I missed the notification and forgot that I have this PR open. Given that #708 builds upon this, let this PR lay to rest.
Also, if I don't respond in like four days, feel free to ping me again, I most likely forgot.