From ad3e6b09f02f113ef600a04674db1bce46a03023 Mon Sep 17 00:00:00 2001 From: rkuklik Date: Sat, 7 Sep 2024 22:33:18 +0200 Subject: [PATCH 1/2] kde: fix plasma cli tools in activation --- modules/kde/hm.nix | 92 ++++++++++++++++++++++++++++++++-------------- 1 file changed, 65 insertions(+), 27 deletions(-) diff --git a/modules/kde/hm.nix b/modules/kde/hm.nix index d7d7f64c4..245e18ed6 100644 --- a/modules/kde/hm.nix +++ b/modules/kde/hm.nix @@ -4,6 +4,8 @@ with config.stylix.fonts; with config.lib.stylix.colors; let + cfg = config.stylix.targets.kde; + formatValue = value: if builtins.isBool value then if value then "true" else "false" @@ -123,6 +125,7 @@ let ServiceTypes = [ "Plasma/LookAndFeel" ]; Website = "https://github.com/danth/stylix"; }; + KPackageStructure = "Plasma/LookAndFeel"; }; lookAndFeelDefaults = { @@ -220,11 +223,54 @@ let printf '%s\n' "$kdeglobals" >"$out/kdeglobals" ''; + activator = pkgs.writeShellScriptBin "stylix-set-kde-wallpaper" '' + set -eu + global_path() { + for directory in /run/current-system/sw/bin /usr/bin /bin; do + if [[ -f "$directory/$1" ]]; then + printf '%s\n' "$directory/$1" + return 0 + fi + done + + return 1 + } + + if wallpaper_image="$(global_path plasma-apply-wallpaperimage)"; then + "$wallpaper_image" "${themePackage}/share/wallpapers/stylix" + else + echo "Skipping plasma-apply-wallpaperimage: command not found" + fi + + if look_and_feel="$(global_path plasma-apply-lookandfeel)"; then + "$look_and_feel" --apply stylix + else + echo "Skipping plasma-apply-lookandfeel: command not found" + fi + ''; + + activateDocs = "https://stylix.danth.me/options/hm.html#stylixtargetskdesetter"; in { - options.stylix.targets.kde.enable = - config.lib.stylix.mkEnableTarget "KDE" true; + options.stylix.targets.kde = { + enable = config.lib.stylix.mkEnableTarget "KDE" true; + service = lib.mkOption { + type = lib.types.bool; + default = false; + example = true; + description = '' + Wallpaper and appearance in Plasma can only be set with KDE tools via D-Bus connection. + + However, home-manager activation happens before entering a user session + (unless started manually), causing these tools to fail. To work around this, + you can enable stylix service to automagically run these tools after login. + + If wallpaper setting fails, we simply ignore it and let home-manager activation + continue as usual. To force stylix settings manually, you can try to run `stylix-set-kde-wallpaper`. + ''; + }; + }; - config = lib.mkIf (config.stylix.enable && config.stylix.targets.kde.enable && pkgs.stdenv.hostPlatform.isLinux) { + config = lib.mkIf (config.stylix.enable && cfg.enable && pkgs.stdenv.hostPlatform.isLinux) { home.packages = [ themePackage ]; xdg.systemDirs.config = [ "${configPackage}" ]; @@ -242,30 +288,22 @@ in { # changes to KDE to make it possible to update the wallpaper through # config files alone. home.activation.stylixLookAndFeel = lib.hm.dag.entryAfter [ "writeBoundary" ] '' - global_path() { - for directory in /run/current-system/sw/bin /usr/bin /bin; do - if [[ -f "$directory/$1" ]]; then - printf '%s\n' "$directory/$1" - return 0 - fi - done - - return 1 - } - - if wallpaper_image="$(global_path plasma-apply-wallpaperimage)"; then - "$wallpaper_image" "${themePackage}/share/wallpapers/stylix" - else - verboseEcho \ - "plasma-apply-wallpaperimage: command not found" - fi - - if look_and_feel="$(global_path plasma-apply-lookandfeel)"; then - "$look_and_feel" --apply stylix - else - verboseEcho \ - "Skipping plasma-apply-lookandfeel: command not found" - fi + ${activator}/bin/stylix-set-kde-wallpaper || verboseEcho \ + "KDE theme setting failed. See `${activateDocs}`" ''; + + systemd.user.services.stylix-set-kde-wallpaper = lib.mkIf cfg.service { + Unit = { + Description = "KDE wallpaper setter for stylix"; + Documentation = activateDocs; + After = [ "plasma-plasmashell.service" ]; + }; + Service = { + ExecStart = "${activator}/bin/stylix-set-kde-wallpaper"; + Restart = "on-failure"; + RestartSec = 1; + }; + Install.WantedBy = [ "default.target" ]; + }; }; } From de72232e61a12dce6ff941b859ca6c087dad1b7b Mon Sep 17 00:00:00 2001 From: rkuklik <90713105+rkuklik@users.noreply.github.com> Date: Sun, 8 Sep 2024 08:40:00 +0200 Subject: [PATCH 2/2] kde: broken docs link --- modules/kde/hm.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/kde/hm.nix b/modules/kde/hm.nix index 245e18ed6..30fa122dc 100644 --- a/modules/kde/hm.nix +++ b/modules/kde/hm.nix @@ -249,7 +249,7 @@ let fi ''; - activateDocs = "https://stylix.danth.me/options/hm.html#stylixtargetskdesetter"; + activateDocs = "https://stylix.danth.me/options/hm.html#stylixtargetskdeservice"; in { options.stylix.targets.kde = { enable = config.lib.stylix.mkEnableTarget "KDE" true;