From 43760a34e578cd93480a27c9513eb9e35991e10d Mon Sep 17 00:00:00 2001 From: Minijackson Date: Wed, 16 Jun 2021 23:02:31 +0200 Subject: lib: init with theme and generators --- common/commandline.nix | 2 +- common/commandline/zsh.nix | 2 +- flake.nix | 2 ++ lib/default.nix | 6 ++++++ lib/generators.nix | 41 +++++++++++++++++++++++++++++++++++++++++ 5 files changed, 51 insertions(+), 2 deletions(-) create mode 100644 lib/default.nix create mode 100644 lib/generators.nix 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: { config, pkgs, lib, ... }: -with import ../lib/theme.nix { inherit lib; }; +with inputs.self.lib.theme; let dominantEscapeCode = fgEscapeCode config.theme.colors.dominant; 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: { config, lib, pkgs, ... }: -with import ../../lib/theme.nix { inherit lib; }; +with inputs.self.lib.theme; let dominantEscapeCode = fgEscapeCode config.theme.colors.dominant; in diff --git a/flake.nix b/flake.nix index 8ff3896..b6e2b02 100644 --- a/flake.nix +++ b/flake.nix @@ -16,6 +16,8 @@ outputs = inputs @ { self, nixpkgs, home-manager, ... }: { + lib = import ./lib { inherit (nixpkgs) lib; }; + nixosModules = { default = { ... }: { 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 @@ +attrs: + +{ + generators = import ./generators.nix attrs; + theme = import ./theme.nix attrs; +} 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 @@ +{ lib, ... }: + +with lib; + +{ + lua = {}: rec { + type = with types; let + valueType = nullOr + (oneOf [ + bool + int + float + str + (attrsOf valueType) + (listOf valueType) + ]) // { + description = "Lua value"; + }; in + valueType; + + lib = { + mkRaw = value: { inherit value; _type = "raw"; }; + }; + + generate = value: + let + list = l: "{ ${concatMapStringsSep ", " generate l} }"; + attrs = a: "{ ${concatStringsSep ", " (mapAttrsToList (name: value: "[${generate name}] = ${generate value}") a)} }"; + in + if value ? _type && value._type == "raw" then value.value + else if isInt value then toString value + else if isFloat value then toString value + else if isString value then "'${escape [ "'" ] value }'" + else if true == value then "true" + else if false == value then "false" + else if null == value then "nil" + else if isList value then list value + else if isAttrs value then attrs value + else abort "Lua value not supported: ${toPretty value}"; + }; +} -- cgit v1.2.3