81 lines
2.0 KiB
Nix
81 lines
2.0 KiB
Nix
{pkgs, ...}: let
|
|
inherit (builtins) foldl' isPath;
|
|
inherit (pkgs) vimUtils;
|
|
inherit (pkgs.lib) fileContents fix optionalAttrs;
|
|
|
|
fs = pkgs.lib.fileset;
|
|
|
|
lua = import ../lua.nix {};
|
|
|
|
versionLua = version: with lua; nix2lua (return (lambda (return version)));
|
|
pluginsLuaDef = plugins:
|
|
with lua; nix2lua (return (foldl' pluginLuaDef {} plugins));
|
|
|
|
textOrContent = content:
|
|
if isPath content
|
|
then fileContents content
|
|
else content;
|
|
|
|
pluginLuaDef = memo: plugin: let
|
|
mkTypeFn = type: let
|
|
content = textOrContent plugin.${type};
|
|
in
|
|
optionalAttrs (! isNull plugin.${type}) {
|
|
${type} = with lua; lambda (raw content);
|
|
};
|
|
pluginName = plugin:
|
|
if plugin ? pname
|
|
then plugin.pname
|
|
else plugin.name;
|
|
name = pluginName plugin.plugin;
|
|
in
|
|
memo
|
|
// {
|
|
${name} =
|
|
{
|
|
name = pluginName plugin.plugin;
|
|
dependencies = map pluginName plugin.dependencies;
|
|
}
|
|
// (mkTypeFn "init")
|
|
// (mkTypeFn "config")
|
|
// (optionalAttrs plugin.lazy {
|
|
lazy = true;
|
|
})
|
|
// (optionalAttrs plugin.hasCommands {
|
|
inherit (plugin) cmd;
|
|
})
|
|
// (optionalAttrs plugin.hasFileTypes {
|
|
inherit (plugin) ft;
|
|
})
|
|
// (optionalAttrs plugin.hasEvents {
|
|
inherit (plugin) events;
|
|
})
|
|
// (optionalAttrs plugin.hasKeymaps {
|
|
inherit (plugin) keymaps;
|
|
});
|
|
};
|
|
in
|
|
fix (self: {
|
|
mkPlugin = version: plugins:
|
|
vimUtils.buildVimPlugin {
|
|
inherit version;
|
|
pname = "sloth-flake";
|
|
src = fs.toSource {
|
|
root = ../..;
|
|
fileset = ../../lua/sloth-flake;
|
|
};
|
|
nvimRequireCheck = "sloth-flake";
|
|
buildPhase = ''
|
|
dir=lua/sloth-flake
|
|
|
|
cat <<'LUA' > $dir/dependencies.lua
|
|
${pluginsLuaDef plugins}
|
|
LUA
|
|
|
|
cat <<'LUA' > $dir/version.lua
|
|
${versionLua version}
|
|
LUA
|
|
'';
|
|
};
|
|
})
|