diff options
| author | Arpit Chakladar <arpitchakladar@gmail.com> | 2026-09-18 06:17:21 +0530 |
|---|---|---|
| committer | Arpit Chakladar <arpitchakladar@gmail.com> | 2026-09-18 06:17:21 +0530 |
| commit | 53eac37422f77750adbc801f71b85ab04cf2b7f9 (patch) | |
| tree | c8ea93c066eee28389aeb14e15f6c37a3e38b276 /modules/colors/base16/default.nix | |
| parent | 453c4a6002e51265f5bcaef3bf53a1362f4c7b6a (diff) | |
| download | home-manager-config-53eac37422f77750adbc801f71b85ab04cf2b7f9.tar.gz home-manager-config-53eac37422f77750adbc801f71b85ab04cf2b7f9.zip | |
chore(colors/base16): refactoring
Diffstat (limited to 'modules/colors/base16/default.nix')
| -rw-r--r-- | modules/colors/base16/default.nix | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/modules/colors/base16/default.nix b/modules/colors/base16/default.nix new file mode 100644 index 0000000..1262b53 --- /dev/null +++ b/modules/colors/base16/default.nix @@ -0,0 +1,57 @@ +# Provide options/configurations for other modules to use base16 colorschemes +{ + config, + lib, + pkgs, + ... +}: +let + schemeFiles = { + "onedark-dark" = ./onedark-dark.nix; + }; + + schemeFile = + schemeFiles.${config.colors.base16} or (throw "Unknown color scheme: ${config.colors.base16}"); + + colors = import schemeFile { }; + + withHashtag = lib.mapAttrs (_: v: "#${v}") colors; + colorNames = builtins.attrNames colors; + + processTemplate = + template: + let + content = if builtins.typeOf template == "path" then builtins.readFile template else template; + replaced = builtins.replaceStrings (map (name: "@@${name}@@") colorNames) (map ( + name: colors.${name} + ) colorNames) content; + in + replaced; +in +{ + options = { + colors.base16 = lib.mkOption { + type = lib.types.str; + default = "onedark-dark"; + description = "Base16 color scheme to use"; + }; + + scheme = lib.mkOption { + type = lib.types.unspecified; + description = "Color scheme providing withHashtag and template function"; + }; + }; + + config = { + scheme = { + inherit withHashtag; + __functor = + self: + { + template, + extension ? "", + }: + pkgs.writeText "themed${extension}" (processTemplate template); + }; + }; +} |
