diff --git a/modules/gnome/hm.nix b/modules/gnome/hm.nix index ac50b075..d57458ae 100644 --- a/modules/gnome/hm.nix +++ b/modules/gnome/hm.nix @@ -10,6 +10,36 @@ let fontSize = toString config.stylix.fonts.sizes.applications; documentFontSize = toString (config.stylix.fonts.sizes.applications - 1); + activator = pkgs.writeShellApplication { + name = "stylix-activate-gnome"; + text = '' + get_exe() { + 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 + echo "Skipping '$1': command not found" + return 1 + } + + if gnome_extensions="$(get_exe gnome-extensions)"; then + extension='user-theme@gnome-shell-extensions.gcampax.github.com' + + case "$1" in + reload) + "$gnome_extensions" disable "$extension" + "$gnome_extensions" enable "$extension" + ;; + enable) + "$gnome_extensions" enable "$extension" + ;; + esac + fi + ''; + }; + in { options.stylix.targets.gnome.enable = @@ -55,19 +85,27 @@ in "org/gnome/shell/extensions/user-theme".name = "Stylix"; }; - xdg.dataFile."themes/Stylix/gnome-shell/gnome-shell.css" = { - source = - let - theme = pkgs.callPackage ./theme.nix { - inherit (config.lib.stylix) colors templates; - }; - in - "${theme}/share/gnome-shell/gnome-shell.css"; - onChange = '' - if [[ -x "$(command -v gnome-extensions)" ]]; then - gnome-extensions disable user-theme@gnome-shell-extensions.gcampax.github.com - gnome-extensions enable user-theme@gnome-shell-extensions.gcampax.github.com - fi + xdg = { + dataFile."themes/Stylix/gnome-shell/gnome-shell.css" = { + source = + let + theme = pkgs.callPackage ./theme.nix { + inherit (config.lib.stylix) colors templates; + }; + in + "${theme}/share/gnome-shell/gnome-shell.css"; + + # Reload the extension so the new theme is applied immediately. + # (The extension doesn't watch the file for changes.) + onChange = "${lib.getExe activator} reload"; + }; + + # Enable the extension after logging in. + configFile."autostart/stylix-activate-gnome.desktop".text = '' + [Desktop Entry] + Type=Application + Exec=${lib.getExe activator} enable + Name=Stylix: enable User Themes extension for GNOME Shell ''; }; }; diff --git a/modules/kde/hm.nix b/modules/kde/hm.nix index e3ada941..ebeeb3ec 100644 --- a/modules/kde/hm.nix +++ b/modules/kde/hm.nix @@ -372,11 +372,11 @@ in # This desktop entry will run the theme activator when a new Plasma session is started # Note: This doesn't run again if a new homeConfiguration is activated from a running Plasma session - configFile."autostart/stylix-activator.desktop".text = '' + configFile."autostart/stylix-activate-kde.desktop".text = '' [Desktop Entry] Type=Application Exec=${activator} - Name=Stylix Activator + Name=Stylix: activate KDE theme X-KDE-AutostartScript=true ''; };