This commit is contained in:
Luke Bentley-Fox 2020-07-20 20:41:02 +01:00
parent 4f192afaa0
commit 60af3a798e
No known key found for this signature in database
GPG Key ID: A02C35CAD21C9BC4
8 changed files with 259 additions and 86 deletions

23
LICENSE.md Normal file
View File

@ -0,0 +1,23 @@
# LICENSE
base16-nix is released under the MIT License:
> Copyright (c) 2020 [Luke Bentley-Fox](https://lukebentleyfox.net)
>
> Permission is hereby granted, free of charge, to any person obtaining a copy
> of this software and associated documentation files (the "Software"), to deal
> in the Software without restriction, including without limitation the rights
> to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
> copies of the Software, and to permit persons to whom the Software is
> furnished to do so, subject to the following conditions:
>
> The above copyright notice and this permission notice shall be included in all
> copies or substantial portions of the Software.
>
> THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
> IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
> FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
> AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
> LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
> OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
> SOFTWARE.

View File

@ -1,17 +1,27 @@
# Base16 themes for home manager
This is a messy, personal set of scripts for managing colour schemes within
hame manager. I am yet to share it because there are some unprincipled
components likely to break (e.g. using `sed` to read yaml files), and because
the build functions it introduces use sizable external dependencies.
This is a fork of [atpotts/base16-nix](https://github.com/atpotts/base16-nix)
I have found aspects of this very nice to use, and have tried to clean it up
enough to be suitable for others to adapt. YMMV however.
Differences:
- Exports the home manager module as a flake output.
- Restricts scope to official base16-themes.
- Prefers the colors-only mustache template if supported, as usually I prefer to
do my own customisation.
## Usage
## Usage
import this flake in your 'flake.nix':
```nix
inputs.base16.url = 'github:lukebfox/base16-nix';
```
then, in any home-manager configuration:
```nix
home.user.${user} = {config,pkgs,lib}:{
imports = [ base16.hmModule ];
}
```
N.b. this example roughly reflects my usage, but I haven't tried to use it
directly, so there may be typos / bugs
```nix
{pkgs, lib, config, ...}:

View File

@ -1,37 +1,57 @@
{config,lib,pkgs,...}:
{ config, lib, pkgs, ... }:
with lib;
let
cfg = config.themes.base16;
inherit (builtins) pathExists;
schemes = importJSON ./schemes.json;
templates = importJSON ./templates.json;
schemes = importJSON ./schemes.json;
# mustache engine
mustache = template-attrs: name: src:
pkgs.stdenv.mkDerivation (
{
name="${name}-${template-attrs.scheme-slug}";
inherit src;
data = pkgs.writeText "${name}-data" (builtins.toJSON template-attrs);
phases = [ "buildPhase" ];
buildPhase ="${pkgs.mustache-go}/bin/mustache $data $src > $out";
allowSubstitutes = false; # will never be in cache
});
# Data file for a given base16 scheme and variant. Returns the nix store
# path of the file.
mkTheme = scheme: variant:
"${pkgs.fetchgit (schemes."${scheme}")}/${variant}.yaml";
# nasty python script for dealing with yaml + different output types
python = pkgs.python.withPackages (ps: with ps; [ pyyaml ]);
loadyaml = {src, name ? "yaml"}:
importJSON (pkgs.stdenv.mkDerivation {
inherit name src;
builder = pkgs.writeText "builder.sh" ''
slug_all=$(${pkgs.coreutils}/bin/basename $src)
slug=''${slug_all%.*}
${python}/bin/python ${./base16writer.py} $slug < ${src} > $out
'';
allowSubstitutes = false; # will never be in cache
});
# Source file for a given base16 template. Use the colors-only template
# if one exists, as I generally prefer to do my own customisations.
# Returns the nix store path of the file.
mkTemplate = name:
let
templateDir = "${pkgs.fetchgit (templates."${name}")}/templates";
in
if pathExists (templateDir + "/colors.mustache")
then templateDir + "/colors.mustache"
else templateDir + "/default.mustache";
theme = loadyaml {
src="${pkgs.fetchgit (schemes."${cfg.scheme}")}/${cfg.variant}.yaml";
# The theme yaml files only supply 16 hex values, but the templates take
# a transformation of this data such as rgb. The hacky python script pre-
# processes the theme file in this way for consumption by the mustache
# engine below.
python = pkgs.python.withPackages (ps: [ ps.pyyaml ]);
preprocess = src:
pkgs.stdenv.mkDerivation {
name = "placeholder-change-me";
inherit src;
builder = pkgs.writeText "builder.sh" ''
slug_all=$(${pkgs.coreutils}/bin/basename $src)
slug=''${slug_all%.*}
${python}/bin/python ${./base16writer.py} $slug < $src > $out
'';
allowSubstitutes = false; # will never be in cache
};
# Mustache engine. Applies any theme to any template, providing they are
# included in the local json source files.
mustache = scheme: variant: name:
pkgs.stdenv.mkDerivation {
name = "${name}-base16-${variant}";
data = preprocess (mkTheme scheme variant);
src = mkTemplate name;
phases = [ "buildPhase" ];
buildPhase ="${pkgs.mustache-go}/bin/mustache $data $src > $out";
allowSubstitutes = false; # will never be in cache
};
in
@ -39,29 +59,16 @@ in
options = {
themes.base16.enable = mkEnableOption "Base 16 Color Schemes";
themes.base16.scheme = mkOption {
type=types.str;
default="solarized";
};
themes.base16.variant = mkOption {
type=types.str;
default="solarized-dark";
};
themes.base16.extraParams = mkOption {
type = types.attrsOf types.string; default = {};
type=types.str;
default="tomorrow";
};
themes.base16.variant = mkOption {
type=types.str;
default="tomorrow";
};
themes.base16.tone = mkOption
};
config = {
lib.base16.theme = theme // cfg.extraParams;
lib.base16.base16template = repo:
mustache (theme // cfg.extraParams) repo
"${pkgs.fetchgit (templates."${repo}")}/templates/default.mustache";
lib.base16.template = attrs@{name ? "unknown-template", src , ...}:
mustache (theme // cfg.extraParams // attrs) name src;
lib.base16.base16template = mustache cfg.scheme cfg.variant;
};
}

View File

@ -1,3 +1,4 @@
# credit @atpotts
import yaml
import json
import sys

28
flake.lock generated Normal file
View File

@ -0,0 +1,28 @@
{
"nodes": {
"nixpkgs": {
"info": {
"lastModified": 1593360652,
"narHash": "sha256-8dXbDWhLzgZfiQ+XZ2rtSnUAafFizeeXJa5fuF/9n4w="
},
"locked": {
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "c5299e9d5bb18f1ebd817e0a4767103b9935f0ee",
"type": "github"
},
"original": {
"id": "nixpkgs",
"ref": "release-20.03",
"type": "indirect"
}
},
"root": {
"inputs": {
"nixpkgs": "nixpkgs"
}
}
},
"root": "root",
"version": 5
}

44
flake.nix Normal file
View File

@ -0,0 +1,44 @@
{
description = "Base16-template builder for nix.";
inputs.nixpkgs.url = "nixpkgs/release-20.03";
outputs = inputs@{ self, nixpkgs }:
let
pkgs = import nixpkgs { system = "x86_64-linux"; };
in {
# Home-Manager Module
hmModule = ./base16.nix;
# Nix shell definition. Enter with 'nix develop'. Inside, can use
# 'update-base16' to update the sources lists.
devShell.x86_64-linux = let
update = pkgs.writeShellScriptBin "update-base16" ''
# should always be permitted to run to completion
generate_sources () {
out=$1
curl "https://raw.githubusercontent.com/chriskempson/base16-$out-source/master/list.yaml"\
| sed -nE "s~^([-_[:alnum:]]+): *(.*)~\1 \2~p"\
| while read name src; do
echo "{\"key\":\"$name\",\"value\":"
nix-prefetch-git $src
echo "}"
done\
| jq -s ".|del(.[].value.date)|from_entries"\
> $out.json
}
generate_sources templates &
generate_sources schemes &
wait
'';
in pkgs.mkShell {
nativeBuildInputs = with pkgs; [
curl nix-prefetch-git gnused jq update
];
};
};
}

View File

@ -47,6 +47,12 @@
"sha256": "0vlr9sxn8xx0n41fflaw1xw5s4hd6cfn7mdvlbs1hldlrd86ysir",
"fetchSubmodules": false
},
"colors": {
"url": "https://github.com/hakatashi/base16-colors-scheme",
"rev": "ecd803faa288bf4bd5a50977d90984143a512364",
"sha256": "1d05vprhrjamssly3hxyfjzmcnf743y39rr7js5y1xxn915qx7gi",
"fetchSubmodules": false
},
"cupertino": {
"url": "https://github.com/Defman21/base16-cupertino",
"rev": "8df41b787a16640dd29f88251e95beed4bf9a5c5",
@ -91,8 +97,8 @@
},
"equilibrium": {
"url": "https://github.com/carloabelli/base16-equilibrium-scheme",
"rev": "509e488d8e707f558c155d88b1c02bf97242fda8",
"sha256": "05w3lyqw19y5f2j974pyh65726cjfq4lm9ma600kkc11flcpg9c3",
"rev": "87d0bd37e7eb682a33b1c5170e9a44e2af2301bd",
"sha256": "0pakiz34kd1n4l5nldl6y3hzxcl5q0pdvk3cdp20f8f7fz9rak3y",
"fetchSubmodules": false
},
"espresso": {
@ -101,6 +107,12 @@
"sha256": "1fvwz5n7z42404lpigl9d3mwfs3rl61fcaafvn4b4pw33l3zn7q6",
"fetchSubmodules": false
},
"eva": {
"url": "https://github.com/kjakapat/base16-eva-scheme",
"rev": "595ea6eff814ae462709f222e7af3492ee804e88",
"sha256": "1f788kr3nxdclg12n1g44g871zy9n5sfsxza3gm8nzzpzwz837gv",
"fetchSubmodules": false
},
"framer": {
"url": "https://github.com/jssee/base16-framer-scheme",
"rev": "f4e15f3182132c57e8294ba235862404e419256f",
@ -203,6 +215,12 @@
"sha256": "0qsmixipxb12lalfpxxp2ni5k3byy67gnrdr2frryny9iwglw742",
"fetchSubmodules": false
},
"nebula": {
"url": "https://github.com/Misterio77/base16-nebula-scheme",
"rev": "cc6010630c5a7a7ec1f5928b37da9721f7988f9a",
"sha256": "0b7y8j038dqhdgqvhxsix6p3miih9h426sfwdvg010fpdid3ynwy",
"fetchSubmodules": false
},
"nova": {
"url": "https://github.com/gessig/base16-nova-scheme",
"rev": "d0bc7162c69d61b62784e8fe5a9e60b3e6c4af3c",
@ -229,8 +247,14 @@
},
"papercolor": {
"url": "https://github.com/jonleopard/base16-papercolor-scheme",
"rev": "6a378195dd7bebab38c9d1b7f7f973603074d3cd",
"sha256": "1r61cm0v2mvsvm8v2dccxhlcx0fqi9kbq9ja869ib2b8lc3vxgn6",
"rev": "369290edecba0ede1208739b3be21fb8a6a5a2d5",
"sha256": "1bipf7bnackg7yz30nqvd6nylnspdwq194hdrasi0gwfvw6j62zx",
"fetchSubmodules": false
},
"pasque": {
"url": "https://github.com/Misterio77/base16-pasque-scheme",
"rev": "41dccec87745e7e73a8feaa899803b0c3ecd12f5",
"sha256": "0fyvnb2zyil0x4vz0b58d9hr30z0vlwl60kx3jl38rfn21ax6whj",
"fetchSubmodules": false
},
"porple": {
@ -259,8 +283,8 @@
},
"snazzy": {
"url": "https://github.com/h404bi/base16-snazzy-scheme",
"rev": "ad9d2ded7bcf2fd631e876c8793d7317a9b9876a",
"sha256": "15w250dnji6r18wgqqjjbvnwy60n669zphyx86ak4iy9mcn91vij",
"rev": "5789feadb12b35604ed95a2fe1b028fafe64d7f1",
"sha256": "08wv03305c8asbdhd9b4i6gsgzk5qvnlrmdn7lyclpx4xd4qlpvx",
"fetchSubmodules": false
},
"solarflare": {
@ -289,8 +313,8 @@
},
"synth-midnight": {
"url": "https://github.com/michael-ball/base16-synth-midnight-scheme",
"rev": "22d57ccdddc70045e7bcab186625d740f874c990",
"sha256": "1vggy2jpf35zv2m8z40gqh9f83jm8hs9zps9vi4z2c5ic9047xrs",
"rev": "bbb9d8300ab33c490038752f2e235f2467f7c6d8",
"sha256": "0xs02n792vq4gwz7qw80qf74d68i3x47zgsrrf35jl9mghn1csda",
"fetchSubmodules": false
},
"tango": {
@ -317,6 +341,12 @@
"sha256": "09mg23rni68plamizmdhwq05k6w64l77m2h4sc65xjpcqaap74x5",
"fetchSubmodules": false
},
"vice": {
"url": "https://github.com/Thomashighbaugh/base16-vice-scheme",
"rev": "142c92c30c9c60e764c267c151c6265d6ea8d540",
"sha256": "1gx7h4s9wm96941p8kbh390nyqjmar369hfwmxg6x7qsjb1rskz7",
"fetchSubmodules": false
},
"woodland": {
"url": "https://github.com/jcornwall/base16-woodland-scheme",
"rev": "0278e12a49f4cf38ecf3026a1e35f4307e928d33",

View File

@ -25,8 +25,8 @@
},
"concfg": {
"url": "https://github.com/h404bi/base16-concfg",
"rev": "ff65516f91d79b31f099d830f20b9d06fb9405f5",
"sha256": "0r0il2wnim7wqs2inn3f8i2apbj2hhinfvr66wng8zibdh7j8zyf",
"rev": "da3596440fdafa7008d50cd0da950a3d6810b257",
"sha256": "0q1r7fxapf0i76hh359llsjichac7d68r9g8z31nni36kx0agdq9",
"fetchSubmodules": false
},
"conemu": {
@ -67,14 +67,20 @@
},
"emacs": {
"url": "https://github.com/belak/base16-emacs",
"rev": "9eba6874c80ab429bf5cbf6c76bb0399d3d2a2cb",
"sha256": "0ag5fsr3377rz6xfa0b9j54r90zh0yiz98kpa27xzhky4f5jpdah",
"rev": "d68512c0856f57a19cd49d1034199836352c15a0",
"sha256": "1h98ra53i7hc7zi9yjc6p29f70r04hivdczhw4imds13akq6j034",
"fetchSubmodules": false
},
"everything": {
"url": "https://github.com/spitfire05/base16-everything",
"rev": "9931a068b7da50f6478170557eb9f586f9f400fc",
"sha256": "0bxbgcqlyiw2wy6yhdb0gkadfcm7ig3y3a9irwzk6b6s3s2hl255",
"fetchSubmodules": false
},
"fzf": {
"url": "https://github.com/nicodebo/base16-fzf",
"rev": "376c4e9bd6c76c381c993fc6dfcba142537a077e",
"sha256": "0s8pp21007g5w7pv7a0hp72lxi5a7xpmzb70mzf8imhyz2c8bbq1",
"url": "https://github.com/fnune/base16-fzf",
"rev": "ef4c386689f18bdc754a830a8e66bc2d46d515ae",
"sha256": "1hcr9sq3bxnin2b1pn9dzw39ddxsx1a0fr075l62yn9203fvq0hq",
"fetchSubmodules": false
},
"gnome-terminal": {
@ -89,6 +95,12 @@
"sha256": "0hzhdhn960m5916hg1yb6vw9mwwq7za9wqkyd32z2c67p4hmcdrq",
"fetchSubmodules": false
},
"gtk-flatcolor": {
"url": "https://github.com/Misterio77/base16-gtk-flatcolor",
"rev": "c30b2ed92d882b447f1d4c621b86a0fec228c5b4",
"sha256": "1g3a7jwlhhhzwgqn8bvngc2rd2nmzni8m3f7ki1f204h4csmyy4j",
"fetchSubmodules": false
},
"gtk2": {
"url": "https://github.com/dawikur/base16-gtk2",
"rev": "8a1a71bde8efb42498be26465b3f81faf564e3b7",
@ -157,8 +169,8 @@
},
"kitty": {
"url": "https://github.com/kdrag0n/base16-kitty",
"rev": "742d0326db469cae2b77ede3e10bedc323a41547",
"sha256": "19ffbvjmpla0pqqasmyfjw7hz7jzr6mhdmy8pn0babz0ff6m65fm",
"rev": "fe5862cec41bfd0b46a1ac3d7565a50680051226",
"sha256": "096sa969z9v9w3ggsqd4d7gmqh52aavkmjhbz4zb35wq7fg5g5zs",
"fetchSubmodules": false
},
"konsole": {
@ -167,6 +179,12 @@
"sha256": "0a8pjah1nkimnj3b59mvfj53zmjd4252s7zb7drvv45ik4n4cjj9",
"fetchSubmodules": false
},
"luakit": {
"url": "https://github.com/twnaing/base16-luakit",
"rev": "34112210caa242a0fb4b6b4f21e3e90e70db6aaa",
"sha256": "0f8wgbcjzhlji1xy8n4mj248416jazjy9x1qn5rfk1agyyslypq9",
"fetchSubmodules": false
},
"mako": {
"url": "https://github.com/Eluminae/base16-mako",
"rev": "f46c99682c03d30f52436741f1902db36738bf06",
@ -229,8 +247,8 @@
},
"qutebrowser": {
"url": "https://github.com/theova/base16-qutebrowser",
"rev": "c5da33b3d50cd30f18a50beac8bb2219c11213d9",
"sha256": "0rdhivsab1zvkqv66n7b7p6n1mmg9sr5ggsw1pl3rr6k3glk0pji",
"rev": "2105f3747a42162315b6dadd4a3d3f856ef3a9b0",
"sha256": "1c5rhr2jymj38x43lqbn4mpkg203x239v7n4ibcxv0h3a764gjgd",
"fetchSubmodules": false
},
"rofi": {
@ -283,14 +301,20 @@
},
"termite": {
"url": "https://github.com/khamer/base16-termite",
"rev": "2c01e32db3ed5e9015d951c39e77373d12022f6a",
"sha256": "1zkvsmcf7cg0a438hfrfpj8q657lq89mi8650x4p5scknkk6bd9s",
"rev": "4b57255c4580f95d5134e9754d27decdac2cf4c8",
"sha256": "12vqh29zgb99rg868rl9h63lvbv8rw0finlzgzg3vawvhx1x2r5v",
"fetchSubmodules": false
},
"termux": {
"url": "https://github.com/kdrag0n/base16-termux",
"rev": "ca2ab0f40eb9a0ae0ddc941b51dc7907660e137b",
"sha256": "0f09x9hwyzqxlnij8qgjvzx48i288xk4i9rihm3whg965clr9dbz",
"rev": "0ddb28fb91c07a1409a92dd4c9b1376ba9916b89",
"sha256": "00knxd0a7h15q9c25x2rwyp5lpp8ry3blsyzl49vmgr6rsn5m1nd",
"fetchSubmodules": false
},
"textadept": {
"url": "https://github.com/rgieseke/base16-textadept",
"rev": "eefe506cc853197c7df24439d6394d6f5bf4959c",
"sha256": "08ws58lmdq9n8bi70pynizj2xv2vw45sfx6fiv2rxkhdgqa435nm",
"fetchSubmodules": false
},
"textmate": {
@ -323,6 +347,12 @@
"sha256": "1qz21jizcy533mqk9wff1wqchhixkcfkysqcqs0x35wwpbri6nz8",
"fetchSubmodules": false
},
"vimiv": {
"url": "https://github.com/karlch/base16-vimiv",
"rev": "9993e275869d9c5b8b54f90727d21573878d50ea",
"sha256": "1xa6xnvmd6vw17r7mqgwramvra3z565v818zfpp7js3223w5080k",
"fetchSubmodules": false
},
"vis": {
"url": "https://github.com/pshevtsov/base16-vis",
"rev": "05dae61a524edf21632fc45b473ec8c3e0f553ab",
@ -349,8 +379,8 @@
},
"windows-terminal": {
"url": "https://github.com/wuqs-net/base16-windows-terminal",
"rev": "82ee9fe9f15da3b5a8330dcee9139d6dc4dbbc09",
"sha256": "0d3vjmxy0g7w0m1kj01arqyla33wb99zai2pqqwpysz82qk6lv4j",
"rev": "121784ab1c5ca849f344914d5276f4b73bbdc371",
"sha256": "15gj7ibdh3n2mmxlkilz3svlpmq3yp77bm6gjkz377ilynmxb2nq",
"fetchSubmodules": false
},
"xcode": {
@ -361,8 +391,8 @@
},
"xfce4-terminal": {
"url": "https://github.com/afg984/base16-xfce4-terminal",
"rev": "418756d9cdc8cbbc481689197122ab4c6f48444a",
"sha256": "1kfg0zagxz3s4ri91l6ih0bfd8vbhyy2kd6vzcfpjkj1565ik0rh",
"rev": "9596bd6d13f46294cbf650f16ada5ce6a4ff8521",
"sha256": "0dbqf7y7h795mdknj4rfr4q4blxx8c8qz6japj4c7g60l7rjs4l1",
"fetchSubmodules": false
},
"xresources": {
@ -379,8 +409,8 @@
},
"zathura": {
"url": "https://github.com/nicodebo/base16-zathura",
"rev": "d3eec6ed9c83725b6044b001d587cd42507c5496",
"sha256": "0b29npil6hsr4cld1g6cz8i9412fvqx2c25ls2v71bajirads1yl",
"rev": "7c276e53401903fda57c52628e0cfb67e70bbdda",
"sha256": "1x32hqa7qpppvy9jms2c6ib9g6mybbwrfbbqw5pfx5ksfbijaypp",
"fetchSubmodules": false
}
}