This repository has been archived on 2024-05-17. You can view files and clone it, but cannot push or open issues or pull requests.
neovim/neovim.nix

96 lines
2.7 KiB
Nix

{ viAlias ? false
, vimAlias ? false
, extraConfig ? ""
, extraLuaConfig ? ""
, wrapNeovim
, neovim-unwrapped
, neovimPlugins
, pkgs
, lib
, nix2lua
, plugins ? { }
, modules ? { }
, ...
}:
let
plugins' = plugins;
modules' = modules;
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';
modules = mergeAttrs modules';
importModule = moduleName: import (./modules + "/${moduleName}.nix") { inherit nix2lua pkgs; };
allModules = mergeAttrs (lib.mapAttrsToList importModule modules);
# Type: excludeOverride :: AttrSet -> AttrSet
excludeOverride = lib.filterAttrs (n: v: n != "override'");
# Type: pluginsWithModules :: AttrSet
pluginsWithModules = mergeAttrs [ (excludeOverride allModules) plugins ];
overridedNeovimPlugins =
if allModules ? override' then neovimPlugins // allModules.override'
else neovimPlugins;
# Type: getPluginByName :: string -> derivation
getPluginByName = lib.flip lib.getAttr overridedNeovimPlugins;
# Type: allPlugins :: AttrSet -> [derivation]
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 && cfg ? _type then toLua cfg
else if lib.isList cfg then toLua (concatLines cfg)
else if lib.isBool cfg then "" # Just skip lua config. Only enable the plugin.
else abort "[neovim] mkPluginLuaConfig: '${name}' has unsupported type '${builtins.typeOf cfg}'");
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 modules;
};
})