Skip to content

Commit

Permalink
gnome: fix Home Manager activation (#860)
Browse files Browse the repository at this point in the history
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: #860

Reviewed-by: NAHO <[email protected]>
  • Loading branch information
danth authored Feb 12, 2025
1 parent d8289c3 commit e86de61
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 15 deletions.
64 changes: 51 additions & 13 deletions modules/gnome/hm.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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='[email protected]'
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 =
Expand Down Expand Up @@ -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 [email protected]
gnome-extensions enable [email protected]
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
'';
};
};
Expand Down
4 changes: 2 additions & 2 deletions modules/kde/hm.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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
'';
};
Expand Down

0 comments on commit e86de61

Please sign in to comment.