aboutsummaryrefslogtreecommitdiffstats
path: root/modules/colors/base16/default.nix
diff options
context:
space:
mode:
Diffstat (limited to 'modules/colors/base16/default.nix')
-rw-r--r--modules/colors/base16/default.nix57
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);
+ };
+ };
+}