gnome: fix Home Manager activation (#860)

This suffers from the same issues as the KDE activation:

- The program is not available in $PATH, but should not be installed for
  all users.

- The program only works when GNOME Shell is running.

Therefore, we use a very similar solution.

Link: https://github.com/danth/stylix/pull/860

Reviewed-by: NAHO <90870942+trueNAHO@users.noreply.github.com>
This commit is contained in:
Daniel Thwaites 2025-02-12 15:43:34 +00:00 committed by GitHub
parent d8289c3f0e
commit e86de61bb8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 53 additions and 15 deletions

View file

@ -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
'';
};
};

View file

@ -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
'';
};