2023-06-09 14:37:25 +03:00
|
|
|
{ lib, substituteAll, ... }:
|
2022-10-22 23:35:27 +03:00
|
|
|
|
2022-09-24 17:21:16 +03:00
|
|
|
let
|
|
|
|
inherit (builtins) length elemAt isList isString hasAttr getAttr;
|
|
|
|
|
|
|
|
###########################################################################
|
2022-09-15 09:57:11 +03:00
|
|
|
# Helpers
|
|
|
|
|
|
|
|
# Source: https://github.com/NixOS/nixpkgs/blob/d61bc96d16ca288c69b798b8e31eca64050098e3/lib/lists.nix
|
|
|
|
foldr = op: nul: list:
|
|
|
|
let
|
2022-09-24 17:21:16 +03:00
|
|
|
len = length list;
|
2022-09-15 09:57:11 +03:00
|
|
|
fold' = n:
|
|
|
|
if n == len
|
|
|
|
then nul
|
2022-09-24 17:21:16 +03:00
|
|
|
else op (elemAt list n) (fold' (n + 1));
|
2022-09-15 09:57:11 +03:00
|
|
|
in
|
|
|
|
fold' 0;
|
|
|
|
|
2022-09-15 10:10:43 +03:00
|
|
|
concatMap = op: list:
|
|
|
|
let
|
|
|
|
concat = (a: b: op a + b);
|
|
|
|
in
|
|
|
|
foldr concat "" list;
|
|
|
|
|
2022-09-17 15:59:06 +03:00
|
|
|
############################################################################
|
|
|
|
# Configs
|
|
|
|
|
|
|
|
optional = cond: val:
|
2022-09-15 09:57:11 +03:00
|
|
|
let
|
2022-09-17 15:59:06 +03:00
|
|
|
def =
|
2022-09-24 17:21:16 +03:00
|
|
|
if isList val then [ ]
|
|
|
|
else if isString val then ""
|
2022-09-17 15:59:06 +03:00
|
|
|
else null;
|
2022-09-15 09:57:11 +03:00
|
|
|
in
|
2022-09-17 15:59:06 +03:00
|
|
|
if cond then val else def;
|
2022-09-15 09:57:11 +03:00
|
|
|
|
2022-09-24 17:21:16 +03:00
|
|
|
getAttrOpt = a: s:
|
|
|
|
if hasAttr a s then getAttr a s else null;
|
|
|
|
|
2022-09-15 09:57:11 +03:00
|
|
|
#############################################################################
|
|
|
|
# Lua
|
|
|
|
|
|
|
|
mkLuaHeredoc = content: ''
|
|
|
|
lua << EOF
|
|
|
|
${content}
|
|
|
|
EOF
|
|
|
|
'';
|
|
|
|
|
2022-09-15 10:10:43 +03:00
|
|
|
mkLuaRc = contents: concatMap mkLuaHeredoc contents;
|
2022-09-24 17:21:16 +03:00
|
|
|
|
2023-06-09 14:37:25 +03:00
|
|
|
############################################################################
|
|
|
|
# Configs
|
|
|
|
|
|
|
|
readSubFile = src: params: builtins.readFile
|
|
|
|
(substituteAll (params // { inherit src; }));
|
|
|
|
|
2022-09-24 17:21:16 +03:00
|
|
|
in
|
|
|
|
{
|
2022-11-19 00:56:53 +03:00
|
|
|
inherit (lib) importJSON attrByPath;
|
2022-09-24 17:21:16 +03:00
|
|
|
inherit foldr concatMap;
|
|
|
|
inherit optional getAttrOpt;
|
|
|
|
inherit mkLuaHeredoc mkLuaRc;
|
2023-06-09 14:37:25 +03:00
|
|
|
inherit readSubFile substituteAll;
|
2022-09-15 09:57:11 +03:00
|
|
|
}
|