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 | |
parent | 28edc231da9976f2127c9624c468b8a52abfc334 (diff) | |
download | nixos-config-reborn-43760a34e578cd93480a27c9513eb9e35991e10d.tar.gz nixos-config-reborn-43760a34e578cd93480a27c9513eb9e35991e10d.zip |
lib: init with theme and generators
-rw-r--r-- | common/commandline.nix | 2 | ||||
-rw-r--r-- | common/commandline/zsh.nix | 2 | ||||
-rw-r--r-- | flake.nix | 2 | ||||
-rw-r--r-- | lib/default.nix | 6 | ||||
-rw-r--r-- | lib/generators.nix | 41 |
5 files changed, 51 insertions, 2 deletions
diff --git a/common/commandline.nix b/common/commandline.nix index 76f115a..4c7c128 100644 --- a/common/commandline.nix +++ b/common/commandline.nix | |||
@@ -2,7 +2,7 @@ inputs: | |||
2 | 2 | ||
3 | { config, pkgs, lib, ... }: | 3 | { config, pkgs, lib, ... }: |
4 | 4 | ||
5 | with import ../lib/theme.nix { inherit lib; }; | 5 | with inputs.self.lib.theme; |
6 | let | 6 | let |
7 | dominantEscapeCode = fgEscapeCode config.theme.colors.dominant; | 7 | dominantEscapeCode = fgEscapeCode config.theme.colors.dominant; |
8 | bgDominantEscapeCode = bgEscapeCode config.theme.colors.dominant; | 8 | bgDominantEscapeCode = bgEscapeCode config.theme.colors.dominant; |
diff --git a/common/commandline/zsh.nix b/common/commandline/zsh.nix index b21c2c0..56bdbac 100644 --- a/common/commandline/zsh.nix +++ b/common/commandline/zsh.nix | |||
@@ -2,7 +2,7 @@ inputs: | |||
2 | 2 | ||
3 | { config, lib, pkgs, ... }: | 3 | { config, lib, pkgs, ... }: |
4 | 4 | ||
5 | with import ../../lib/theme.nix { inherit lib; }; | 5 | with inputs.self.lib.theme; |
6 | let | 6 | let |
7 | dominantEscapeCode = fgEscapeCode config.theme.colors.dominant; | 7 | dominantEscapeCode = fgEscapeCode config.theme.colors.dominant; |
8 | in | 8 | in |
@@ -16,6 +16,8 @@ | |||
16 | 16 | ||
17 | outputs = inputs @ { self, nixpkgs, home-manager, ... }: { | 17 | outputs = inputs @ { self, nixpkgs, home-manager, ... }: { |
18 | 18 | ||
19 | lib = import ./lib { inherit (nixpkgs) lib; }; | ||
20 | |||
19 | nixosModules = { | 21 | nixosModules = { |
20 | default = { ... }: { | 22 | default = { ... }: { |
21 | imports = [ | 23 | imports = [ |
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 | } | ||