2023-02-10 17:39:31 +00:00
|
|
|
inputs: {
|
2023-02-01 19:11:37 +00:00
|
|
|
configuration,
|
|
|
|
pkgs,
|
2024-07-11 22:49:44 +00:00
|
|
|
lib,
|
2023-02-01 19:11:37 +00:00
|
|
|
check ? true,
|
|
|
|
extraSpecialArgs ? {},
|
2024-04-20 20:42:48 +00:00
|
|
|
extraModules ? [],
|
2023-02-01 19:11:37 +00:00
|
|
|
}: let
|
2024-07-13 15:05:21 +00:00
|
|
|
inherit (pkgs) vimPlugins;
|
2023-10-03 17:48:09 +00:00
|
|
|
inherit (pkgs.vimUtils) buildVimPlugin;
|
2024-07-13 15:05:21 +00:00
|
|
|
inherit (lib.strings) isString toString;
|
|
|
|
inherit (lib.lists) filter map concatLists;
|
|
|
|
inherit (lib.attrsets) recursiveUpdate getAttr;
|
2024-04-09 06:55:45 +00:00
|
|
|
inherit (lib.asserts) assertMsg;
|
2023-02-01 19:11:37 +00:00
|
|
|
|
2024-04-20 20:42:48 +00:00
|
|
|
# import modules.nix with `check`, `pkgs` and `lib` as arguments
|
|
|
|
# check can be disabled while calling this file is called
|
|
|
|
# to avoid checking in all modules
|
2023-02-01 19:11:37 +00:00
|
|
|
nvimModules = import ./modules.nix {
|
2024-07-11 22:49:44 +00:00
|
|
|
inherit pkgs check lib;
|
2023-02-01 19:11:37 +00:00
|
|
|
};
|
|
|
|
|
2024-04-20 20:42:48 +00:00
|
|
|
# evaluate the extended library with the modules
|
|
|
|
# optionally with any additional modules passed by the user
|
2024-07-11 22:49:44 +00:00
|
|
|
module = lib.evalModules {
|
2024-04-07 15:31:06 +00:00
|
|
|
specialArgs = recursiveUpdate {modulesPath = toString ./.;} extraSpecialArgs;
|
2024-04-20 20:42:48 +00:00
|
|
|
modules = concatLists [[configuration] nvimModules extraModules];
|
2023-02-01 19:11:37 +00:00
|
|
|
};
|
|
|
|
|
2024-04-20 20:42:48 +00:00
|
|
|
# alias to the internal configuration
|
2023-11-06 09:33:38 +00:00
|
|
|
vimOptions = module.config.vim;
|
|
|
|
|
2024-04-20 20:42:48 +00:00
|
|
|
# build a vim plugin with the given name and arguments
|
|
|
|
# if the plugin is nvim-treesitter, warn the user to use buildTreesitterPlug
|
|
|
|
# instead
|
2024-07-13 22:04:10 +00:00
|
|
|
buildPlug = {pname, ...} @ attrs: let
|
|
|
|
src = getAttr ("plugin-" + pname) inputs;
|
|
|
|
in
|
2024-07-16 08:00:50 +00:00
|
|
|
pkgs.runCommand "${pname}-${src.shortRev or src.shortDirtyRev or "dirty"}" attrs
|
2024-07-13 22:04:10 +00:00
|
|
|
''
|
|
|
|
mkdir -p $out
|
2024-07-16 08:00:50 +00:00
|
|
|
cp -r ${src}/. $out
|
2024-07-13 22:04:10 +00:00
|
|
|
'';
|
|
|
|
|
|
|
|
noBuildPlug = {pname, ...} @ attrs: let
|
|
|
|
input = getAttr ("plugin-" + pname) inputs;
|
|
|
|
in
|
|
|
|
{
|
|
|
|
version = input.shortRev or input.shortDirtyRev or "dirty";
|
|
|
|
outPath = getAttr ("plugin-" + pname) inputs;
|
|
|
|
}
|
|
|
|
// attrs;
|
2023-02-01 19:11:37 +00:00
|
|
|
|
|
|
|
buildTreesitterPlug = grammars: vimPlugins.nvim-treesitter.withPlugins (_: grammars);
|
|
|
|
|
|
|
|
buildConfigPlugins = plugins:
|
|
|
|
map
|
|
|
|
(plug: (
|
|
|
|
if (isString plug)
|
|
|
|
then
|
|
|
|
(
|
|
|
|
if (plug == "nvim-treesitter")
|
|
|
|
then (buildTreesitterPlug vimOptions.treesitter.grammars)
|
2023-06-25 12:09:12 +00:00
|
|
|
else if (plug == "flutter-tools-patched")
|
|
|
|
then
|
2024-07-13 22:04:10 +00:00
|
|
|
(
|
|
|
|
buildPlug
|
|
|
|
{
|
|
|
|
pname = "flutter-tools";
|
|
|
|
patches = [../patches/flutter-tools.patch];
|
|
|
|
}
|
|
|
|
)
|
|
|
|
else noBuildPlug {pname = plug;}
|
2023-02-01 19:11:37 +00:00
|
|
|
)
|
|
|
|
else plug
|
|
|
|
))
|
|
|
|
(filter
|
|
|
|
(f: f != null)
|
|
|
|
plugins);
|
|
|
|
|
2024-04-20 20:42:48 +00:00
|
|
|
# built (or "normalized") plugins that are modified
|
|
|
|
builtStartPlugins = buildConfigPlugins vimOptions.startPlugins;
|
|
|
|
builtOptPlugins = map (package: {
|
|
|
|
plugin = package;
|
2024-07-09 23:37:07 +00:00
|
|
|
optional = true;
|
2024-04-20 20:42:48 +00:00
|
|
|
}) (buildConfigPlugins vimOptions.optPlugins);
|
|
|
|
|
2024-04-21 00:21:48 +00:00
|
|
|
# additional Lua and Python3 packages, mapped to their respective functions
|
|
|
|
# to conform to the format makeNeovimConfig expects. end user should
|
|
|
|
# only ever need to pass a list of packages, which are modified
|
|
|
|
# here
|
2024-04-20 20:42:48 +00:00
|
|
|
extraLuaPackages = ps: map (x: ps.${x}) vimOptions.luaPackages;
|
2024-04-20 23:23:07 +00:00
|
|
|
extraPython3Packages = ps: map (x: ps.${x}) vimOptions.python3Packages;
|
2024-04-20 20:42:48 +00:00
|
|
|
|
2024-07-13 15:05:21 +00:00
|
|
|
# Wrap the user's desired (unwrapped) Neovim package with arguments that'll be used to
|
|
|
|
# generate a wrapped Neovim package.
|
2024-07-14 03:47:21 +00:00
|
|
|
neovim-wrapped = inputs.mnw.lib.wrap pkgs {
|
2024-07-13 15:05:21 +00:00
|
|
|
neovim = vimOptions.package;
|
|
|
|
plugins = concatLists [builtStartPlugins builtOptPlugins];
|
2024-07-13 22:04:10 +00:00
|
|
|
appName = "nvf";
|
2024-07-13 15:05:21 +00:00
|
|
|
extraBinPath = vimOptions.extraPackages;
|
2024-07-20 08:30:48 +00:00
|
|
|
initLua = vimOptions.builtLuaConfigRC;
|
|
|
|
luaFiles = vimOptions.extraLuaFiles;
|
2024-04-21 00:21:48 +00:00
|
|
|
|
2024-04-20 23:23:07 +00:00
|
|
|
inherit (vimOptions) viAlias vimAlias withRuby withNodeJs withPython3;
|
2024-07-13 15:05:21 +00:00
|
|
|
inherit extraLuaPackages extraPython3Packages;
|
2024-04-21 00:21:48 +00:00
|
|
|
};
|
2024-07-20 13:01:40 +00:00
|
|
|
|
|
|
|
# Additional helper scripts for printing and displaying nvf configuration
|
|
|
|
# in your commandline.
|
|
|
|
printConfig = pkgs.writers.writeDashBin "print-nvf-config" ''
|
|
|
|
cat << EOF
|
|
|
|
${vimOptions.builtLuaConfigRC}
|
|
|
|
EOF
|
|
|
|
'';
|
|
|
|
|
|
|
|
printConfigPath = pkgs.writers.writeDashBin "print-nvf-config-path" ''
|
|
|
|
realpath ${pkgs.writeTextFile {
|
|
|
|
name = "nvf-init.lua";
|
|
|
|
text = vimOptions.builtLuaConfigRC;
|
|
|
|
}}
|
|
|
|
'';
|
2023-02-01 19:11:37 +00:00
|
|
|
in {
|
|
|
|
inherit (module) options config;
|
|
|
|
inherit (module._module.args) pkgs;
|
2024-04-20 20:42:48 +00:00
|
|
|
|
2024-07-20 13:01:40 +00:00
|
|
|
# Expose wrapped neovim-package for userspace
|
|
|
|
# or module consumption.
|
|
|
|
neovim = pkgs.symlinkJoin {
|
|
|
|
name = "nvf-with-helpers";
|
|
|
|
paths = [neovim-wrapped printConfig printConfigPath];
|
|
|
|
postBuild = "echo helpers added";
|
2024-07-20 13:55:56 +00:00
|
|
|
|
|
|
|
meta = {
|
|
|
|
description = "Wrapped version of Neovim with additional helper scripts";
|
|
|
|
mainProgram = "nvim";
|
|
|
|
};
|
2024-07-20 13:01:40 +00:00
|
|
|
};
|
2023-02-01 19:11:37 +00:00
|
|
|
}
|