From 8cce73bcf55181c0a44176c44d8b00196926ba74 Mon Sep 17 00:00:00 2001 From: DaniD3v Date: Sun, 21 Jul 2024 23:38:20 +0200 Subject: [PATCH] draft: reworked hm-module --- module.nix | 160 ++++++++++++++++++++--------------------------------- 1 file changed, 59 insertions(+), 101 deletions(-) diff --git a/module.nix b/module.nix index 387fb4a..a4d4603 100644 --- a/module.nix +++ b/module.nix @@ -9,76 +9,30 @@ matugen: { osCfg = inputs.osConfig.programs.matugen or {}; tomlFormat = pkgs.formats.toml {}; - - capitalize = str: let - inherit (builtins) substring stringLength; - firstChar = substring 0 1 str; - restOfString = substring 1 (stringLength str) str; - in - lib.concatStrings [(lib.toUpper firstChar) restOfString]; - - # don't use ~, use $HOME - sanitizedTemplates = - builtins.mapAttrs (_: v: { - mode = capitalize cfg.variant; - input_path = builtins.toString v.input_path; - output_path = builtins.replaceStrings ["$HOME"] ["~"] v.output_path; - }) - cfg.templates; - - matugenConfig = tomlFormat.generate "matugen-config.toml" { - config = {}; - templates = sanitizedTemplates; - }; - - # get matugen package - pkg = matugen.packages.${pkgs.system}.default; - - themePackage = pkgs.runCommandLocal "matugen-themes-${cfg.variant}" {} '' - mkdir -p $out - cd $out - export HOME=$(pwd) - - ${pkg}/bin/matugen \ - image ${cfg.wallpaper} \ - ${ - if cfg.templates != {} - then "--config ${matugenConfig}" - else "" - } \ - --mode ${cfg.variant} \ - --type ${cfg.type} \ - --json ${cfg.jsonFormat} \ - --quiet \ - > $out/theme.json - ''; - colors = builtins.fromJSON (builtins.readFile "${themePackage}/theme.json"); in { options.programs.matugen = { enable = lib.mkEnableOption "Matugen declarative theming"; wallpaper = lib.mkOption { - type = lib.types.path; - default = osCfg.wallpaper or "${pkgs.nixos-artwork.wallpapers.simple-blue}/share/backgrounds/nixos/nix-wallpaper-simple-blue.png"; + type = with lib.types; nullOr path; + default = osCfg.wallpaper or null; + example = "../wallpaper/astolfo.png"; description = "Path to `wallpaper` that matugen will generate the colorschemes from"; - defaultText = lib.literalExample '' - "${pkgs.nixos-artwork.wallpapers.simple-blue}/share/backgrounds/nixos/nix-wallpaper-simple-blue.png" - ''; }; templates = lib.mkOption { - type = with lib.types; - attrsOf (submodule { + type = with lib; + types.attrsOf (types.submodule { options = { - input_path = lib.mkOption { - type = path; + input_path = mkOption { + type = types.path; example = "./style.css"; description = "Path to the template"; }; - output_path = lib.mkOption { - type = str; + output_path = mkOption { + type = types.str; example = "~/.config/sytle.css"; description = "Path where the generated file will be written to"; @@ -93,56 +47,60 @@ in { ''; }; - type = lib.mkOption { - 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"; - description = "Palette used when generating the colorschemes."; - }; + settings = lib.mkOption { + inherit (tomlFormat) type; + default = osCfg.settings or {}; - jsonFormat = lib.mkOption { - type = lib.types.enum ["rgb" "rgba" "hsl" "hsla" "hex" "strip"]; - default = osCfg.jsonFormat or "strip"; - - example = "rgba"; - description = "Color format of the colorschemes."; - }; + example = '' + config.reload_apps_list = { + gtk_theme = true; + kitty = true; + } + ''; + description = '' + Matugen configuration file in nix syntax. - variant = lib.mkOption { - type = lib.types.enum ["light" "dark" "amoled"]; - default = osCfg.variant or "dark"; - - example = "light"; - description = "Colorscheme variant."; + Written to {file}`$XDG_CONFIG_HOME/matugen/config.toml` + A manual for configuring matugen can be found at . + ''; }; + }; - theme.files = lib.mkOption { - type = lib.types.package; - readOnly = true; - default = - if builtins.hasAttr "templates" osCfg - then - if cfg.templates != osCfg.templates - then themePackage - else osCfg.theme.files - else themePackage; - - description = "Generated theme files. Including only the variant chosen."; - }; + config = let + package = matugen.packages.${pkgs.system}.default; + + mergedCfg = + cfg.settings + // ( + if cfg.templates != {} + then {inherit (cfg) templates;} + else {} + ); + + configFile = tomlFormat.generate "config.toml" mergedCfg; + + resultPackage = + if (cfg.wallpaper != null) + then [ + ( + pkgs.runCommand "results" {} + '' + echo "out path: $out" + echo "running command: ${package}/bin/matugen image ${cfg.wallpaper} --config ${configFile} --prefix $out" + + mkdir -p $out/${config.home.homeDirectory} + ${package}/bin/matugen image ${cfg.wallpaper} --config ${configFile} --prefix $out + '' + ) + ] + else []; + in + lib.mkIf cfg.enable { + home.packages = + [package] + ++ resultPackage; - theme.colors = lib.mkOption { - inherit (pkgs.formats.json {}) type; - readOnly = true; - default = - if builtins.hasAttr "templates" osCfg - then - if cfg.templates != osCfg.templates - then colors - else osCfg.theme.colors - else colors; - - description = "Generated theme colors. Includes all variants."; + xdg.configFile."matugen/config.toml".source = + lib.mkIf (mergedCfg != {}) configFile; }; - }; }