Support per user themes for GNOME shell

This commit is contained in:
Daniel Thwaites 2023-02-01 12:06:03 +00:00
parent 02f0297038
commit ba324393e9
No known key found for this signature in database
GPG key ID: D8AFC4BF05670F9D
3 changed files with 52 additions and 10 deletions

View file

@ -22,6 +22,18 @@ with lib;
if config.stylix.polarity == "dark"
then "prefer-dark"
else "default";
"org/gnome/shell/extensions/user-theme".name = "Stylix";
};
xdg.dataFile."themes/Stylix/gnome-shell/gnome-shell.css" = {
source =
let theme = import ./theme.nix { inherit pkgs config; };
in "${theme}/share/gnome-shell/gnome-shell.css";
onChange = ''
gnome-extensions disable user-theme@gnome-shell-extensions.gcampax.github.com
gnome-extensions enable user-theme@gnome-shell-extensions.gcampax.github.com
'';
};
};
}

View file

@ -17,17 +17,13 @@ with lib;
nixpkgs.overlays = [(self: super: {
gnome = super.gnome.overrideScope' (gnomeSelf: gnomeSuper: {
gnome-shell = gnomeSuper.gnome-shell.overrideAttrs (oldAttrs: {
postPatch = let
colors = config.lib.stylix.colors {
template = builtins.readFile ./colors.mustache;
extension = "scss";
};
in (oldAttrs.postPatch or "") + ''
rm data/theme/gnome-shell-sass/{_colors.scss,_palette.scss}
cp ${colors} data/theme/gnome-shell-sass/_colors.scss
'';
postFixup =
let theme = import ./theme.nix { inherit pkgs config; };
in ''
cp ${theme}/share/gnome-shell/gnome-shell-theme.gresource \
$out/share/gnome-shell/gnome-shell-theme.gresource
'';
patches = (oldAttrs.patches or []) ++ [
./shell_colors.patch
./shell_remove_dark_mode.patch
];
});

34
modules/gnome/theme.nix Normal file
View file

@ -0,0 +1,34 @@
{ pkgs, config }:
let
colors = config.lib.stylix.colors {
template = builtins.readFile ./colors.mustache;
extension = "scss";
};
in pkgs.stdenv.mkDerivation {
name = "stylix-gnome-shell-theme";
src = pkgs.fetchurl {
url = "mirror://gnome/sources/gnome-shell/43/gnome-shell-43.2.tar.xz";
sha256 = "52/UvpNCQQ7p+9zday2Bxv8GDnyMxaDxyuanq6JdGGA=";
};
patches = [ ./shell_colors.patch ];
postPatch = ''
rm data/theme/gnome-shell-sass/{_colors.scss,_palette.scss}
cp ${colors} data/theme/gnome-shell-sass/_colors.scss
'';
nativeBuildInputs = with pkgs; [ sass glib.dev ];
buildPhase = ''
sass data/theme/gnome-shell.scss >data/theme/gnome-shell.css
glib-compile-resources --sourcedir=data/theme data/gnome-shell-theme.gresource.xml
'';
installPhase = ''
mkdir -p $out/share/gnome-shell
mv data/theme/gnome-shell.css $out/share/gnome-shell/gnome-shell.css
mv data/gnome-shell-theme.gresource $out/share/gnome-shell/gnome-shell-theme.gresource
'';
}