Use an external library for base16 ♻️

https://github.com/SenchoPens/base16.nix
This commit is contained in:
Daniel Thwaites 2022-04-23 10:36:20 +01:00
parent 3b47dde0da
commit c2358177dc
No known key found for this signature in database
GPG key ID: D8AFC4BF05670F9D
15 changed files with 208 additions and 211 deletions

View file

@ -1,5 +1,25 @@
{
"nodes": {
"base16": {
"inputs": {
"nixpkgs": [
"nixpkgs"
]
},
"locked": {
"lastModified": 1643556194,
"narHash": "sha256-mU/pD30cIRcodLROhbIpRuEoEsO9aV5lDrYav0ZSIUA=",
"owner": "SenchoPens",
"repo": "base16.nix",
"rev": "abc25e69d0e18ce54dbe6d95a531c4d63ed59932",
"type": "github"
},
"original": {
"owner": "SenchoPens",
"repo": "base16.nix",
"type": "github"
}
},
"nixpkgs": {
"locked": {
"lastModified": 1633422745,
@ -18,6 +38,7 @@
},
"root": {
"inputs": {
"base16": "base16",
"nixpkgs": "nixpkgs",
"utils": "utils"
}

View file

@ -1,10 +1,14 @@
{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
base16 = {
url = "github:SenchoPens/base16.nix";
inputs.nixpkgs.follows = "nixpkgs";
};
utils.url = "github:numtide/flake-utils";
};
outputs = { nixpkgs, utils, self, ... }:
outputs = { nixpkgs, base16, utils, self, ... }:
(utils.lib.eachSystem [ "aarch64-linux" "i686-linux" "x86_64-linux" ]
(system:
let
@ -35,7 +39,7 @@
packages.palette-generator = palette-generator;
apps.palette-generator = palette-generator-app;
})) // {
nixosModules.stylix = { pkgs, ... }: {
nixosModules.stylix = { pkgs, ... }@args: {
imports = [
./modules/console.nix
./modules/dunst.nix
@ -50,9 +54,10 @@
./modules/qutebrowser.nix
./modules/sway.nix
./modules/vim.nix
(import ./stylix/palette.nix
self.packages.${pkgs.system}.palette-generator)
./stylix/base16.nix
(import ./stylix/palette.nix {
inherit (self.packages.${pkgs.system}) palette-generator;
base16 = base16.lib args;
})
./stylix/fonts.nix
./stylix/home-manager.nix
./stylix/pixel.nix

View file

@ -1,32 +1,32 @@
{ config, ... }:
with config.lib.stylix.colors;
with config.lib.stylix.colors.withHashtag;
with config.stylix.fonts;
{
stylix.homeModule = {
services.dunst.settings = {
global = {
separator_color = base02-hash;
separator_color = base02;
font = sansSerif.name;
};
urgency_low = {
background = base01-hash;
foreground = base05-hash;
frame_color = base0B-hash;
background = base01;
foreground = base05;
frame_color = base0B;
};
urgency_normal = {
background = base01-hash;
foreground = base05-hash;
frame_color = base0E-hash;
background = base01;
foreground = base05;
frame_color = base0E;
};
urgency_critical = {
background = base01-hash;
foreground = base05-hash;
frame_color = base08-hash;
background = base01;
foreground = base05;
frame_color = base08;
};
};
};

View file

@ -1,16 +1,15 @@
{ pkgs, config, ... }:
let
base16-fish = pkgs.fetchFromGitHub {
owner = "tomyun";
repo = "base16-fish";
rev = "7f647967fddedaf803191bc9113b13d2071dc3cf";
sha256 = "IGUbLjsmmAvB9UKGkR7oqdpjeVEfzt83GpyBkrZf2O4=";
theme = config.lib.stylix.colors {
templateRepo = pkgs.fetchFromGitHub {
owner = "tomyun";
repo = "base16-fish";
rev = "7f647967fddedaf803191bc9113b13d2071dc3cf";
sha256 = "IGUbLjsmmAvB9UKGkR7oqdpjeVEfzt83GpyBkrZf2O4=";
};
};
theme = config.lib.stylix.base16.buildTemplate "fish"
"${base16-fish}/templates/default.mustache";
promptInit = ''
source ${theme}
base16-stylix

View file

@ -2,7 +2,7 @@
with config.lib.stylix;
with config.stylix.fonts;
with config.lib.stylix.colors;
with config.lib.stylix.colors.withHashtag;
let
# Grub requires fonts to be converted to "PFF2 format"
@ -24,7 +24,7 @@ let
in {
boot.loader.grub = {
backgroundColor = base00-hash;
backgroundColor = base00;
# Need to override the NixOS splash, this will match the background
splashImage = pixel "base00";
@ -36,7 +36,7 @@ in {
themeTxt = ''
desktop-image: "background.png"
desktop-image-scale-method: "crop"
desktop-color: "${base00-hash}"
desktop-color: "${base00}"
title-text: ""
@ -56,10 +56,10 @@ in {
font = "${sansSerif.name}"
text = "@TIMEOUT_NOTIFICATION_MIDDLE@"
border_color = "${base00-hash}"
bg_color = "${base00-hash}"
fg_color = "${base0B-hash}"
text_color = "${base05-hash}"
border_color = "${base00}"
bg_color = "${base00}"
fg_color = "${base0B}"
text_color = "${base05}"
}
+ boot_menu {
@ -74,9 +74,9 @@ in {
item_spacing = 0
item_padding = 0
item_font = "${sansSerif.name}"
item_color = "${base05-hash}"
item_color = "${base05}"
selected_item_color = "${base01-hash}"
selected_item_color = "${base01}"
selected_item_pixmap_style = "selection_*.png"
}
'';

View file

@ -30,7 +30,7 @@ let
'';
# Based on https://github.com/nana-4/materia-theme/blob/master/change_color.sh
preConfigure = with config.lib.stylix.colors;
preConfigure = with config.lib.stylix.colors.withHashtag;
let font = config.stylix.fonts.sansSerif.name;
in ''
echo 'Setting font family'
@ -91,24 +91,24 @@ let
{} \; ;
find "$FILEPATH" -type f -exec sed -i'\' \
-e 's/%BG%/${base00-hash}/g' \
-e 's/%BG2%/${base01-hash}/g' \
-e 's/%FG%/${base05-hash}/g' \
-e 's/%HDR_BG%/${base01-hash}/g' \
-e 's/%HDR_BG2%/${base01-hash}/g' \
-e 's/%HDR_BG3%/${base01-hash}/g' \
-e 's/%HDR_FG%/${base05-hash}/g' \
-e 's/%INACTIVE_FG%/${base04-hash}/g' \
-e 's/%MATERIA_SURFACE%/${base01-hash}/g' \
-e 's/%MATERIA_VIEW%/${base00-hash}/g' \
-e 's/%SEL_BG%/${base02-hash}/g' \
-e 's/%SEL_BG2%/${base03-hash}/g' \
-e 's/%TERMINAL_COLOR4%/${base0A-hash}/g' \
-e 's/%TERMINAL_COLOR5%/${base0D-hash}/g' \
-e 's/%TERMINAL_COLOR9%/${base03-hash}/g' \
-e 's/%TERMINAL_COLOR10%/${base09-hash}/g' \
-e 's/%TERMINAL_COLOR11%/${base01-hash}/g' \
-e 's/%TERMINAL_COLOR12%/${base02-hash}/g' \
-e 's/%BG%/${base00}/g' \
-e 's/%BG2%/${base01}/g' \
-e 's/%FG%/${base05}/g' \
-e 's/%HDR_BG%/${base01}/g' \
-e 's/%HDR_BG2%/${base01}/g' \
-e 's/%HDR_BG3%/${base01}/g' \
-e 's/%HDR_FG%/${base05}/g' \
-e 's/%INACTIVE_FG%/${base04}/g' \
-e 's/%MATERIA_SURFACE%/${base01}/g' \
-e 's/%MATERIA_VIEW%/${base00}/g' \
-e 's/%SEL_BG%/${base02}/g' \
-e 's/%SEL_BG2%/${base03}/g' \
-e 's/%TERMINAL_COLOR4%/${base0A}/g' \
-e 's/%TERMINAL_COLOR5%/${base0D}/g' \
-e 's/%TERMINAL_COLOR9%/${base03}/g' \
-e 's/%TERMINAL_COLOR10%/${base09}/g' \
-e 's/%TERMINAL_COLOR11%/${base01}/g' \
-e 's/%TERMINAL_COLOR12%/${base02}/g' \
-e 's/%MATERIA_SELECTION_OPACITY%/0.32/g' \
-e 's/%MATERIA_PANEL_OPACITY%/0.6/g' \
{} \; ;

View file

@ -1,101 +1,101 @@
{ config, ... }:
with config.lib.stylix.colors;
with config.lib.stylix.colors.withHashtag;
# Based upon https://github.com/helix-editor/helix/blob/f8c83f98859fd618980141eb95e7927dcdf074d7/runtime/themes/base16_default_dark.toml
let theme = {
"ui.background".bg = base00-hash;
"ui.background".bg = base00;
"ui.menu" = {
fg = base05-hash;
bg = base01-hash;
fg = base05;
bg = base01;
};
"ui.menu.selected" = {
fg = base01-hash;
bg = base04-hash;
fg = base01;
bg = base04;
};
"ui.linenr" = {
fg = base03-hash;
bg = base01-hash;
fg = base03;
bg = base01;
};
"ui.popup".bg = base01-hash;
"ui.window".bg = base01-hash;
"ui.popup".bg = base01;
"ui.window".bg = base01;
"ui.linenr.selected" = {
fg = base04-hash;
bg = base01-hash;
fg = base04;
bg = base01;
modifiers = [ "bold" ];
};
"ui.selection".bg = base02-hash;
"ui.selection".bg = base02;
"comment" = {
fg = base03-hash;
fg = base03;
modifiers = [ "italic" ];
};
"ui.statusline" = {
fg = base04-hash;
bg = base01-hash;
fg = base04;
bg = base01;
};
"ui.cursor" = {
fg = base04-hash;
fg = base04;
modifiers = [ "reversed" ];
};
"ui.cursor.primary" = {
fg = base05-hash;
fg = base05;
modifiers = [ "reversed" ];
};
"ui.text" = base05-hash;
"operator" = base05-hash;
"ui.text.focus" = base05-hash;
"variable" = base08-hash;
"constant.numeric" = base09-hash;
"constant" = base09-hash;
"attributes" = base09-hash;
"type" = base0A-hash;
"ui.text" = base05;
"operator" = base05;
"ui.text.focus" = base05;
"variable" = base08;
"constant.numeric" = base09;
"constant" = base09;
"attributes" = base09;
"type" = base0A;
"ui.cursor.match" = {
fg = base0A-hash;
fg = base0A;
modifiers = [ "underlined" ];
};
"string" = base0B-hash;
"variable.other.member" = base0B-hash;
"constant.character.escape" = base0C-hash;
"function" = base0D-hash;
"constructor" = base0D-hash;
"special" = base0D-hash;
"keyword" = base0E-hash;
"label" = base0E-hash;
"namespace" = base0E-hash;
"string" = base0B;
"variable.other.member" = base0B;
"constant.character.escape" = base0C;
"function" = base0D;
"constructor" = base0D;
"special" = base0D;
"keyword" = base0E;
"label" = base0E;
"namespace" = base0E;
"ui.help" = {
fg = base06-hash;
bg = base01-hash;
fg = base06;
bg = base01;
};
"markup.heading" = base0D-hash;
"markup.list" = base08-hash;
"markup.heading" = base0D;
"markup.list" = base08;
"markup.bold" = {
fg = base0A-hash;
fg = base0A;
modifiers = [ "bold" ];
};
"markup.italic" = {
fg = base0E-hash;
fg = base0E;
modifiers = [ "italic" ];
};
"markup.link.url" = {
fg = base09-hash;
fg = base09;
modifiers = [ "underlined" ];
};
"markup.link.text" = base08-hash;
"markup.quote" = base0C-hash;
"markup.raw" = base0B-hash;
"markup.link.text" = base08;
"markup.quote" = base0C;
"markup.raw" = base0B;
"diff.plus" = base0B-hash;
"diff.delta" = base09-hash;
"diff.minus" = base08-hash;
"diff.plus" = base0B;
"diff.delta" = base09;
"diff.minus" = base08;
"diagnostic".modifiers = [ "underlined" ];
"ui.gutter".bg = base01-hash;
"info" = base0D-hash;
"hint" = base03-hash;
"debug" = base03-hash;
"warning" = base09-hash;
"error" = base08-hash;
"ui.gutter".bg = base01;
"info" = base0D;
"hint" = base03;
"debug" = base03;
"warning" = base09;
"error" = base08;
};
in {

View file

@ -5,38 +5,38 @@
programs.kitty = {
font = config.stylix.fonts.monospace;
settings = with config.lib.stylix.colors; {
settings = with config.lib.stylix.colors.withHashtag; {
# Based on https://github.com/kdrag0n/base16-kitty/
active_border_color = base03-hash;
active_tab_background = base00-hash;
active_tab_foreground = base05-hash;
background = base00-hash;
cursor = base05-hash;
foreground = base05-hash;
inactive_border_color = base01-hash;
inactive_tab_background = base01-hash;
inactive_tab_foreground = base04-hash;
selection_background = base05-hash;
selection_foreground = base00-hash;
tab_bar_background = base01-hash;
url_color = base04-hash;
active_border_color = base03;
active_tab_background = base00;
active_tab_foreground = base05;
background = base00;
cursor = base05;
foreground = base05;
inactive_border_color = base01;
inactive_tab_background = base01;
inactive_tab_foreground = base04;
selection_background = base05;
selection_foreground = base00;
tab_bar_background = base01;
url_color = base04;
color0 = base00-hash;
color1 = base08-hash;
color2 = base0B-hash;
color3 = base0A-hash;
color4 = base0D-hash;
color5 = base0E-hash;
color6 = base0C-hash;
color7 = base05-hash;
color8 = base03-hash;
color9 = base09-hash;
color10 = base01-hash;
color11 = base02-hash;
color12 = base04-hash;
color13 = base06-hash;
color14 = base0F-hash;
color15 = base07-hash;
color0 = base00;
color1 = base08;
color2 = base0B;
color3 = base0A;
color4 = base0D;
color5 = base0E;
color6 = base0C;
color7 = base05;
color8 = base03;
color9 = base09;
color10 = base01;
color11 = base02;
color12 = base04;
color13 = base06;
color14 = base0F;
color15 = base07;
};
};
};

View file

@ -1,18 +1,18 @@
{ config, ... }:
with config.stylix.fonts;
with config.lib.stylix.colors;
with config.lib.stylix.colors.withHashtag;
let
background = base00-hash;
secondary-background = base01-hash;
selection-background = base03-hash;
foreground = base05-hash;
inverted-foreground = base00-hash;
info = base0B-hash;
secondary-info = base0C-hash;
warning = base0E-hash;
error = base08-hash;
background = base00;
secondary-background = base01;
selection-background = base03;
foreground = base05;
inverted-foreground = base00;
info = base0B;
secondary-info = base0C;
warning = base0E;
error = base08;
in {
stylix.homeModule = {

View file

@ -1,12 +1,12 @@
{ config, ... }:
with config.lib.stylix.colors;
with config.lib.stylix.colors.withHashtag;
let
text = base05-hash;
urgent = base08-hash;
focused = base0A-hash;
unfocused = base03-hash;
text = base05;
urgent = base08;
focused = base0A;
unfocused = base03;
fonts = {
names = [ config.stylix.fonts.sansSerif.name ];
@ -19,8 +19,8 @@ in {
inherit fonts;
colors = let
background = base00-hash;
indicator = base0B-hash;
background = base00;
indicator = base0B;
in {
inherit background;
urgent = {
@ -59,12 +59,12 @@ in {
inherit fonts;
colors = let
background = base01-hash;
background = base01;
border = background;
in {
inherit background;
statusline = text;
separator = base03-hash;
separator = base03;
focusedWorkspace = {
inherit text border;
background = focused;

View file

@ -1,27 +1,24 @@
{ pkgs, config, ... }:
let
base16-vim = pkgs.fetchFromGitHub {
owner = "chriskempson";
repo = "base16-vim";
rev = "6191622d5806d4448fa2285047936bdcee57a098";
sha256 = "6FsT87qcl9GBxgxrPx2bPULIMA/O8TRxHaN49qMM4uM=";
themeFile = config.lib.stylix.colors {
templateRepo = pkgs.fetchFromGitHub {
owner = "chriskempson";
repo = "base16-vim";
rev = "6191622d5806d4448fa2285047936bdcee57a098";
sha256 = "6FsT87qcl9GBxgxrPx2bPULIMA/O8TRxHaN49qMM4uM=";
};
};
themePlugin = pkgs.vimUtils.buildVimPlugin {
name = "stylix";
pname = "stylix";
src = base16-vim;
data = config.lib.stylix.base16.json;
passAsFile = [ "data" ];
src = themeFile;
dontUnpack = true;
buildPhase = ''
# Remove pre-built color schemes
rm colors/*
${pkgs.mustache-go}/bin/mustache $dataPath \
templates/default.mustache > colors/base16-stylix.vim
install -D $src $out/colors/base16-stylix.vim
'';
};

View file

@ -6,28 +6,15 @@ import Data.Word ( Word8 )
import Text.JSON ( JSObject, toJSObject )
import Text.Printf ( printf )
makeOutputs :: (String, RGB Word8) -> [(String, String)]
makeOutputs (name, RGB r g b)
= [ (name ++ "-dec-r", show $ fromIntegral r / 255)
, (name ++ "-dec-g", show $ fromIntegral g / 255)
, (name ++ "-dec-b", show $ fromIntegral b / 255)
, (name ++ "-rgb-r", show r)
, (name ++ "-rgb-g", show g)
, (name ++ "-rgb-b", show b)
, (name ++ "-hex-r", printf "%02x" r)
, (name ++ "-hex-g", printf "%02x" g)
, (name ++ "-hex-b", printf "%02x" b)
, (name ++ "-hex", printf "%02x%02x%02x" r g b)
, (name ++ "-hash", printf "#%02x%02x%02x" r g b)
]
toWord8 :: (RealFrac a) => RGB a -> RGB Word8
toWord8 (RGB r g b) = RGB (truncate r) (truncate g) (truncate b)
toHex :: RGB Word8 -> String
toHex (RGB r g b) = printf "%02x%02x%02x" r g b
makeOutputTable :: (RealFrac a) => V.Vector (RGB a) -> JSObject String
makeOutputTable
= toJSObject
. concat
. V.map makeOutputs
. V.toList
. V.imap (\i c -> (printf "base%02X" i, c))
. V.map toWord8
. V.map (toHex . toWord8)

View file

@ -1,20 +0,0 @@
# Used to build templates from http://chriskempson.com/projects/base16/
{ pkgs, config, ... }:
{
config.lib.stylix.base16 = rec {
json = builtins.toJSON (config.lib.stylix.colors // {
# Additional attributes only used for base16
scheme-name = "Stylix";
scheme-slug = "stylix";
scheme-author = "Stylix";
});
buildTemplate = name: templatePath:
pkgs.runCommand "base16-${name}" {
inherit json templatePath;
passAsFile = [ "json" ];
} "${pkgs.mustache-go}/bin/mustache $jsonPath $templatePath > $out";
};
}

View file

@ -1,4 +1,4 @@
palette-generator:
{ palette-generator, base16 }:
{ pkgs, lib, config, ... }:
with lib;
@ -6,10 +6,16 @@ with lib;
let
cfg = config.stylix;
palette = pkgs.runCommand "palette.json" { } ''
paletteJSON = pkgs.runCommand "palette.json" { } ''
${palette-generator}/bin/palette-generator ${cfg.image} $out
'';
palette = importJSON paletteJSON // {
author = "Stylix";
scheme = "Stylix";
slug = "stylix";
};
in {
options.stylix = {
image = mkOption {
@ -50,5 +56,7 @@ in {
*/
};
config.lib.stylix.colors = importJSON palette;
# This attrset can be used like a function too, see
# https://github.com/SenchoPens/base16.nix#mktheme
config.lib.stylix.colors = base16.mkSchemeAttrs palette;
}

View file

@ -4,6 +4,6 @@
# Generate a PNG image containing a named color
config.lib.stylix.pixel = color:
pkgs.runCommand "${color}-pixel.png" {
color = config.lib.stylix.colors."${color}-hash";
color = config.lib.stylix.colors.withHashtag.${color};
} "${pkgs.imagemagick}/bin/convert xc:$color png32:$out";
}