116 lines
2.9 KiB
Nix
116 lines
2.9 KiB
Nix
{
|
|
version,
|
|
types,
|
|
}: {
|
|
pkgs,
|
|
package ? pkgs.neovim-unwrapped,
|
|
dependencies ? [],
|
|
dependenciesExtraArgs ? {},
|
|
extraLuaPackages ? (_: []),
|
|
runtime ? null,
|
|
init ? null,
|
|
viAlias ? false,
|
|
vimAlias ? false,
|
|
vimdiffAlias ? false,
|
|
nvimdiffAlias ? false,
|
|
...
|
|
} @ config: let
|
|
inherit (builtins) isString isPath map;
|
|
inherit (pkgs) callPackage bash lib;
|
|
inherit (lib.strings) optionalString;
|
|
inherit (lib.lists) concatMap optional;
|
|
inherit (lib.trivial) flip;
|
|
inherit (lib.attrsets) optionalAttrs;
|
|
|
|
deps = callPackage ./deps.nix {inherit dependenciesExtraArgs types;};
|
|
|
|
normalizedPlugins = deps.normalizePlugins dependencies;
|
|
sloth-flake = deps.mkSlothFlakePlugin version normalizedPlugins;
|
|
runtimePlugin = deps.mkRuntimePlugin runtime;
|
|
plugins =
|
|
normalizedPlugins
|
|
++ (
|
|
deps.normalizePlugins
|
|
([sloth-flake] ++ (optional (runtime != null) runtimePlugin))
|
|
);
|
|
|
|
extractPlugin = p: {inherit (p) optional plugin;};
|
|
extractPlugins = map extractPlugin;
|
|
|
|
extractLuaPackageFn = plugin:
|
|
optional (plugin ? extraLuaPackages) plugin.extraLuaPackages;
|
|
extractLuaPackagesFn = plugins: let
|
|
fnList = concatMap extractLuaPackageFn plugins;
|
|
concatPackages = ps: fn: fn ps;
|
|
in
|
|
ps: concatMap (concatPackages ps) fnList;
|
|
|
|
buildInit = {
|
|
init ? null,
|
|
postInit ? null,
|
|
config ? null,
|
|
}: let
|
|
initStr = optionalString (! isNull init) ''
|
|
(function()
|
|
${deps.textOrContent init}
|
|
end)();
|
|
|
|
'';
|
|
|
|
slothCall =
|
|
if isNull postInit
|
|
then "require('sloth-flake').setup {}"
|
|
else ''
|
|
require('sloth-flake').setup {
|
|
post_init = function()
|
|
${deps.textOrContent postInit}
|
|
end,
|
|
};
|
|
'';
|
|
|
|
configStr = optionalString (! isNull config) ''
|
|
|
|
(function()
|
|
${deps.textOrContent config}
|
|
end)()
|
|
'';
|
|
in ''
|
|
-- Generated by sloth-flake
|
|
${initStr}
|
|
${slothCall}
|
|
${configStr}
|
|
'';
|
|
|
|
customRC =
|
|
if isString init || isPath init
|
|
then deps.textOrContent init
|
|
else buildInit (optionalAttrs (! isNull init) init);
|
|
|
|
neovimConfig =
|
|
pkgs.neovimUtils.makeNeovimConfig {
|
|
inherit customRC;
|
|
plugins = extractPlugins plugins;
|
|
extraLuaPackages = ps:
|
|
(extractLuaPackagesFn plugins ps) ++ (extraLuaPackages ps);
|
|
}
|
|
// {luaRcContent = customRC;};
|
|
params =
|
|
removeAttrs neovimConfig ["manifestRc" "neovimRcContent"]
|
|
// {inherit viAlias vimAlias;};
|
|
pkg = pkgs.wrapNeovimUnstable package params;
|
|
mkDiffAlias = name:
|
|
(flip optionalString) ''
|
|
cat <<SH > $out/bin/${name}
|
|
#!${bash}/bin/bash
|
|
exec $out/bin/nvim -d "\''${@}"
|
|
SH
|
|
chmod 555 $out/bin/${name}
|
|
'';
|
|
in
|
|
builtins.seq (types.mkNeovimPkgOptions config) (pkg.overrideAttrs (final: super: {
|
|
postBuild =
|
|
super.postBuild
|
|
+ (mkDiffAlias "vimdiff" vimdiffAlias)
|
|
+ (mkDiffAlias "nvimdiff" nvimdiffAlias);
|
|
}))
|