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";
flake = false;
};
schemer2 = {
url = "github:thefryscorer/schemer2";
flake = false;
};
auto-base16-theme = {
url = "github:makuto/auto-base16-theme";
flake = false;
};
};
outputs = { self, nixpkgs, ... }@inputs: {

View File

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

View File

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

View File

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

View File

@ -3,9 +3,6 @@ inputs:
{
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" "flatSteam" ] [ "gaming" "flatSteam" ])
(lib.mkAliasOptionModule [ "ezpcusr" "newWine" ] [ "gaming" "newWine" ])

View File

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