Refactor theme module

Signed-off-by: Nikolaos Karaolidis <nick@karaolidis.com>
This commit is contained in:
2024-07-27 16:23:32 +01:00
parent 4c04dda643
commit 922eb479a0
13 changed files with 871 additions and 903 deletions

View File

@@ -23,10 +23,7 @@ in
target = "ags/config.js"; target = "ags/config.js";
}; };
programs.matugen.settings.templates.ags = { theme.templates."${hmConfig.xdg.configHome}/ags/theme.sass".source = ./theme.sass;
input_path = ./theme.sass;
output_path = "${hmConfig.xdg.configHome}/ags/theme.sass";
};
systemd.user = { systemd.user = {
targets.tray.Unit = { targets.tray.Unit = {

View File

@@ -12,23 +12,20 @@ let
in in
{ {
home-manager.users.${username} = { home-manager.users.${username} = {
programs = { programs.btop.settings.color_theme = "matugen";
btop.settings.color_theme = "matugen";
matugen.settings.templates.btop = { theme = {
input_path = ./theme.theme; templates."${hmConfig.xdg.configHome}/btop/themes/matugen.theme".source = ./theme.theme;
output_path = "${hmConfig.xdg.configHome}/btop/themes/matugen.theme";
}; extraConfig = "${
lib.meta.getExe (
pkgs.writeShellApplication {
name = "reload-btop";
runtimeInputs = with pkgs; [ procps ];
text = "exec pkill btop -SIGUSR2";
}
)
} &";
}; };
theme.extraConfig = "${
lib.meta.getExe (
pkgs.writeShellApplication {
name = "reload-btop";
runtimeInputs = with pkgs; [ procps ];
text = "exec pkill btop -SIGUSR2";
}
)
} &";
}; };
} }

View File

@@ -51,15 +51,9 @@ in
); );
}; };
programs.matugen.settings.templates = { theme.templates = {
gtk3 = { "${hmConfig.xdg.configHome}/gtk-3.0/theme.css".source = ./theme.css;
input_path = ./theme.css; "${hmConfig.xdg.configHome}/gtk-4.0/theme.css".source = ./theme.css;
output_path = "${hmConfig.xdg.configHome}/gtk-3.0/theme.css";
};
gtk4 = {
input_path = ./theme.css;
output_path = "${hmConfig.xdg.configHome}/gtk-4.0/theme.css";
};
}; };
theme.extraConfig = "${ theme.extraConfig = "${

View File

@@ -131,29 +131,26 @@ in
extraConfig = "source = ./theme.conf"; extraConfig = "source = ./theme.conf";
}; };
programs = { programs.zsh.loginExtra = lib.mkAfter ''
zsh.loginExtra = lib.mkAfter '' if [ -z "$WAYLAND_DISPLAY" ] && [ -n "$XDG_VTNR" ] && [ "$XDG_VTNR" -eq 1 ]; then
if [ -z "$WAYLAND_DISPLAY" ] && [ -n "$XDG_VTNR" ] && [ "$XDG_VTNR" -eq 1 ]; then hyprland &> /tmp/hyprland.log
hyprland &> /tmp/hyprland.log fi
fi '';
'';
matugen.settings.templates.hyprland = { theme = {
input_path = ./theme.conf; templates."${hmConfig.xdg.configHome}/hypr/theme.conf".source = ./theme.conf;
output_path = "${hmConfig.xdg.configHome}/hypr/theme.conf";
}; extraConfig = "${
lib.meta.getExe (
pkgs.writeShellApplication {
name = "reload-hyprland";
runtimeInputs = with pkgs; [ hyprland ];
text = "exec hyprctl reload";
}
)
} &";
}; };
theme.extraConfig = "${
lib.meta.getExe (
pkgs.writeShellApplication {
name = "reload-hyprland";
runtimeInputs = with pkgs; [ hyprland ];
text = "exec hyprctl reload";
}
)
} &";
home.sessionVariables.NIXOS_OZONE_WL = "1"; home.sessionVariables.NIXOS_OZONE_WL = "1";
}; };
} }

View File

@@ -13,37 +13,34 @@ let
in in
{ {
home-manager.users.${username} = { home-manager.users.${username} = {
programs = { programs.kitty = {
kitty = { enable = true;
enable = true;
font = { font = {
name = builtins.head hmConfig.theme.font.monospace.names; name = builtins.head hmConfig.theme.font.monospace.names;
package = builtins.head hmConfig.theme.font.monospace.packages; package = builtins.head hmConfig.theme.font.monospace.packages;
inherit (hmConfig.theme.font) size; inherit (hmConfig.theme.font) size;
};
extraConfig = ''
confirm_os_window_close 0
include theme.conf
'';
}; };
matugen.settings.templates.kitty = { extraConfig = ''
input_path = ./theme.conf; confirm_os_window_close 0
output_path = "${hmConfig.xdg.configHome}/kitty/theme.conf"; include theme.conf
}; '';
}; };
theme.extraConfig = "${ theme = {
lib.meta.getExe ( templates."${hmConfig.xdg.configHome}/kitty/theme.conf".source = ./theme.conf;
pkgs.writeShellApplication {
name = "reload-kitty"; extraConfig = "${
runtimeInputs = with pkgs; [ procps ]; lib.meta.getExe (
text = "exec pkill kitty -SIGUSR1"; pkgs.writeShellApplication {
} name = "reload-kitty";
) runtimeInputs = with pkgs; [ procps ];
} &"; text = "exec pkill kitty -SIGUSR1";
}
)
} &";
};
home.persistence."/cache${userConfig.home}".directories = [ home.persistence."/cache${userConfig.home}".directories = [
"${hmConfig.xdg.relativeCacheHome}/kitty" "${hmConfig.xdg.relativeCacheHome}/kitty"

View File

@@ -1,100 +0,0 @@
{
username ? throw "username argument is required",
}:
{
config,
lib,
pkgs,
...
}:
let
hmConfig = config.home-manager.users.${username};
in
{
home-manager.users.${username} = {
imports = [ ./options.nix ];
programs.matugen = {
enable = true;
settings = {
config = {
custom_colors =
let
mkColor = category: color: {
color = hmConfig.theme.color.${category}.${color};
blend = hmConfig.theme.color.${category}.blend;
};
in
{
danger = mkColor "semantic" "danger";
warning = mkColor "semantic" "warning";
success = mkColor "semantic" "success";
info = mkColor "semantic" "info";
red = mkColor "basic" "red";
orange = mkColor "basic" "orange";
yellow = mkColor "basic" "yellow";
green = mkColor "basic" "green";
cyan = mkColor "basic" "cyan";
blue = mkColor "basic" "blue";
magenta = mkColor "basic" "magenta";
pink = mkColor "basic" "magenta";
keywords = mkColor "syntax" "keywords";
functions = mkColor "syntax" "functions";
properties = mkColor "syntax" "properties";
constants = mkColor "syntax" "constants";
strings = mkColor "syntax" "strings";
numbers = mkColor "syntax" "numbers";
structures = mkColor "syntax" "structures";
types = mkColor "syntax" "types";
};
custom_keywords =
let
zeroPad = hex: if builtins.stringLength hex == 1 then "0${hex}" else hex;
percentageToHex = percentage: zeroPad (lib.trivial.toHexString (builtins.floor (percentage * 255)));
in
{
flavour = hmConfig.theme.flavour;
contrast = builtins.toString hmConfig.theme.contrast;
radius = builtins.toString hmConfig.theme.radius;
padding = builtins.toString hmConfig.theme.padding;
padding_double = builtins.toString (hmConfig.theme.padding * 2);
blur = builtins.toString hmConfig.theme.blur;
opacity = builtins.toString hmConfig.theme.opacity;
opacity_hex = builtins.toString (percentageToHex hmConfig.theme.opacity);
opacity_shadow = builtins.toString (hmConfig.theme.opacity * 0.75);
opacity_shadow_hex = builtins.toString (percentageToHex (hmConfig.theme.opacity * 0.75));
font_size = builtins.toString hmConfig.theme.font.size;
font_sans_serif = builtins.head hmConfig.theme.font.sansSerif.names;
font_sans_serif_all = builtins.concatStringsSep ", " hmConfig.theme.font.sansSerif.names;
font_serif = builtins.head hmConfig.theme.font.serif.names;
font_serif_all = builtins.concatStringsSep ", " hmConfig.theme.font.serif.names;
font_monospace = builtins.head hmConfig.theme.font.monospace.names;
font_monospace_all = builtins.concatStringsSep ", " hmConfig.theme.font.monospace.names;
font_emoji = builtins.head hmConfig.theme.font.emoji.names;
font_emoji_all = builtins.concatStringsSep ", " hmConfig.theme.font.emoji.names;
};
};
templates = { };
};
};
theme.extraConfig = lib.mkBefore (
lib.meta.getExe (
pkgs.writeShellApplication {
name = "theme-matugen";
runtimeInputs = with pkgs; [ matugen ];
text = ''
exec matugen image "${hmConfig.theme.configDir}/wallpaper" \
--type scheme-${hmConfig.theme.flavour} \
--mode "$(cat "${hmConfig.theme.configDir}/mode")" \
--contrast ${builtins.toString hmConfig.theme.contrast}
'';
}
)
);
};
}

View File

@@ -1,30 +0,0 @@
{
config,
pkgs,
lib,
...
}:
let
cfg = config.programs.matugen;
in
{
# https://github.com/Theaninova/matugen/blob/add-home-manager-module/hm-module.nix
options.programs.matugen =
with lib;
with types;
{
enable = mkEnableOption "matugen";
package = mkPackageOption pkgs "matugen" { };
settings = mkOption {
type = attrsOf anything;
description = "Settings to write to config.toml.";
};
};
config = lib.mkIf cfg.enable {
home.packages = [ cfg.package ];
xdg.configFile."matugen/config.toml".source = lib.mkIf (cfg.settings != null) (
(pkgs.formats.toml { }).generate "matugen" cfg.settings
);
};
}

File diff suppressed because it is too large Load Diff

View File

@@ -26,17 +26,11 @@ in
QT_QPA_PLATFORMTHEME = "qt5ct"; QT_QPA_PLATFORMTHEME = "qt5ct";
}; };
programs.matugen.settings.templates = { theme.templates = {
# https://github.com/GabePoel/KvLibadwaita/blob/main/src/KvLibadwaita/KvLibadwaita.kvconfig # https://github.com/GabePoel/KvLibadwaita/blob/main/src/KvLibadwaita/KvLibadwaita.kvconfig
kvantumConfig = { "${hmConfig.xdg.configHome}/Kvantum/KvAdwQt/KvAdwQt.kvconfig".source = ./KvAdwQt/KvAdwQt.kvconfig;
input_path = ./KvAdwQt/KvAdwQt.kvconfig;
output_path = "${hmConfig.xdg.configHome}/Kvantum/KvAdwQt/KvAdwQt.kvconfig";
};
# https://github.com/GabePoel/KvLibadwaita/blob/main/src/KvLibadwaita/KvLibadwaita.svg # https://github.com/GabePoel/KvLibadwaita/blob/main/src/KvLibadwaita/KvLibadwaita.svg
kvantumSvg = { "${hmConfig.xdg.configHome}/Kvantum/KvAdwQt/KvAdwQt.svg".source = ./KvAdwQt/KvAdwQt.svg;
input_path = ./KvAdwQt/KvAdwQt.svg;
output_path = "${hmConfig.xdg.configHome}/Kvantum/KvAdwQt/KvAdwQt.svg";
};
}; };
xdg.configFile = xdg.configFile =

View File

@@ -24,13 +24,8 @@ in
"Ctrl_Alt, t, exec, ${themeBin} toggle" "Ctrl_Alt, t, exec, ${themeBin} toggle"
]; ];
home = { home.persistence."/persist${userConfig.home}".directories = [
activation.themeInit = inputs.home-manager.lib.hm.dag.entryAfter [ "${hmConfig.xdg.relativeConfigHome}/theme"
"writeBoundary" ];
] "run ${themeBin}";
persistence."/persist${userConfig.home}".directories = [
"${hmConfig.xdg.relativeConfigHome}/theme"
];
};
}; };
} }

View File

@@ -1,12 +1,33 @@
{ {
config, config,
inputs,
lib, lib,
pkgs, pkgs,
... ...
}: }:
let let
cfg = config.theme; cfg = config.theme;
init = pkgs.writeShellApplication {
activation = pkgs.writeShellApplication {
name = "theme-init";
runtimeInputs = with pkgs; [ matugen ];
bashOptions = [
"nounset"
"pipefail"
];
text = ''
matugen image "${cfg.configDir}/wallpaper" \
--type scheme-${cfg.flavour} \
--mode "$(cat "${cfg.configDir}/mode")" \
--contrast ${builtins.toString cfg.contrast}
[ -z "$DISPLAY" ] && [ -z "$WAYLAND_DISPLAY" ] && exit 0
${cfg.extraConfig}
'';
};
theme = pkgs.writeShellApplication {
name = "theme"; name = "theme";
runtimeInputs = with pkgs; [ coreutils ]; runtimeInputs = with pkgs; [ coreutils ];
bashOptions = [ bashOptions = [
@@ -17,7 +38,7 @@ let
CONFIG = cfg.configDir; CONFIG = cfg.configDir;
DEFAULT_WALLPAPER = cfg.wallpaper; DEFAULT_WALLPAPER = cfg.wallpaper;
DEFAULT_MODE = cfg.mode; DEFAULT_MODE = cfg.mode;
SWITCH = lib.meta.getExe (pkgs.writeShellScriptBin "themeExtraConfig" cfg.extraConfig); ACTIVATION = lib.meta.getExe activation;
}; };
text = builtins.readFile ./theme.sh; text = builtins.readFile ./theme.sh;
}; };
@@ -43,7 +64,7 @@ in
pkg = mkOption { pkg = mkOption {
type = package; type = package;
default = init; default = theme;
readOnly = true; readOnly = true;
description = "The package containing the `theme` script"; description = "The package containing the `theme` script";
}; };
@@ -51,7 +72,40 @@ in
extraConfig = mkOption { extraConfig = mkOption {
type = lines; type = lines;
default = ""; default = "";
description = "Extra configuration lines to add to the theme script."; description = "Extra configuration lines to add to the theme reload script.";
};
templates = mkOption {
type = attrsOf (
submodule (
{ name, config, ... }:
{
options = {
source = mkOption {
type = nullOr path;
description = "Path of the source file or directory.";
default = null;
};
text = mkOption {
type = nullOr str;
description = "Text of the file.";
default = null;
};
target = mkOption {
type = str;
defaultText = literalExpression "name";
description = "Path to target relative to the user's {env}`HOME`.";
};
};
config.target = mkDefault name;
}
)
);
default = { };
description = "Templates to fill with theme colors.";
}; };
flavour = mkOption { flavour = mkOption {
@@ -112,7 +166,7 @@ in
semantic = { semantic = {
blend = mkOption { blend = mkOption {
type = bool; type = bool;
default = false; default = true;
description = "Blend the colors."; description = "Blend the colors.";
}; };
@@ -364,8 +418,16 @@ in
config = lib.mkIf cfg.enable { config = lib.mkIf cfg.enable {
home = { home = {
activation.themeInit = inputs.home-manager.lib.hm.dag.entryAfter [
"writeBoundary"
] "run ${lib.meta.getExe activation}";
packages = packages =
[ cfg.pkg ] with pkgs;
[
matugen
theme
]
++ cfg.font.sansSerif.packages ++ cfg.font.sansSerif.packages
++ cfg.font.serif.packages ++ cfg.font.serif.packages
++ cfg.font.monospace.packages ++ cfg.font.monospace.packages
@@ -389,5 +451,75 @@ in
emoji = cfg.font.emoji.names; emoji = cfg.font.emoji.names;
}; };
}; };
xdg.configFile."matugen/config.toml".source = (
(pkgs.formats.toml { }).generate "matugen" {
config = {
custom_colors =
let
mkColor = category: color: {
color = cfg.color.${category}.${color};
blend = cfg.color.${category}.blend;
};
in
{
danger = mkColor "semantic" "danger";
warning = mkColor "semantic" "warning";
success = mkColor "semantic" "success";
info = mkColor "semantic" "info";
red = mkColor "basic" "red";
orange = mkColor "basic" "orange";
yellow = mkColor "basic" "yellow";
green = mkColor "basic" "green";
cyan = mkColor "basic" "cyan";
blue = mkColor "basic" "blue";
magenta = mkColor "basic" "magenta";
pink = mkColor "basic" "pink";
keywords = mkColor "syntax" "keywords";
functions = mkColor "syntax" "functions";
properties = mkColor "syntax" "properties";
constants = mkColor "syntax" "constants";
strings = mkColor "syntax" "strings";
numbers = mkColor "syntax" "numbers";
structures = mkColor "syntax" "structures";
types = mkColor "syntax" "types";
};
custom_keywords =
let
zeroPad = hex: if builtins.stringLength hex == 1 then "0${hex}" else hex;
percentageToHex = percentage: zeroPad (lib.trivial.toHexString (builtins.floor (percentage * 255)));
in
{
flavour = cfg.flavour;
contrast = builtins.toString cfg.contrast;
radius = builtins.toString cfg.radius;
padding = builtins.toString cfg.padding;
padding_double = builtins.toString (cfg.padding * 2);
blur = builtins.toString cfg.blur;
opacity = builtins.toString cfg.opacity;
opacity_hex = builtins.toString (percentageToHex cfg.opacity);
opacity_shadow = builtins.toString (cfg.opacity * 0.75);
opacity_shadow_hex = builtins.toString (percentageToHex (cfg.opacity * 0.75));
font_size = builtins.toString cfg.font.size;
font_sans_serif = builtins.head cfg.font.sansSerif.names;
font_sans_serif_all = builtins.concatStringsSep ", " cfg.font.sansSerif.names;
font_serif = builtins.head cfg.font.serif.names;
font_serif_all = builtins.concatStringsSep ", " cfg.font.serif.names;
font_monospace = builtins.head cfg.font.monospace.names;
font_monospace_all = builtins.concatStringsSep ", " cfg.font.monospace.names;
font_emoji = builtins.head cfg.font.emoji.names;
font_emoji_all = builtins.concatStringsSep ", " cfg.font.emoji.names;
};
};
templates = builtins.mapAttrs (name: template: {
input_path = template.source or (pkgs.writeText name template.text);
output_path = template.target;
}) cfg.templates;
}
);
}; };
} }

View File

@@ -1,6 +1,9 @@
[ ! -L "$CONFIG"/wallpaper ] && ln -sf "$DEFAULT_WALLPAPER" "$CONFIG"/wallpaper [ ! -L "$CONFIG"/wallpaper ] && ln -sf "$DEFAULT_WALLPAPER" "$CONFIG"/wallpaper
[ ! -f "$CONFIG"/mode ] && echo "$DEFAULT_MODE" > "$CONFIG"/mode [ ! -f "$CONFIG"/mode ] && echo "$DEFAULT_MODE" > "$CONFIG"/mode
WALLPAPER=""
MODE=""
set_wallpaper() { set_wallpaper() {
if [ -f "$1" ]; then if [ -f "$1" ]; then
WALLPAPER="$1" WALLPAPER="$1"
@@ -35,14 +38,9 @@ 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
"$SWITCH"
} > /dev/null
} }
WALLPAPER=""
MODE=""
if [ $# -eq 0 ]; then if [ $# -eq 0 ]; then
finish finish
else else

View File

@@ -36,7 +36,6 @@ in
(import ../common/user/configs/gui/hyprland { inherit username; }) (import ../common/user/configs/gui/hyprland { inherit username; })
(import ../common/user/configs/gui/hyprshot { inherit username; }) (import ../common/user/configs/gui/hyprshot { inherit username; })
(import ../common/user/configs/gui/kitty { inherit username; }) (import ../common/user/configs/gui/kitty { inherit username; })
(import ../common/user/configs/gui/matugen { inherit username; })
(import ../common/user/configs/gui/networking { inherit username; }) (import ../common/user/configs/gui/networking { inherit username; })
(import ../common/user/configs/gui/obsidian { inherit username; }) (import ../common/user/configs/gui/obsidian { inherit username; })
(import ../common/user/configs/gui/pipewire { inherit username; }) (import ../common/user/configs/gui/pipewire { inherit username; })