From e2bf634dcf61a638df59c2ae8b2045256cb81af0 Mon Sep 17 00:00:00 2001 From: wrvsrx Date: Thu, 16 Oct 2025 16:11:35 +0800 Subject: [PATCH] kde/hm: add plasmaWorkspacePackage option Link: https://github.com/nix-community/stylix/pull/1943 Reviewed-by: Ian Ressa Reviewed-by: NAHO <90870942+trueNAHO@users.noreply.github.com> --- modules/kde/hm.nix | 84 ++++++++++++++++++++++++++++++---------------- 1 file changed, 55 insertions(+), 29 deletions(-) diff --git a/modules/kde/hm.nix b/modules/kde/hm.nix index 164d2c52..ec5614bc 100644 --- a/modules/kde/hm.nix +++ b/modules/kde/hm.nix @@ -304,42 +304,56 @@ let # want to avoid installing these tools explicitly because that would pull # in large dependencies for people who aren't actually using KDE. # The workaround used is to assume a list of common paths where the tools - # might be installed, and look there. The ideal solution would require - # changes to KDE to make it possible to update the wallpaper through - # config files alone. + # might be installed, and look there. If people want to specify their + # plasma-workspace package rather than use the workaround, they can + # specify `plasmaWorkspacePackage` option explicitly. + # + # The ideal solution would require changes to KDE to make it possible to + # update the wallpaper through config files alone. activatorPackage = pkgs.writeShellApplication { name = "stylix-kde-apply-plasma-theme"; runtimeEnv = { inherit (config.home) username; }; text = - mergeWithImage - '' - get_exe() { - for directory in \ - /run/current-system/sw/bin \ - "/etc/profiles/per-user/$username/bin" \ - /usr/bin \ - /bin - do - if [[ -f "$directory/$1" ]]; then - printf '%s\n' "$directory/$1" - return 0 - fi - done - echo "Skipping '$1': command not found" - return 1 - } + if cfg.plasmaWorkspacePackage == null then + mergeWithImage + '' + get_exe() { + for directory in \ + /run/current-system/sw/bin \ + "/etc/profiles/per-user/$username/bin" \ + /usr/bin \ + /bin + do + if [[ -f "$directory/$1" ]]; then + printf '%s\n' "$directory/$1" + return 0 + fi + done + echo "Skipping '$1': command not found" + return 1 + } - if look_and_feel="$(get_exe plasma-apply-lookandfeel)"; then - "$look_and_feel" --apply "${Id}" || + if look_and_feel="$(get_exe plasma-apply-lookandfeel)"; then + "$look_and_feel" --apply "${Id}" || + echo "Failed plasma-apply-lookandfeel, ignoring error." + fi + '' + '' + if wallpaper_image="$(get_exe plasma-apply-wallpaperimage)"; then + "$wallpaper_image" "${themePackage}/share/wallpapers/${Id}" || + echo "Failed plasma-apply-wallpaperimage, ignoring error." + fi + '' + else + mergeWithImage + '' + ${lib.getExe' cfg.plasmaWorkspacePackage "plasma-apply-lookandfeel"} --apply "${Id}" || echo "Failed plasma-apply-lookandfeel, ignoring error." - fi - '' - '' - if wallpaper_image="$(get_exe plasma-apply-wallpaperimage)"; then - "$wallpaper_image" "${themePackage}/share/wallpapers/${Id}" || + '' + '' + ${lib.getExe' cfg.plasmaWorkspacePackage "plasma-apply-wallpaperimage"} "${themePackage}/share/wallpapers/${Id}" || echo "Failed plasma-apply-wallpaperimage, ignoring error." - fi - ''; + ''; runtimeEnv.QT_QPA_PLATFORM = "minimal"; }; activator = lib.getExe activatorPackage; @@ -391,6 +405,18 @@ in default = "default"; description = "The library for the application style."; }; + plasmaWorkspacePackage = lib.mkOption { + type = lib.types.nullOr lib.types.package; + default = null; + example = "pkgs.plasma-workspace"; + description = '' + If set to null, stylix will assume a series of possible KDE + installation paths and search for the `plasma-apply-lookandfeel` and + `plasma-apply-wallpaperimage` executables within them. Otherwise, it + will directly use these two executables from the specified package. + Setting this variable may introduce a large closure. + ''; + }; }; config =