diff options
author | Minijackson <minijackson@riseup.net> | 2021-06-16 23:02:31 +0200 |
---|---|---|
committer | Minijackson <minijackson@riseup.net> | 2021-06-16 23:02:31 +0200 |
commit | 43760a34e578cd93480a27c9513eb9e35991e10d (patch) | |
tree | ad63c603692a6c956e0acae2a42e7cf238ed919b /lib | |
parent | 28edc231da9976f2127c9624c468b8a52abfc334 (diff) | |
download | nixos-config-reborn-43760a34e578cd93480a27c9513eb9e35991e10d.tar.gz nixos-config-reborn-43760a34e578cd93480a27c9513eb9e35991e10d.zip |
lib: init with theme and generators
Diffstat (limited to 'lib')
-rw-r--r-- | lib/default.nix | 6 | ||||
-rw-r--r-- | lib/generators.nix | 41 |
2 files changed, 47 insertions, 0 deletions
diff --git a/lib/default.nix b/lib/default.nix new file mode 100644 index 0000000..4bdd20d --- /dev/null +++ b/lib/default.nix | |||
@@ -0,0 +1,6 @@ | |||
1 | attrs: | ||
2 | |||
3 | { | ||
4 | generators = import ./generators.nix attrs; | ||
5 | theme = import ./theme.nix attrs; | ||
6 | } | ||
diff --git a/lib/generators.nix b/lib/generators.nix new file mode 100644 index 0000000..e93d4b0 --- /dev/null +++ b/lib/generators.nix | |||
@@ -0,0 +1,41 @@ | |||
1 | { lib, ... }: | ||
2 | |||
3 | with lib; | ||
4 | |||
5 | { | ||
6 | lua = {}: rec { | ||
7 | type = with types; let | ||
8 | valueType = nullOr | ||
9 | (oneOf [ | ||
10 | bool | ||
11 | int | ||
12 | float | ||
13 | str | ||
14 | (attrsOf valueType) | ||
15 | (listOf valueType) | ||
16 | ]) // { | ||
17 | description = "Lua value"; | ||
18 | }; in | ||
19 | valueType; | ||
20 | |||
21 | lib = { | ||
22 | mkRaw = value: { inherit value; _type = "raw"; }; | ||
23 | }; | ||
24 | |||
25 | generate = value: | ||
26 | let | ||
27 | list = l: "{ ${concatMapStringsSep ", " generate l} }"; | ||
28 | attrs = a: "{ ${concatStringsSep ", " (mapAttrsToList (name: value: "[${generate name}] = ${generate value}") a)} }"; | ||
29 | in | ||
30 | if value ? _type && value._type == "raw" then value.value | ||
31 | else if isInt value then toString value | ||
32 | else if isFloat value then toString value | ||
33 | else if isString value then "'${escape [ "'" ] value }'" | ||
34 | else if true == value then "true" | ||
35 | else if false == value then "false" | ||
36 | else if null == value then "nil" | ||
37 | else if isList value then list value | ||
38 | else if isAttrs value then attrs value | ||
39 | else abort "Lua value not supported: ${toPretty value}"; | ||
40 | }; | ||
41 | } | ||