From 8174101c22c42ff832955f1384bf5a02e46c1d9d Mon Sep 17 00:00:00 2001 From: Daniel Thwaites Date: Fri, 22 Jul 2022 17:42:34 +0100 Subject: [PATCH] Implement manual palettes :sparkles: Fixes #1 --- README.md | 11 +++++++- stylix/palette.nix | 70 +++++++++++++++++++++++++++------------------- 2 files changed, 52 insertions(+), 29 deletions(-) diff --git a/README.md b/README.md index 5fe3d38..cc1fa3f 100644 --- a/README.md +++ b/README.md @@ -58,9 +58,18 @@ a NixOS module; how to do this is shown in the example above. # A colorscheme will be chosen automatically based on your wallpaper. stylix.image = ./wallpaper.png; - # Use this option to force a light or dark theme. + # Use this option to force a light or dark theme to be chosen. stylix.polarity = "light"; + # You can override parts of the scheme by hand: + stylix.palette = { + base00 = "eeeeee"; + base05 = "111111"; + }; + + # Or replace it with a scheme from base16: + stylix.base16Scheme = "${base16-schemes}/gruvbox-dark-hard.yaml"; + # Select your preferred fonts, or use these defaults: stylix.fonts = { serif = { diff --git a/stylix/palette.nix b/stylix/palette.nix index fabdd5f..a9dbe4e 100644 --- a/stylix/palette.nix +++ b/stylix/palette.nix @@ -9,13 +9,18 @@ let paletteJSON = pkgs.runCommand "palette.json" { } '' ${palette-generator}/bin/palette-generator ${cfg.polarity} ${cfg.image} $out ''; + generatedPalette = importJSON paletteJSON; - palette = importJSON paletteJSON // { + paletteOverrides = filterAttrs (_: color: color != null) cfg.palette; + + metadata = { author = "Stylix"; scheme = "Stylix"; slug = "stylix"; }; + stylixPalette = generatedPalette // paletteOverrides // metadata; + in { options.stylix = { polarity = mkOption { @@ -40,35 +45,44 @@ in { ''; }; - /* TODO: Implement manual palette - palette = genAttrs [ - "base00" - "base01" - "base02" - "base03" - "base04" - "base05" - "base06" - "base07" - "base08" - "base09" - "base0A" - "base0B" - "base0C" - "base0D" - "base0E" - "base0F" - ] (name: - mkOption { - description = "Hexadecimal color value for ${name}."; - default = null; - defaultText = "Automatically selected from the background image."; - type = types.nullOr (types.strMatching "[0-9a-fA-F]{6}"); - }); - */ + palette = genAttrs [ + "base00" "base01" "base02" "base03" "base04" "base05" "base06" "base07" + "base08" "base09" "base0A" "base0B" "base0C" "base0D" "base0E" "base0F" + ] (base: mkOption { + description = '' + Hexadecimal color value for ${base}. + + These options can be used to override a section of the automatically + generated palette, while keeping other parts. For example, you can + select the background and text colors by setting bases 00 to 07, while + keeping the accent colors automatic. + + See stylix.base16Scheme for importing an entire + scheme. + ''; + default = null; + defaultText = "Automatically selected from the background image."; + type = types.nullOr (types.strMatching "[0-9a-fA-F]{6}"); + }); + + base16Scheme = mkOption { + description = '' + A scheme following the base16 standard. + + This can be a path to a file, a string of YAML, or an attribute set. + + Setting this option will completely disable the automatic palette + generator, and use these colors instead. + ''; + default = null; + type = with types; nullOr (oneOf [ path lines attrs ]); + }; }; # This attrset can be used like a function too, see # https://github.com/SenchoPens/base16.nix#mktheme - config.lib.stylix.colors = base16.mkSchemeAttrs palette; + config.lib.stylix.colors = + if cfg.base16Scheme != null + then base16.mkSchemeAttrs cfg.base16Scheme + else base16.mkSchemeAttrs stylixPalette; }