40 lines
942 B
Nix
40 lines
942 B
Nix
|
rec {
|
||
|
#############################################################################
|
||
|
# Helpers
|
||
|
|
||
|
# Source: https://github.com/NixOS/nixpkgs/blob/d61bc96d16ca288c69b798b8e31eca64050098e3/lib/lists.nix
|
||
|
foldr = op: nul: list:
|
||
|
let
|
||
|
len = builtins.length list;
|
||
|
fold' = n:
|
||
|
if n == len
|
||
|
then nul
|
||
|
else op (builtins.elemAt list n) (fold' (n + 1));
|
||
|
in
|
||
|
fold' 0;
|
||
|
|
||
|
extractAttrs = attr: list:
|
||
|
let
|
||
|
getAttr' = builtins.getAttr attr;
|
||
|
hasAttr' = builtins.hasAttr attr;
|
||
|
filteredList = builtins.filter hasAttr' list;
|
||
|
in
|
||
|
builtins.map getAttr' filteredList;
|
||
|
|
||
|
#############################################################################
|
||
|
# Lua
|
||
|
|
||
|
mkLuaHeredoc = content: ''
|
||
|
lua << EOF
|
||
|
${content}
|
||
|
EOF
|
||
|
'';
|
||
|
|
||
|
mkLuaRc = contents:
|
||
|
let
|
||
|
concat = (a: b: a + b);
|
||
|
luaHeredors = builtins.map mkLuaHeredoc contents;
|
||
|
in
|
||
|
foldr concat "" luaHeredors;
|
||
|
}
|