-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlib.nix
52 lines (47 loc) · 1.2 KB
/
lib.nix
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
let
toLua =
with builtins;
val:
if val == null then
"nil"
else if isString val || isBool val || isInt val || isFloat val then
toJSON val
else if isPath val then
"assert(loadfile('${val}'))()"
else if isAttrs val then
if val ? type && val.type == "derivation" then
toLua "${val}"
else if val ? type && val.type == "lua" then
val.expression
else
"{" + (concatStringsSep "," (map (k: "[${toLua k}]=" + (toLua val.${k})) (attrNames val))) + "}"
else if isList val then
"{" + (concatStringsSep "," (map toLua val)) + "}"
else
throw "type convertion is not implemented";
modules = pkgs: [
{
_module.args = {
inherit pkgs;
};
}
./module.nix
];
in
{
inherit toLua modules;
luaExpr = lua: {
type = "lua";
expression = lua;
};
toLuaFn = fn: args: "${fn}(${builtins.concatStringsSep "," (map toLua args)})";
toKeymap =
def_opts:
builtins.foldl' (f: f) (
mode: lhs: rhs: opts: {
inherit mode lhs rhs;
opts = def_opts // opts;
}
);
toRc = pkgs: config: (pkgs.lib.evalModules { modules = (modules pkgs) ++ [ config ]; }).config.out;
}