From ac8e82769ec50f0c73eedca1f49b674a686c2acf Mon Sep 17 00:00:00 2001 From: Talia-12 Date: Tue, 27 Aug 2024 11:14:28 +1000 Subject: [PATCH 1/4] add custom colors option to nix module. --- module.nix | 57 ++++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 49 insertions(+), 8 deletions(-) diff --git a/module.nix b/module.nix index d00d2df..1fba9b0 100644 --- a/module.nix +++ b/module.nix @@ -8,6 +8,17 @@ matugen: { cfg = config.programs.matugen; osCfg = args.osConfig.programs.matugen or {}; + hexColor = lib.types.strMatching "#([0-9a-fA-F]{3}){1,2}"; + hexStrippedColor = lib.types.strMatching "([0-9a-fA-F]{3}){1,2}"; + rgbColor = lib.types.strMatching "rgb\(\d{1,3}, ?\d{1,3}, ?\d{1,3}\)"; + rgbaColor = lib.types.strMatching "rgba\(\d{1,3}, ?\d{1,3}, ?\d{1,3}, ?\d{1,3}\)"; + hslColor = lib.types.strMatching "hsl\(\d{1,3}, ?\d{1,3}%, ?\d{1,3}%\)"; + hslaColor = lib.types.strMatching "hsla\(\d{1,3}, ?\d{1,3}%, ?\d{1,3}%, ?[0,1](\.\d*)\)"; + + # Only hexColor is currently supported for custom_colors. + colorType = hexColor; + # colorType = lib.types.oneOf [hexColor hexStrippedColor rgbColor rgbaColor hslColor hslaColor]; + configFormat = pkgs.formats.toml {}; capitalize = str: let @@ -27,7 +38,9 @@ matugen: { cfg.templates; matugenConfig = configFormat.generate "matugen-config.toml" { - config = {}; + config = { + custom_colors = cfg.custom_colors; + }; templates = sanitizedTemplates; }; @@ -41,18 +54,14 @@ matugen: { ${cfg.package}/bin/matugen \ image ${cfg.wallpaper} \ - ${ - if cfg.templates != {} - then "--config ${matugenConfig}" - else "" - } \ + --config ${matugenConfig} \ --mode ${cfg.variant} \ --type ${cfg.type} \ --json ${cfg.jsonFormat} \ --quiet \ > $out/theme.json ''; - colors = builtins.fromJSON (builtins.readFile "${themePackage}/theme.json"); + colors = (builtins.fromJSON (builtins.readFile "${themePackage}/theme.json")).colors; in { options.programs.matugen = { enable = lib.mkEnableOption "Matugen declarative theming"; @@ -95,11 +104,43 @@ in { ''; }; + custom_colors = lib.mkOption { + description = "Other colors that should be included in the colorsheme."; + type = with lib.types; + attrsOf (submodule { + options = { + color = lib.mkOption { + description = "Color value for this custom color."; + type = colorType; + example = "#d03e3e"; + }; + blend = lib.mkOption { + description = "Whether to pick a color close to the given value, or to pass the value through to the final colorscheme unchanged."; + type = bool; + default = true; + }; + }; + }); + default = osCfg.custom_colors or {}; + example = '' + { + light-red.color = "#d03e3e"; + light-orange.color = "#d7691d"; + light-yellow.color = "#ad8200"; + + red = { + color = "#ff0000"; + blend = false; + }; + } + ''; + }; + type = lib.mkOption { description = "Palette used when generating the colorschemes."; type = lib.types.enum ["scheme-content" "scheme-expressive" "scheme-fidelity" "scheme-fruit-salad" "scheme-monochrome" "scheme-neutral" "scheme-rainbow" "scheme-tonal-spot"]; default = osCfg.palette or "scheme-tonal-spot"; - example = "triadic"; + example = "scheme-content"; }; jsonFormat = lib.mkOption { From 7df197c7b917c897fab4339c4804c95f296dd260 Mon Sep 17 00:00:00 2001 From: Talia-12 Date: Tue, 27 Aug 2024 15:12:18 +1000 Subject: [PATCH 2/4] add backup config option to add in anything that isn't explicitly supported --- module.nix | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/module.nix b/module.nix index 1fba9b0..81a83a2 100644 --- a/module.nix +++ b/module.nix @@ -40,7 +40,7 @@ matugen: { matugenConfig = configFormat.generate "matugen-config.toml" { config = { custom_colors = cfg.custom_colors; - }; + } // cfg.config; templates = sanitizedTemplates; }; @@ -157,6 +157,17 @@ in { example = "light"; }; + config = lib.mkOption { + description = "Add things to the config not covered by other options."; + type = lib.types.attrs; + default = osCfg.config or {}; + example = '' + { + custom_keywords.font1 = "Google Sans"; + } + ''; + }; + theme.files = lib.mkOption { type = lib.types.package; readOnly = true; From ac4a36bf331012b655abe5125d801033dee976c2 Mon Sep 17 00:00:00 2001 From: Talia-12 Date: Wed, 28 Aug 2024 23:29:37 +1000 Subject: [PATCH 3/4] make nix module able to generate from color or wallpaper. --- module.nix | 53 +++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 39 insertions(+), 14 deletions(-) diff --git a/module.nix b/module.nix index 81a83a2..f5f145e 100644 --- a/module.nix +++ b/module.nix @@ -8,16 +8,22 @@ matugen: { cfg = config.programs.matugen; osCfg = args.osConfig.programs.matugen or {}; - hexColor = lib.types.strMatching "#([0-9a-fA-F]{3}){1,2}"; - hexStrippedColor = lib.types.strMatching "([0-9a-fA-F]{3}){1,2}"; - rgbColor = lib.types.strMatching "rgb\(\d{1,3}, ?\d{1,3}, ?\d{1,3}\)"; - rgbaColor = lib.types.strMatching "rgba\(\d{1,3}, ?\d{1,3}, ?\d{1,3}, ?\d{1,3}\)"; - hslColor = lib.types.strMatching "hsl\(\d{1,3}, ?\d{1,3}%, ?\d{1,3}%\)"; - hslaColor = lib.types.strMatching "hsla\(\d{1,3}, ?\d{1,3}%, ?\d{1,3}%, ?[0,1](\.\d*)\)"; - - # Only hexColor is currently supported for custom_colors. - colorType = hexColor; - # colorType = lib.types.oneOf [hexColor hexStrippedColor rgbColor rgbaColor hslColor hslaColor]; + hexColorRegex = ''#([0-9a-fA-F]{3}){1,2}''; + hexStrippedColorRegex = ''([0-9a-fA-F]{3}){1,2}''; + rgbColorRegex = ''rgb\([0-9]{1,3}, ?[0-9]{1,3}, ?[0-9]{1,3}\)''; + rgbaColorRegex = ''rgba\([0-9]{1,3}, ?[0-9]{1,3}, ?[0-9]{1,3}, ?[0-9]{1,3}\)''; + hslColorRegex = ''hsl\([0-9]{1,3}(\.[0-9]*)?, ?[0-9]{1,3}(\.[0-9]*)?%, ?[0-9]{1,3}(\.[0-9]*)?%\)''; + hslaColorRegex = ''hsla\([0-9]{1,3}(\.[0-9]*)?, ?[0-9]{1,3}(\.[0-9]*)?%, ?[0-9]{1,3}(\.[0-9]*)?%, ?[0,1](\.[0-9]*)?\)''; + + hexColor = lib.types.strMatching hexColorRegex; + hexStrippedColor = lib.types.strMatching hexStrippedColorRegex; + rgbColor = lib.types.strMatching rgbColorRegex; + rgbaColor = lib.types.strMatching rgbaColorRegex; + hslColor = lib.types.strMatching hslColorRegex; + hslaColor = lib.types.strMatching hslaColorRegex; + + sourceColorType = lib.types.oneOf [hexColor rgbColor hslColor]; + customColorType = hexColor; # Only hexColor is currently supported for custom_colors. configFormat = pkgs.formats.toml {}; @@ -47,20 +53,32 @@ matugen: { # get matugen package pkg = matugen.packages.${pkgs.system}.default; - themePackage = pkgs.runCommandLocal "matugen-themes-${cfg.variant}" {} '' + # takes in a source color string and returns the subcommand needed to generate + # a color scheme using that color type. + sourceColorTypeMatcher = color: (lib.lists.findSingle (p: null != builtins.match p.regex color) {} {} [ + { regex = hexColorRegex; code = "hex"; } + { regex = rgbColorRegex; code = "rgb"; } + { regex = hslColorRegex; code = "hsl"; } + ]).code; + + command = if (builtins.isNull cfg.source_color) then + "image ${cfg.wallpaper}" else + "color ${sourceColorTypeMatcher cfg.source_color} \"${cfg.source_color}\""; + + themePackage = builtins.trace command (pkgs.runCommandLocal "matugen-themes-${cfg.variant}" {} '' mkdir -p $out cd $out export HOME=$(pwd) ${cfg.package}/bin/matugen \ - image ${cfg.wallpaper} \ + ${command} \ --config ${matugenConfig} \ --mode ${cfg.variant} \ --type ${cfg.type} \ --json ${cfg.jsonFormat} \ --quiet \ > $out/theme.json - ''; + ''); colors = (builtins.fromJSON (builtins.readFile "${themePackage}/theme.json")).colors; in { options.programs.matugen = { @@ -72,6 +90,13 @@ in { default = pkg; }; + source_color = lib.mkOption { + description = "Hex color to generate the colorschemes from. If this and wallpaper are defined, will use this."; + type = lib.types.nullOr sourceColorType; + default = osCfg.source_color or null; + example = "#ff1243"; + }; + wallpaper = lib.mkOption { description = "Path to `wallpaper` that matugen will generate the colorschemes from"; type = lib.types.path; @@ -111,7 +136,7 @@ in { options = { color = lib.mkOption { description = "Color value for this custom color."; - type = colorType; + type = customColorType; example = "#d03e3e"; }; blend = lib.mkOption { From 80a781659f626adf40febdca2c339c200a92b556 Mon Sep 17 00:00:00 2001 From: Talia-12 Date: Thu, 29 Aug 2024 01:34:30 +1000 Subject: [PATCH 4/4] made contrast configurable in nix module --- module.nix | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/module.nix b/module.nix index f5f145e..4397c34 100644 --- a/module.nix +++ b/module.nix @@ -76,6 +76,7 @@ matugen: { --mode ${cfg.variant} \ --type ${cfg.type} \ --json ${cfg.jsonFormat} \ + --contrast ${lib.strings.floatToString cfg.contrast} \ --quiet \ > $out/theme.json ''); @@ -182,6 +183,13 @@ in { example = "light"; }; + contrast = lib.mkOption { + description = "Value from -1 to 1. -1 represents minimum contrast, 0 represents standard (i.e. the design as spec'd), and 1 represents maximum contrast."; + type = lib.types.numbers.between (-1) 1; + default = 0; + example = "0.2"; + }; + config = lib.mkOption { description = "Add things to the config not covered by other options."; type = lib.types.attrs;