Add extraCss option for GTK

This commit is contained in:
Daniel Thwaites 2023-03-07 11:22:50 +00:00
parent dd7fc590c3
commit 6d3a046d17
No known key found for this signature in database
GPG key ID: D8AFC4BF05670F9D

View file

@ -1,16 +1,40 @@
{ pkgs, config, lib, ... }:
with lib;
let
css = config.lib.stylix.colors {
cfg = config.stylix.targets.gtk;
baseCss = config.lib.stylix.colors {
template = builtins.readFile ./gtk.mustache;
extension = "css";
};
in {
options.stylix.targets.gtk.enable =
config.lib.stylix.mkEnableTarget "all GTK3, GTK4 and Libadwaita apps" true;
config = lib.mkIf config.stylix.targets.gtk.enable {
finalCss = pkgs.runCommandLocal "gtk.css" {} ''
echo ${escapeShellArg cfg.extraCss} >>$out
cat ${baseCss} >>$out
'';
in {
options.stylix.targets.gtk = {
enable = config.lib.stylix.mkEnableTarget
"all GTK3, GTK4 and Libadwaita apps" true;
extraCss = mkOption {
description = ''
Extra code added to <literal>gtk-3.0/gtk.css</literal>
and <literal>gtk-4.0/gtk.css</literal>.
'';
type = types.lines;
default = "";
example = ''
// Remove rounded corners
window.background { border-radius: 0; }
'';
};
};
config = lib.mkIf cfg.enable {
# programs.dconf.enable = true; required in system config
gtk = {
enable = true;
@ -22,8 +46,8 @@ in {
};
xdg.configFile = {
"gtk-3.0/gtk.css".source = css;
"gtk-4.0/gtk.css".source = css;
"gtk-3.0/gtk.css".source = finalCss;
"gtk-4.0/gtk.css".source = finalCss;
};
};
}