rework colors module, allow generating colors from image

This commit is contained in:
notgne2 2021-10-06 19:29:50 -07:00
parent 6a324ed487
commit 7e614b3168
No known key found for this signature in database
GPG Key ID: BB661E172B42A7F8
7 changed files with 157 additions and 148 deletions

View File

@ -30,6 +30,14 @@
url = "github:franciscolourenco/done"; url = "github:franciscolourenco/done";
flake = false; flake = false;
}; };
schemer2 = {
url = "github:thefryscorer/schemer2";
flake = false;
};
auto-base16-theme = {
url = "github:makuto/auto-base16-theme";
flake = false;
};
}; };
outputs = { self, nixpkgs, ... }@inputs: { outputs = { self, nixpkgs, ... }@inputs: {

View File

@ -1,8 +1,8 @@
name: base16: base16:
'' ''
{ {
"name": "Base16 ${name}", "name": "Base16 generated",
"type": "dark", "type": "dark",
"colors": { "colors": {
// Contrast colors // Contrast colors

View File

@ -1,4 +1,4 @@
name: base16: base16:
'' ''
gtk-color-scheme = "bg_color:#${base16."base00"}\nfg_color:#${ gtk-color-scheme = "bg_color:#${base16."base00"}\nfg_color:#${

View File

@ -1,4 +1,4 @@
name: base16: base16:
'' ''
" GUI color definitions " GUI color definitions

View File

@ -39,13 +39,13 @@ let
lib.mapAttrs' (k: v: lib.nameValuePair "${k}-dec-g" ((hexToRgb v).g / 255.0)) base16 // lib.mapAttrs' (k: v: lib.nameValuePair "${k}-dec-g" ((hexToRgb v).g / 255.0)) base16 //
lib.mapAttrs' (k: v: lib.nameValuePair "${k}-dec-b" ((hexToRgb v).b / 255.0)) base16; lib.mapAttrs' (k: v: lib.nameValuePair "${k}-dec-b" ((hexToRgb v).b / 255.0)) base16;
mustache = scheme: name: src: mustache = scheme: src:
pkgs.stdenv.mkDerivation ( pkgs.stdenv.mkDerivation (
{ {
# TODO add template name # TODO add template name
name = lib.strings.sanitizeDerivationName name; name = "base16-generated";
inherit src; inherit src;
data = pkgs.writeText "${name}-data" (builtins.toJSON scheme); data = pkgs.writeText "base16-generated-data" (builtins.toJSON scheme);
phases = [ "buildPhase" ]; phases = [ "buildPhase" ];
buildPhase = "${pkgs.mustache-go}/bin/mustache $data $src > $out"; buildPhase = "${pkgs.mustache-go}/bin/mustache $data $src > $out";
} }
@ -53,11 +53,27 @@ let
genTheme = repo: mustache genTheme = repo: mustache
(makeScheme cfg.base16 // { (makeScheme cfg.base16 // {
scheme-name = cfg.favColors.name; scheme-name = "base16 generated";
scheme-slug = "idk"; scheme-slug = "idk";
scheme-author = "nixos"; scheme-author = "nixos";
}) })
cfg.favColors.name "${repo}/templates/default.mustache"; "${repo}/templates/default.mustache";
schemer2 = pkgs.buildGoPackage rec {
pname = "schemer2";
version = "0.0.1";
goPackagePath = "github.com/thefryscorer/schemer2";
src = inputs.schemer2;
vendorSha256 = "1fzlslz9xr3jay9kpvrg7sj1a0c1f1m1kn5rnis49hvlr1sc00d1";
meta = with lib; {
description = "Terminal Colorscheme Generator and Converter";
homepage = "https://github.com/thefryscorer/schemer2";
};
};
in in
{ {
options.colors = { options.colors = {
@ -83,19 +99,11 @@ in
type = types.attrsOf types.str; type = types.attrsOf types.str;
}; };
favColors = mkOption { baseColors = mkOption {
description = "Your favourite color scheme"; type = types.either (types.attrsOf types.str) types.path;
default = { }; description = "base16 color scheme or path to an image to use to generate the scheme";
type = types.submodule {
options = {
name = mkOption {
type = types.str;
default = "Monokai";
description = "Name of your color scheme";
};
base16 = mkOption {
type = types.attrsOf types.str;
default = { default = {
# (monokai)
base00 = "272822"; base00 = "272822";
base01 = "383830"; base01 = "383830";
base02 = "49483e"; base02 = "49483e";
@ -113,16 +121,12 @@ in
base0E = "ae81ff"; base0E = "ae81ff";
base0F = "cc6633"; base0F = "cc6633";
}; };
description = "BASE16 color scheme";
};
};
};
}; };
}; };
config = config =
let let
colorsJson = builtins.toFile "colors.json" (builtins.toJSON cfg.favColors.base16); colorsJson = builtins.toFile "colors.json" (builtins.toJSON cfg.base16);
themeHashOut = pkgs.runCommandNoCC "theme-hash" { } '' themeHashOut = pkgs.runCommandNoCC "theme-hash" { } ''
cat ${colorsJson} | ${pkgs.coreutils}/bin/sha256sum | ${pkgs.coreutils}/bin/head -c 8 > $out cat ${colorsJson} | ${pkgs.coreutils}/bin/sha256sum | ${pkgs.coreutils}/bin/head -c 8 > $out
''; '';
@ -131,41 +135,41 @@ in
i3config = { i3config = {
config = { config = {
colors = { colors = {
background = "#${cfg.favColors.base16.base07}"; background = "#${cfg.base16.base07}";
focused = { focused = {
border = "#${cfg.favColors.base16.base05}"; border = "#${cfg.base16.base05}";
background = "#${cfg.favColors.base16.base0D}"; background = "#${cfg.base16.base0D}";
text = "#${cfg.favColors.base16.base00}"; text = "#${cfg.base16.base00}";
indicator = "#${cfg.favColors.base16.base0D}"; indicator = "#${cfg.base16.base0D}";
childBorder = "#${cfg.favColors.base16.base0D}"; childBorder = "#${cfg.base16.base0D}";
}; };
focusedInactive = { focusedInactive = {
border = "#${cfg.favColors.base16.base01}"; border = "#${cfg.base16.base01}";
background = "#${cfg.favColors.base16.base01}"; background = "#${cfg.base16.base01}";
text = "#${cfg.favColors.base16.base05}"; text = "#${cfg.base16.base05}";
indicator = "#${cfg.favColors.base16.base03}"; indicator = "#${cfg.base16.base03}";
childBorder = "#${cfg.favColors.base16.base01}"; childBorder = "#${cfg.base16.base01}";
}; };
unfocused = { unfocused = {
border = "#${cfg.favColors.base16.base01}"; border = "#${cfg.base16.base01}";
background = "#${cfg.favColors.base16.base00}"; background = "#${cfg.base16.base00}";
text = "#${cfg.favColors.base16.base05}"; text = "#${cfg.base16.base05}";
indicator = "#${cfg.favColors.base16.base01}"; indicator = "#${cfg.base16.base01}";
childBorder = "#${cfg.favColors.base16.base01}"; childBorder = "#${cfg.base16.base01}";
}; };
urgent = { urgent = {
border = "#${cfg.favColors.base16.base08}"; border = "#${cfg.base16.base08}";
background = "#${cfg.favColors.base16.base08}"; background = "#${cfg.base16.base08}";
text = "#${cfg.favColors.base16.base00}"; text = "#${cfg.base16.base00}";
indicator = "#${cfg.favColors.base16.base08}"; indicator = "#${cfg.base16.base08}";
childBorder = "#${cfg.favColors.base16.base08}"; childBorder = "#${cfg.base16.base08}";
}; };
placeholder = { placeholder = {
border = "#${cfg.favColors.base16.base00}"; border = "#${cfg.base16.base00}";
background = "#${cfg.favColors.base16.base00}"; background = "#${cfg.base16.base00}";
text = "#${cfg.favColors.base16.base05}"; text = "#${cfg.base16.base05}";
indicator = "#${cfg.favColors.base16.base00}"; indicator = "#${cfg.base16.base00}";
childBorder = "#${cfg.favColors.base16.base00}"; childBorder = "#${cfg.base16.base00}";
}; };
}; };
}; };
@ -175,22 +179,22 @@ in
name = "colors-${themeHash}"; name = "colors-${themeHash}";
is_dark = true; is_dark = true;
colors = { colors = {
"accent-color" = "#${cfg.favColors.base16.base02}"; "accent-color" = "#${cfg.base16.base02}";
"primary-color" = "#${cfg.favColors.base16.base08}"; "primary-color" = "#${cfg.base16.base08}";
"warning-color" = "#${cfg.favColors.base16.base0F}"; "warning-color" = "#${cfg.base16.base0F}";
"sidebar-color" = "#${cfg.favColors.base16.base01}"; "sidebar-color" = "#${cfg.base16.base01}";
"roomlist-background-color" = "#${cfg.favColors.base16.base00}"; "roomlist-background-color" = "#${cfg.base16.base00}";
"roomlist-text-color" = "#${cfg.favColors.base16.base05}"; "roomlist-text-color" = "#${cfg.base16.base05}";
"roomlist-text-secondary-color" = "${cfg.favColors.base16.base06}"; "roomlist-text-secondary-color" = "${cfg.base16.base06}";
"roomlist-highlights-color" = "#${cfg.favColors.base16.base02}"; "roomlist-highlights-color" = "#${cfg.base16.base02}";
"roomlist-separator-color" = "#${cfg.favColors.base16.base05}"; "roomlist-separator-color" = "#${cfg.base16.base05}";
"timeline-background-color" = "#${cfg.favColors.base16.base00}"; "timeline-background-color" = "#${cfg.base16.base00}";
"timeline-text-color" = "#${cfg.favColors.base16.base07}"; "timeline-text-color" = "#${cfg.base16.base07}";
"timeline-text-secondary-color" = "#${cfg.favColors.base16.base05}"; "timeline-text-secondary-color" = "#${cfg.base16.base05}";
"timeline-highlights-color" = "#${cfg.favColors.base16.base02}"; "timeline-highlights-color" = "#${cfg.base16.base02}";
"reaction-row-button-selected-bg-color" = "#${cfg.favColors.base16.base0B}"; "reaction-row-button-selected-bg-color" = "#${cfg.base16.base0B}";
}; };
}; };
@ -201,12 +205,19 @@ in
showLabsSettings = true; showLabsSettings = true;
}; };
base16FromImageSrc = pkgs.runCommandNoCC "auto-image-base16" { } ''
${schemer2}/bin/schemer2 -format img::colors -in ${cfg.baseColors} -out colors.txt && ${pkgs.python3}/bin/python3 ${inputs.auto-base16-theme}/AutoBase16Theme.py ${inputs.auto-base16-theme}/templates/base16-template.yaml auto-image-base16.yaml
${pkgs.yaml2json}/bin/yaml2json < auto-image-base16.yaml > $out
'';
base16FromImage = lib.filterAttrs (k: v: k != "scheme" && k != "author") (builtins.fromJSON (builtins.readFile base16FromImageSrc));
in in
mkIf cfg.enable { mkIf cfg.enable {
# Read only utility attributes # Read only utility attributes
colors.base16 = cfg.favColors.base16; colors.base16 = if builtins.typeOf cfg.baseColors == "set" then cfg.baseColors else base16FromImage;
colors.base16Rgb = builtins.mapAttrs hexToRgb cfg.favColors.base16; colors.base16Rgb = builtins.mapAttrs hexToRgb cfg.base16;
colors.base16Split = builtins.mapAttrs splitHex cfg.favColors.base16; colors.base16Split = builtins.mapAttrs splitHex cfg.base16;
# Element # Element
xdg.configFile."Riot/config.json".text = builtins.toJSON elementConfig; xdg.configFile."Riot/config.json".text = builtins.toJSON elementConfig;
@ -214,44 +225,44 @@ in
# Mako # Mako
programs.mako = { programs.mako = {
backgroundColor = "#${cfg.favColors.base16.base00}"; backgroundColor = "#${cfg.base16.base00}";
textColor = "#${cfg.favColors.base16.base07}"; textColor = "#${cfg.base16.base07}";
borderColor = "#${cfg.favColors.base16.base08}"; borderColor = "#${cfg.base16.base08}";
progressColor = "over #${cfg.favColors.base16.base0D}"; progressColor = "over #${cfg.base16.base0D}";
}; };
# I3/sway # I3/sway
wayland.windowManager.sway = i3config; wayland.windowManager.sway = i3config;
xsession.windowManager.i3 = i3config; xsession.windowManager.i3 = i3config;
colors.i3BarColors = { colors.i3BarColors = {
background = "#${cfg.favColors.base16.base00}"; background = "#${cfg.base16.base00}";
separator = "#${cfg.favColors.base16.base01}"; separator = "#${cfg.base16.base01}";
statusline = "#${cfg.favColors.base16.base04}"; statusline = "#${cfg.base16.base04}";
focusedWorkspace = { focusedWorkspace = {
border = "#${cfg.favColors.base16.base05}"; border = "#${cfg.base16.base05}";
background = "#${cfg.favColors.base16.base0D}"; background = "#${cfg.base16.base0D}";
text = "#${cfg.favColors.base16.base00}"; text = "#${cfg.base16.base00}";
}; };
activeWorkspace = { activeWorkspace = {
border = "#${cfg.favColors.base16.base05}"; border = "#${cfg.base16.base05}";
background = "#${cfg.favColors.base16.base03}"; background = "#${cfg.base16.base03}";
text = "#${cfg.favColors.base16.base00}"; text = "#${cfg.base16.base00}";
}; };
inactiveWorkspace = { inactiveWorkspace = {
border = "#${cfg.favColors.base16.base03}"; border = "#${cfg.base16.base03}";
background = "#${cfg.favColors.base16.base01}"; background = "#${cfg.base16.base01}";
text = "#${cfg.favColors.base16.base05}"; text = "#${cfg.base16.base05}";
}; };
urgentWorkspace = { urgentWorkspace = {
border = "#${cfg.favColors.base16.base08}"; border = "#${cfg.base16.base08}";
background = "#${cfg.favColors.base16.base08}"; background = "#${cfg.base16.base08}";
text = "#${cfg.favColors.base16.base00}"; text = "#${cfg.base16.base00}";
}; };
bindingMode = { bindingMode = {
border = "#${cfg.favColors.base16.base00}"; border = "#${cfg.base16.base00}";
background = "#${cfg.favColors.base16.base0A}"; background = "#${cfg.base16.base0A}";
text = "#${cfg.favColors.base16.base00}"; text = "#${cfg.base16.base00}";
}; };
}; };
@ -259,23 +270,23 @@ in
services.dunst = { services.dunst = {
settings = { settings = {
global = { global = {
frame_color = "#${cfg.favColors.base16.base09}"; frame_color = "#${cfg.base16.base09}";
separator_color = "#${cfg.favColors.base16.base05}"; separator_color = "#${cfg.base16.base05}";
}; };
urgency_low = { urgency_low = {
background = "#${cfg.favColors.base16.base01}"; background = "#${cfg.base16.base01}";
foreground = "#${cfg.favColors.base16.base03}"; foreground = "#${cfg.base16.base03}";
}; };
urgency_normal = { urgency_normal = {
background = "#${cfg.favColors.base16.base02}"; background = "#${cfg.base16.base02}";
foreground = "#${cfg.favColors.base16.base05}"; foreground = "#${cfg.base16.base05}";
}; };
urgency_critical = { urgency_critical = {
background = "#${cfg.favColors.base16.base08}"; background = "#${cfg.base16.base08}";
foreground = "#${cfg.favColors.base16.base06}"; foreground = "#${cfg.base16.base06}";
}; };
}; };
}; };
@ -289,7 +300,7 @@ in
''; '';
# neovim # neovim
xdg.configFile."nvim/colors/base16.vim".text = import ../data/vim-base16.nix cfg.favColors.name cfg.favColors.base16; xdg.configFile."nvim/colors/base16.vim".text = import ../data/vim-base16.nix cfg.base16;
programs.neovim.extraConfig = '' programs.neovim.extraConfig = ''
colorscheme base16 colorscheme base16
set termguicolors set termguicolors
@ -304,7 +315,7 @@ in
configBase16 = { configBase16 = {
name = "Generated"; name = "Generated";
kind = "dark"; kind = "dark";
colors = builtins.mapAttrs (k: v: { hex.rgb = v; }) cfg.favColors.base16; colors = builtins.mapAttrs (k: v: { hex.rgb = v; }) cfg.base16;
}; };
}; };
in in
@ -312,11 +323,7 @@ in
name = "Generated"; name = "Generated";
package = generated-gtk-theme; package = generated-gtk-theme;
}; };
gtk2.extraConfig = ( gtk2.extraConfig = import ../data/gtk2-base16.nix cfg.base16;
(import ../data/gtk2-base16.nix)
cfg.favColors.name
cfg.favColors.base16
);
}; };
# Codium/VSCODE # Codium/VSCODE
@ -328,7 +335,7 @@ in
[ [
( (
mkIf config.programs.vscode.enable { mkIf config.programs.vscode.enable {
".vscode-oss/extensions/base16-1.0.0/themes/nix-colors.json".text = (import ../data/codium-base16.nix) cfg.favColors.name cfg.favColors.base16; ".vscode-oss/extensions/base16-1.0.0/themes/nix-colors.json".text = import ../data/codium-base16.nix cfg.base16;
".vscode-oss/extensions/base16-1.0.0/package.json".text = builtins.toJSON { ".vscode-oss/extensions/base16-1.0.0/package.json".text = builtins.toJSON {
name = "nix colors"; name = "nix colors";
displayName = "Automatic Nix-generated base16 colors"; displayName = "Automatic Nix-generated base16 colors";

View File

@ -3,9 +3,6 @@ inputs:
{ {
imports = [ imports = [
(lib.mkAliasOptionModule [ "ezpcusr" "favColors" ] [ "colors" "favColors" ])
(lib.mkAliasOptionModule [ "ezpcusr" "favFont" ] [ "fonts" "favFont" ])
(lib.mkAliasOptionModule [ "ezpcusr" "waybarCss" ] [ "programs" "waybar" "style" ])
(lib.mkAliasOptionModule [ "ezpcusr" "gaming" ] [ "gaming" "enable" ]) (lib.mkAliasOptionModule [ "ezpcusr" "gaming" ] [ "gaming" "enable" ])
(lib.mkAliasOptionModule [ "ezpcusr" "flatSteam" ] [ "gaming" "flatSteam" ]) (lib.mkAliasOptionModule [ "ezpcusr" "flatSteam" ] [ "gaming" "flatSteam" ])
(lib.mkAliasOptionModule [ "ezpcusr" "newWine" ] [ "gaming" "newWine" ]) (lib.mkAliasOptionModule [ "ezpcusr" "newWine" ] [ "gaming" "newWine" ])

View File

@ -394,9 +394,7 @@ in
# base0F = "B03060"; # base0F = "B03060";
# }; # };
# }; # };
favColors = { baseColors = {
name = "Material Vivid";
base16 = {
base00 = "202124"; base00 = "202124";
base01 = "27292c"; base01 = "27292c";
base02 = "323639"; base02 = "323639";
@ -415,7 +413,6 @@ in
base0F = "8d6e63"; base0F = "8d6e63";
}; };
}; };
};
programs.fish.shellAliases = { programs.fish.shellAliases = {
bp = "npm version patch && npm publish && git push"; bp = "npm version patch && npm publish && git push";