summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--common/commandline.nix2
-rw-r--r--common/commandline/zsh.nix2
-rw-r--r--flake.nix2
-rw-r--r--lib/default.nix6
-rw-r--r--lib/generators.nix41
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
5with import ../lib/theme.nix { inherit lib; }; 5with inputs.self.lib.theme;
6let 6let
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
5with import ../../lib/theme.nix { inherit lib; }; 5with inputs.self.lib.theme;
6let 6let
7 dominantEscapeCode = fgEscapeCode config.theme.colors.dominant; 7 dominantEscapeCode = fgEscapeCode config.theme.colors.dominant;
8in 8in
diff --git a/flake.nix b/flake.nix
index 8ff3896..b6e2b02 100644
--- a/flake.nix
+++ b/flake.nix
@@ -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 @@
1attrs:
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
3with 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}