mirror of
https://github.com/NotAShelf/neovim-flake.git
synced 2025-01-08 09:09:49 +01:00
module: remove redundant code
the bulk of the build step is moved to modules/wrapper/build
This commit is contained in:
parent
c7f4dd19ca
commit
da26ea78b2
1 changed files with 9 additions and 96 deletions
|
@ -9,9 +9,8 @@
|
||||||
extraModules ? [],
|
extraModules ? [],
|
||||||
configuration ? {},
|
configuration ? {},
|
||||||
}: let
|
}: let
|
||||||
inherit (pkgs) vimPlugins;
|
inherit (lib.strings) toString;
|
||||||
inherit (lib.strings) isString toString;
|
inherit (lib.lists) concatLists;
|
||||||
inherit (lib.lists) filter map concatLists;
|
|
||||||
|
|
||||||
# import modules.nix with `check`, `pkgs` and `lib` as arguments
|
# import modules.nix with `check`, `pkgs` and `lib` as arguments
|
||||||
# check can be disabled while calling this file is called
|
# check can be disabled while calling this file is called
|
||||||
|
@ -21,7 +20,12 @@
|
||||||
# evaluate the extended library with the modules
|
# evaluate the extended library with the modules
|
||||||
# optionally with any additional modules passed by the user
|
# optionally with any additional modules passed by the user
|
||||||
module = lib.evalModules {
|
module = lib.evalModules {
|
||||||
specialArgs = extraSpecialArgs // {modulesPath = toString ./.;};
|
specialArgs =
|
||||||
|
extraSpecialArgs
|
||||||
|
// {
|
||||||
|
inherit inputs;
|
||||||
|
modulesPath = toString ./.;
|
||||||
|
};
|
||||||
modules = concatLists [
|
modules = concatLists [
|
||||||
nvimModules
|
nvimModules
|
||||||
modules
|
modules
|
||||||
|
@ -36,102 +40,11 @@
|
||||||
extraModules))
|
extraModules))
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
|
|
||||||
# alias to the internal configuration
|
|
||||||
vimOptions = module.config.vim;
|
|
||||||
|
|
||||||
noBuildPlug = {pname, ...} @ attrs: let
|
|
||||||
src = inputs."plugin-${attrs.pname}";
|
|
||||||
in
|
|
||||||
{
|
|
||||||
version = src.shortRev or src.shortDirtyRev or "dirty";
|
|
||||||
outPath = src;
|
|
||||||
passthru.vimPlugin = false;
|
|
||||||
}
|
|
||||||
// attrs;
|
|
||||||
|
|
||||||
# build a vim plugin with the given name and arguments
|
|
||||||
# if the plugin is nvim-treesitter, warn the user to use buildTreesitterPlug
|
|
||||||
# instead
|
|
||||||
buildPlug = attrs: let
|
|
||||||
src = inputs."plugin-${attrs.pname}";
|
|
||||||
in
|
|
||||||
pkgs.vimUtils.buildVimPlugin (
|
|
||||||
{
|
|
||||||
version = src.shortRev or src.shortDirtyRev or "dirty";
|
|
||||||
inherit src;
|
|
||||||
}
|
|
||||||
// attrs
|
|
||||||
);
|
|
||||||
|
|
||||||
buildTreesitterPlug = grammars: vimPlugins.nvim-treesitter.withPlugins (_: grammars);
|
|
||||||
|
|
||||||
pluginBuilders = {
|
|
||||||
nvim-treesitter = buildTreesitterPlug vimOptions.treesitter.grammars;
|
|
||||||
flutter-tools-patched = buildPlug {
|
|
||||||
pname = "flutter-tools";
|
|
||||||
patches = [../patches/flutter-tools.patch];
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
buildConfigPlugins = plugins:
|
|
||||||
map (
|
|
||||||
plug:
|
|
||||||
if (isString plug)
|
|
||||||
then pluginBuilders.${plug} or (noBuildPlug {pname = plug;})
|
|
||||||
else plug
|
|
||||||
) (filter (f: f != null) plugins);
|
|
||||||
|
|
||||||
# built (or "normalized") plugins that are modified
|
|
||||||
builtStartPlugins = buildConfigPlugins vimOptions.startPlugins;
|
|
||||||
builtOptPlugins = map (package: package // {optional = true;}) (buildConfigPlugins vimOptions.optPlugins);
|
|
||||||
|
|
||||||
# additional Lua and Python3 packages, mapped to their respective functions
|
|
||||||
# to conform to the format mnw expects. end user should
|
|
||||||
# only ever need to pass a list of packages, which are modified
|
|
||||||
# here
|
|
||||||
extraLuaPackages = ps: map (x: ps.${x}) vimOptions.luaPackages;
|
|
||||||
extraPython3Packages = ps: map (x: ps.${x}) vimOptions.python3Packages;
|
|
||||||
|
|
||||||
# Wrap the user's desired (unwrapped) Neovim package with arguments that'll be used to
|
|
||||||
# generate a wrapped Neovim package.
|
|
||||||
neovim-wrapped = inputs.mnw.lib.wrap pkgs {
|
|
||||||
neovim = vimOptions.package;
|
|
||||||
plugins = builtStartPlugins ++ builtOptPlugins;
|
|
||||||
appName = "nvf";
|
|
||||||
extraBinPath = vimOptions.extraPackages;
|
|
||||||
initLua = vimOptions.builtLuaConfigRC;
|
|
||||||
luaFiles = vimOptions.extraLuaFiles;
|
|
||||||
|
|
||||||
inherit (vimOptions) viAlias vimAlias withRuby withNodeJs withPython3;
|
|
||||||
inherit extraLuaPackages extraPython3Packages;
|
|
||||||
};
|
|
||||||
|
|
||||||
dummyInit = pkgs.writeText "nvf-init.lua" vimOptions.builtLuaConfigRC;
|
|
||||||
# Additional helper scripts for printing and displaying nvf configuration
|
|
||||||
# in your commandline.
|
|
||||||
printConfig = pkgs.writers.writeDashBin "nvf-print-config" "cat ${dummyInit}";
|
|
||||||
printConfigPath = pkgs.writers.writeDashBin "nvf-print-config-path" "echo -n ${dummyInit}";
|
|
||||||
in {
|
in {
|
||||||
inherit (module) options config;
|
inherit (module) options config;
|
||||||
inherit (module._module.args) pkgs;
|
inherit (module._module.args) pkgs;
|
||||||
|
|
||||||
# Expose wrapped neovim-package for userspace
|
# Expose wrapped neovim-package for userspace
|
||||||
# or module consumption.
|
# or module consumption.
|
||||||
neovim = pkgs.symlinkJoin {
|
neovim = module.config.vim.build.finalPackage;
|
||||||
name = "nvf-with-helpers";
|
|
||||||
paths = [neovim-wrapped printConfig printConfigPath];
|
|
||||||
postBuild = "echo Helpers added";
|
|
||||||
|
|
||||||
# Allow evaluating vimOptions, i.e., config.vim from the packages' passthru
|
|
||||||
# attribute. For example, packages.x86_64-linux.neovim.passthru.neovimConfig
|
|
||||||
# will return the configuration in full.
|
|
||||||
passthru.neovimConfig = vimOptions;
|
|
||||||
|
|
||||||
meta =
|
|
||||||
neovim-wrapped.meta
|
|
||||||
// {
|
|
||||||
description = "Wrapped Neovim package with helper scripts to print the config (path)";
|
|
||||||
};
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue