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

90 lines
2.2 KiB
Nix
Raw Normal View History

2024-04-17 19:35:34 +03:00
{ viAlias ? false
2022-11-30 22:49:32 +03:00
, vimAlias ? false
2022-11-30 22:52:01 +03:00
, extraConfig ? ""
, extraLuaConfig ? ""
2022-11-30 22:49:32 +03:00
, wrapNeovim
, neovim-unwrapped
, tree-sitter
, neovimPlugins
, lib
, nix2lua
2024-04-17 19:35:34 +03:00
, plugins ? { }
, modules ? { }
2022-11-30 22:49:32 +03:00
, ...
}:
2024-04-17 19:35:34 +03:00
2022-11-30 22:49:32 +03:00
let
2024-04-16 16:17:45 +03:00
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';
2023-05-23 00:19:13 +03:00
2024-04-17 19:35:34 +03:00
importModule = moduleName: import (./modules + "/${moduleName}.nix") { inherit nix2lua; };
2022-11-30 22:49:32 +03:00
2024-04-17 19:35:34 +03:00
allModules = mergeAttrs (lib.mapAttrsToList importModule modules);
2024-04-16 16:17:45 +03:00
2024-04-17 19:35:34 +03:00
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" ];
2022-11-30 22:49:32 +03:00
2024-04-17 19:35:34 +03:00
/*
Type: mkLuaRc :: [string] -> string
*/
mkLuaRc = list: lib.concatLines (map mkLuaHeredoc list);
2022-11-30 22:49:32 +03:00
in
(wrapNeovim neovim-unwrapped {
inherit viAlias;
inherit vimAlias;
withPython3 = false;
2023-06-09 15:31:58 +03:00
withNodeJs = false;
2022-11-30 22:49:32 +03:00
withRuby = false;
configure = {
2024-04-17 19:35:34 +03:00
customRC = extraConfig + mkLuaRc allLuaConfigs;
2022-11-30 22:49:32 +03:00
packages.myVimPackages = { start = allPlugins; };
};
}).overrideAttrs (oldAttrs: {
passthru = oldAttrs.passthru // {
nix2lua = nix2lua.lib;
2024-04-17 19:35:34 +03:00
inherit plugins;
2022-11-30 22:49:32 +03:00
};
})