Refactor theme management

Signed-off-by: Nikolaos Karaolidis <nick@karaolidis.com>
This commit is contained in:
2024-10-17 18:43:06 +01:00
parent ab042e03aa
commit d4b941f1fa
7 changed files with 25 additions and 17 deletions

View File

@@ -15,7 +15,7 @@
theme = { theme = {
template."${home}/.config/btop/themes/matugen.theme".source = ./theme.theme; template."${home}/.config/btop/themes/matugen.theme".source = ./theme.theme;
extraConfig = "${ reloadExtraConfig = "${
lib.meta.getExe ( lib.meta.getExe (
pkgs.writeShellApplication { pkgs.writeShellApplication {
name = "reload-btop"; name = "reload-btop";

View File

@@ -57,7 +57,7 @@ in
"${home}/.config/gtk-4.0/theme.css".source = ./theme.css; "${home}/.config/gtk-4.0/theme.css".source = ./theme.css;
}; };
theme.extraConfig = "${ theme.initExtraConfig = "${
lib.meta.getExe ( lib.meta.getExe (
pkgs.writeShellApplication { pkgs.writeShellApplication {
name = "theme-gtk"; name = "theme-gtk";

View File

@@ -140,7 +140,7 @@
theme = { theme = {
template."${home}/.config/hypr/theme.conf".source = ./theme.conf; template."${home}/.config/hypr/theme.conf".source = ./theme.conf;
extraConfig = "${ reloadExtraConfig = "${
lib.meta.getExe ( lib.meta.getExe (
pkgs.writeShellApplication { pkgs.writeShellApplication {
name = "reload-hyprland"; name = "reload-hyprland";

View File

@@ -33,7 +33,7 @@ in
theme = { theme = {
template."${home}/.config/kitty/theme.conf".source = ./theme.conf; template."${home}/.config/kitty/theme.conf".source = ./theme.conf;
extraConfig = "${ reloadExtraConfig = "${
lib.meta.getExe ( lib.meta.getExe (
pkgs.writeShellApplication { pkgs.writeShellApplication {
name = "reload-kitty"; name = "reload-kitty";

View File

@@ -63,6 +63,6 @@ in
Install.WantedBy = [ "graphical-session.target" ]; Install.WantedBy = [ "graphical-session.target" ];
}; };
theme.extraConfig = lib.mkAfter "${themeSwww} &"; theme.reloadExtraConfig = "${themeSwww} &";
}; };
} }

View File

@@ -8,25 +8,24 @@
let let
cfg = config.theme; cfg = config.theme;
activation = pkgs.writeShellApplication { init = pkgs.writeShellApplication {
name = "theme-init"; name = "theme-init";
runtimeInputs = with pkgs; [ matugen ]; runtimeInputs = with pkgs; [ matugen ];
bashOptions = [
"errexit"
"pipefail"
];
text = '' text = ''
matugen image "${cfg.configDir}/wallpaper" \ matugen image "${cfg.configDir}/wallpaper" \
--type scheme-${cfg.flavour} \ --type scheme-${cfg.flavour} \
--mode "$(cat "${cfg.configDir}/mode")" \ --mode "$(cat "${cfg.configDir}/mode")" \
--contrast ${builtins.toString cfg.contrast} --contrast ${builtins.toString cfg.contrast}
[ -z "$DISPLAY" ] && [ -z "$WAYLAND_DISPLAY" ] && exit 0 ${cfg.initExtraConfig}
${cfg.extraConfig}
''; '';
}; };
reload = pkgs.writeShellApplication {
name = "theme-reload";
text = cfg.reloadExtraConfig;
};
theme = pkgs.writeShellApplication { theme = pkgs.writeShellApplication {
name = "theme"; name = "theme";
runtimeInputs = with pkgs; [ coreutils ]; runtimeInputs = with pkgs; [ coreutils ];
@@ -34,7 +33,8 @@ let
CONFIG = cfg.configDir; CONFIG = cfg.configDir;
DEFAULT_WALLPAPER = cfg.wallpaper; DEFAULT_WALLPAPER = cfg.wallpaper;
DEFAULT_MODE = cfg.mode; DEFAULT_MODE = cfg.mode;
ACTIVATION = lib.meta.getExe activation; INIT = lib.meta.getExe init;
RELOAD = lib.meta.getExe reload;
}; };
text = builtins.readFile ./theme.sh; text = builtins.readFile ./theme.sh;
}; };
@@ -65,7 +65,13 @@ in
description = "The package containing the `theme` script"; description = "The package containing the `theme` script";
}; };
extraConfig = mkOption { initExtraConfig = mkOption {
type = lines;
default = "";
description = "Extra configuration lines to add to the theme initialization script.";
};
reloadExtraConfig = mkOption {
type = lines; type = lines;
default = ""; default = "";
description = "Extra configuration lines to add to the theme reload script."; description = "Extra configuration lines to add to the theme reload script.";
@@ -416,7 +422,8 @@ in
home = { home = {
activation.themeInit = inputs.home-manager.lib.hm.dag.entryAfter [ activation.themeInit = inputs.home-manager.lib.hm.dag.entryAfter [
"writeBoundary" "writeBoundary"
] "run ${lib.meta.getExe activation}"; "dconfSettings"
] "run ${lib.meta.getExe init}";
packages = packages =
with pkgs; with pkgs;

View File

@@ -38,7 +38,8 @@ finish() {
[[ -n "${WALLPAPER}" ]] && ln -sf "${WALLPAPER}" "${CONFIG}"/wallpaper [[ -n "${WALLPAPER}" ]] && ln -sf "${WALLPAPER}" "${CONFIG}"/wallpaper
[[ -n "${MODE}" ]] && echo "${MODE}" > "${CONFIG}"/mode [[ -n "${MODE}" ]] && echo "${MODE}" > "${CONFIG}"/mode
"${ACTIVATION}" > /dev/null "${INIT}" > /dev/null
"${RELOAD}" > /dev/null
} }
if [[ $# -eq 0 ]]; then if [[ $# -eq 0 ]]; then