Refactor theme module
Signed-off-by: Nikolaos Karaolidis <nick@karaolidis.com>
This commit is contained in:
@@ -1,12 +1,33 @@
|
||||
{
|
||||
config,
|
||||
inputs,
|
||||
lib,
|
||||
pkgs,
|
||||
...
|
||||
}:
|
||||
let
|
||||
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";
|
||||
runtimeInputs = with pkgs; [ coreutils ];
|
||||
bashOptions = [
|
||||
@@ -17,7 +38,7 @@ let
|
||||
CONFIG = cfg.configDir;
|
||||
DEFAULT_WALLPAPER = cfg.wallpaper;
|
||||
DEFAULT_MODE = cfg.mode;
|
||||
SWITCH = lib.meta.getExe (pkgs.writeShellScriptBin "themeExtraConfig" cfg.extraConfig);
|
||||
ACTIVATION = lib.meta.getExe activation;
|
||||
};
|
||||
text = builtins.readFile ./theme.sh;
|
||||
};
|
||||
@@ -43,7 +64,7 @@ in
|
||||
|
||||
pkg = mkOption {
|
||||
type = package;
|
||||
default = init;
|
||||
default = theme;
|
||||
readOnly = true;
|
||||
description = "The package containing the `theme` script";
|
||||
};
|
||||
@@ -51,7 +72,40 @@ in
|
||||
extraConfig = mkOption {
|
||||
type = lines;
|
||||
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 {
|
||||
@@ -112,7 +166,7 @@ in
|
||||
semantic = {
|
||||
blend = mkOption {
|
||||
type = bool;
|
||||
default = false;
|
||||
default = true;
|
||||
description = "Blend the colors.";
|
||||
};
|
||||
|
||||
@@ -364,8 +418,16 @@ in
|
||||
|
||||
config = lib.mkIf cfg.enable {
|
||||
home = {
|
||||
activation.themeInit = inputs.home-manager.lib.hm.dag.entryAfter [
|
||||
"writeBoundary"
|
||||
] "run ${lib.meta.getExe activation}";
|
||||
|
||||
packages =
|
||||
[ cfg.pkg ]
|
||||
with pkgs;
|
||||
[
|
||||
matugen
|
||||
theme
|
||||
]
|
||||
++ cfg.font.sansSerif.packages
|
||||
++ cfg.font.serif.packages
|
||||
++ cfg.font.monospace.packages
|
||||
@@ -389,5 +451,75 @@ in
|
||||
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;
|
||||
}
|
||||
);
|
||||
};
|
||||
}
|
||||
|
Reference in New Issue
Block a user