89 lines
2.2 KiB
Nix
89 lines
2.2 KiB
Nix
{ viAlias ? false
|
|
, vimAlias ? false
|
|
, extraConfig ? ""
|
|
, extraLuaConfig ? ""
|
|
, wrapNeovim
|
|
, neovim-unwrapped
|
|
, tree-sitter
|
|
, neovimPlugins
|
|
, lib
|
|
, nix2lua
|
|
, plugins ? { }
|
|
, modules ? { }
|
|
, ...
|
|
}:
|
|
|
|
|
|
let
|
|
plugins' = plugins;
|
|
|
|
mergeAttrs = v:
|
|
if builtins.isList v then
|
|
lib.foldl lib.recursiveUpdate { } (map mergeAttrs v)
|
|
else if v ? _type then
|
|
if v._type == "merge" then mergeAttrs v.contents
|
|
else if v._type == "if" then lib.optionalAttrs v.condition v.content
|
|
else builtins.abort "Unsupported attribute"
|
|
else v;
|
|
in
|
|
let
|
|
plugins = mergeAttrs plugins';
|
|
|
|
importModule = moduleName: import (./modules + "/${moduleName}.nix") { inherit nix2lua; };
|
|
|
|
allModules = mergeAttrs (lib.mapAttrsToList importModule modules);
|
|
|
|
pluginsWithModules = mergeAttrs [ allModules plugins ];
|
|
|
|
|
|
/*
|
|
Type: getPluginByName :: string -> derivation
|
|
*/
|
|
getPluginByName = lib.flip lib.getAttr neovimPlugins;
|
|
allPlugins = map getPluginByName (lib.attrNames pluginsWithModules);
|
|
|
|
/*
|
|
Type: mkPluginLuaConfig :: string -> a -> string
|
|
*/
|
|
mkPluginLuaConfig = name: cfg:
|
|
with nix2lua.lib;
|
|
"-- Plugin: ${builtins.trace "Plugin: ${name}" name}\n"
|
|
+ (if lib.isString cfg then cfg
|
|
else if lib.isAttrs cfg then toLua cfg
|
|
else if lib.isList cfg then toLua (concatLines cfg)
|
|
else abort "[neovim] mkPluginLuaConfig: unsupported type");
|
|
pluginLuaConfigs = lib.mapAttrsToList mkPluginLuaConfig pluginsWithModules;
|
|
|
|
basicLuaConfigs = map builtins.readFile [ ./config/basic.lua ];
|
|
|
|
allLuaConfigs = basicLuaConfigs ++ pluginLuaConfigs;
|
|
|
|
/*
|
|
Type: mkLuaHeredoc :: string -> string
|
|
*/
|
|
mkLuaHeredoc = content: lib.concatLines [ "lua << EOF" content "EOF" ];
|
|
|
|
/*
|
|
Type: mkLuaRc :: [string] -> string
|
|
*/
|
|
mkLuaRc = list: lib.concatLines (map mkLuaHeredoc list);
|
|
in
|
|
(wrapNeovim neovim-unwrapped {
|
|
inherit viAlias;
|
|
inherit vimAlias;
|
|
|
|
withPython3 = false;
|
|
withNodeJs = false;
|
|
withRuby = false;
|
|
|
|
configure = {
|
|
customRC = extraConfig + mkLuaRc allLuaConfigs;
|
|
|
|
packages.myVimPackages = { start = allPlugins; };
|
|
};
|
|
}).overrideAttrs (oldAttrs: {
|
|
passthru = oldAttrs.passthru // {
|
|
nix2lua = nix2lua.lib;
|
|
inherit plugins;
|
|
};
|
|
})
|