-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdefault.nix
More file actions
68 lines (62 loc) · 1.33 KB
/
Copy pathdefault.nix
File metadata and controls
68 lines (62 loc) · 1.33 KB
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
let
inherit (builtins)
isString
isBool
isInt
isFloat
isPath
isAttrs
isList
concatStringsSep
attrNames
toJSON
elemAt
;
toLua =
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 isList val then
"{" + (concatStringsSep "," (map toLua val)) + "}"
else if isAttrs val then
if val.type or null == "derivation" then
toJSON (toString val)
else if val.type or null == "lua" then
val.expression
else
"{" + (concatStringsSep "," (map (k: "[${toLua k}]=" + (toLua val.${k})) (attrNames val))) + "}"
else
throw "type conversion 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}(${concatStringsSep "," (map toLua args)})";
toKeymap =
def_opts: args:
let
at = elemAt args;
in
{
mode = at 0;
lhs = at 1;
rhs = at 2;
opts = def_opts // at 3;
};
toRc =
pkgs: config:
(pkgs.lib.evalModules {
modules = modules pkgs ++ [ config ];
}).config.out;
}