blob: 1262b5380c7948290b4f4966795c01b45367bfc1 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
# Provide options/configurations for other modules to use base16 colorschemes
{
config,
lib,
pkgs,
...
}:
let
schemeFiles = {
"onedark-dark" = ./onedark-dark.nix;
};
schemeFile =
schemeFiles.${config.colors.base16} or (throw "Unknown color scheme: ${config.colors.base16}");
colors = import schemeFile { };
withHashtag = lib.mapAttrs (_: v: "#${v}") colors;
colorNames = builtins.attrNames colors;
processTemplate =
template:
let
content = if builtins.typeOf template == "path" then builtins.readFile template else template;
replaced = builtins.replaceStrings (map (name: "@@${name}@@") colorNames) (map (
name: colors.${name}
) colorNames) content;
in
replaced;
in
{
options = {
colors.base16 = lib.mkOption {
type = lib.types.str;
default = "onedark-dark";
description = "Base16 color scheme to use";
};
scheme = lib.mkOption {
type = lib.types.unspecified;
description = "Color scheme providing withHashtag and template function";
};
};
config = {
scheme = {
inherit withHashtag;
__functor =
self:
{
template,
extension ? "",
}:
pkgs.writeText "themed${extension}" (processTemplate template);
};
};
}
|