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.5 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
, neovimPlugins
2024-04-18 01:20:31 +03:00
, pkgs
2022-11-30 22:49:32 +03:00
, 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;
2024-04-18 01:20:31 +03:00
modules' = modules;
2024-04-16 16:17:45 +03:00
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';
2024-04-18 01:20:31 +03:00
modules = mergeAttrs modules';
2023-05-23 00:19:13 +03:00
2024-04-18 01:20:31 +03:00
importModule = moduleName: import (./modules + "/${moduleName}.nix") { inherit nix2lua pkgs; };
2024-04-17 19:35:34 +03:00
allModules = mergeAttrs (lib.mapAttrsToList importModule modules);
2024-04-16 16:17:45 +03:00
2024-04-18 01:20:31 +03:00
# Type: excludeOverride :: AttrSet -> AttrSet
excludeOverride = lib.filterAttrs (n: v: n != "override'");
# Type: pluginsWithModules :: AttrSet
pluginsWithModules = mergeAttrs [ (excludeOverride allModules) plugins ];
2024-04-17 19:35:34 +03:00
2024-04-18 01:20:31 +03:00
overridedNeovimPlugins =
if allModules ? override' then neovimPlugins // allModules.override'
else neovimPlugins;
2024-04-17 19:35:34 +03:00
2024-04-18 01:20:31 +03:00
# Type: getPluginByName :: string -> derivation
getPluginByName = lib.flip lib.getAttr overridedNeovimPlugins;
# Type: allPlugins :: AttrSet -> [derivation]
2024-04-17 19:35:34 +03:00
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-18 00:04:06 +03:00
inherit plugins modules;
2022-11-30 22:49:32 +03:00
};
})