Compare commits

...

8 commits

Author SHA1 Message Date
diniamo
7d9c3e6cb6
Merge d48f52f065 into fd65c83956 2024-08-09 07:29:46 +00:00
diniamo
d48f52f065 fix: add Gerg's suggestion 2024-08-09 09:29:41 +02:00
diniamo
1340eb34a0 style: improve code clarity 2024-08-09 09:29:29 +02:00
diniamo
fa660627fc style: remove leftover commented code 2024-08-08 12:34:16 +02:00
diniamo
5c79c458fc feat: byte-compile plugins 2024-08-05 14:57:02 +02:00
diniamo
13cc59ab99 feat: use <<< instead of echo -n | 2024-08-05 14:10:31 +02:00
diniamo
97d49d331c feat: vim.byteCompileLua 2024-08-05 13:55:16 +02:00
diniamo
afa5e3594b feat: print-nvf-config(-path) -> nvf-print-config(-path) 2024-08-05 13:55:16 +02:00
3 changed files with 62 additions and 44 deletions

View file

@ -102,6 +102,8 @@ configuration formats.
yourself by adding `vim.opt.listchars:append({ eol = '<char>' })` to your yourself by adding `vim.opt.listchars:append({ eol = '<char>' })` to your
lua configuration lua configuration
- Pre-compile lua files using LuaJIT for performance. Can be disabled with `vim.byteCompileLua = false`.
[Neovim documentation on `vim.cmd`]: https://neovim.io/doc/user/lua.html#vim.cmd() [Neovim documentation on `vim.cmd`]: https://neovim.io/doc/user/lua.html#vim.cmd()
- Make Neovim's configuration file entirely Lua based. This comes with a few - Make Neovim's configuration file entirely Lua based. This comes with a few
@ -143,10 +145,10 @@ configuration formats.
- Add [neo-tree.nvim] as an alternative file-tree plugin. It will be available - Add [neo-tree.nvim] as an alternative file-tree plugin. It will be available
under `vim.filetree.neo-tree`, similar to nvimtree. under `vim.filetree.neo-tree`, similar to nvimtree.
- Add `print-nvf-config` & `print-nvf-config-path` helper scripts to Neovim - Add `nvf-print-config` & `nvf-print-config-path` helper scripts to Neovim
closure. Both of those scripts have been automatically added to your PATH upon closure. Both of those scripts have been automatically added to your PATH upon
using neovimConfig or `programs.nvf.enable`. using neovimConfig or `programs.nvf.enable`.
- `print-nvf-config` will display your `init.lua`, in full. - `nvf-print-config` will display your `init.lua`, in full.
- `print-nvf-config-path` will display the path to _a clone_ of your - `nvf-print-config-path` will display the path to _a clone_ of your
`init.lua`. This is not the path used by the Neovim wrapper, but an `init.lua`. This is not the path used by the Neovim wrapper, but an
identical clone. identical clone.

View file

@ -7,11 +7,10 @@ inputs: {
extraModules ? [], extraModules ? [],
}: let }: let
inherit (pkgs) vimPlugins; inherit (pkgs) vimPlugins;
inherit (pkgs.vimUtils) buildVimPlugin;
inherit (lib.strings) isString toString; inherit (lib.strings) isString toString;
inherit (lib.lists) filter map concatLists; inherit (lib.lists) filter map concatLists;
inherit (lib.attrsets) recursiveUpdate getAttr; inherit (lib.attrsets) recursiveUpdate;
inherit (lib.asserts) assertMsg; inherit (builtins) baseNameOf;
# 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
@ -33,12 +32,27 @@ inputs: {
# build a vim plugin with the given name and arguments # build a vim plugin with the given name and arguments
# if the plugin is nvim-treesitter, warn the user to use buildTreesitterPlug # if the plugin is nvim-treesitter, warn the user to use buildTreesitterPlug
# instead # instead
buildPlug = {pname, ...} @ attrs: let buildPlug = attrs: let
src = getAttr ("plugin-" + pname) inputs; src = inputs."plugin-${attrs.pname}";
in in
pkgs.stdenvNoCC.mkDerivation ({ pkgs.stdenvNoCC.mkDerivation ({
inherit src;
version = src.shortRev or src.shortDirtyRev or "dirty"; version = src.shortRev or src.shortDirtyRev or "dirty";
inherit src;
nativeBuildInputs = with pkgs.vimUtils; [
vimCommandCheckHook
vimGenDocHook
neovimRequireCheckHook
];
passthru.vimPlugin = true;
buildPhase = lib.optionalString vimOptions.byteCompileLua ''
runHook preBuild
find . -type f -name '*.lua' -exec luajit -bd -- {} {} \;
runHook postBuild
'';
installPhase = '' installPhase = ''
runHook preInstall runHook preInstall
@ -50,41 +64,27 @@ inputs: {
} }
// attrs); // attrs);
noBuildPlug = {pname, ...} @ attrs: let
input = getAttr ("plugin-" + pname) inputs;
in
{
version = input.shortRev or input.shortDirtyRev or "dirty";
outPath = getAttr ("plugin-" + pname) inputs;
}
// attrs;
buildTreesitterPlug = grammars: vimPlugins.nvim-treesitter.withPlugins (_: grammars); buildTreesitterPlug = grammars: vimPlugins.nvim-treesitter.withPlugins (_: grammars);
buildConfigPlugins = plugins: pluginBuilders = {
map nvim-treesitter = buildTreesitterPlug vimOptions.treesitter.grammars;
(plug: ( flutter-tools-patched =
if (isString plug)
then
(
if (plug == "nvim-treesitter")
then (buildTreesitterPlug vimOptions.treesitter.grammars)
else if (plug == "flutter-tools-patched")
then
(
buildPlug buildPlug
{ {
pname = "flutter-tools"; pname = "flutter-tools";
patches = [../patches/flutter-tools.patch]; patches = [../patches/flutter-tools.patch];
} };
) };
else noBuildPlug {pname = plug;}
) buildConfigPlugins = plugins:
map
(
plug:
if (isString plug)
then pluginBuilders.${plug} or (buildPlug {pname = plug;})
else plug else plug
)) )
(filter (filter (f: f != null) plugins);
(f: f != null)
plugins);
# built (or "normalized") plugins that are modified # built (or "normalized") plugins that are modified
builtStartPlugins = buildConfigPlugins vimOptions.startPlugins; builtStartPlugins = buildConfigPlugins vimOptions.startPlugins;
@ -100,6 +100,16 @@ inputs: {
extraLuaPackages = ps: map (x: ps.${x}) vimOptions.luaPackages; extraLuaPackages = ps: map (x: ps.${x}) vimOptions.luaPackages;
extraPython3Packages = ps: map (x: ps.${x}) vimOptions.python3Packages; extraPython3Packages = ps: map (x: ps.${x}) vimOptions.python3Packages;
luaConfig =
if vimOptions.byteCompileLua
then pkgs.runCommandLocal "init.lua" {text = vimOptions.builtLuaConfigRC;} "${pkgs.luajit}/bin/luajit -bd -- - $out <<< \"$text\""
else pkgs.writeText "init.lua" vimOptions.builtLuaConfigRC;
extraLuaFiles =
if vimOptions.byteCompileLua
then map (file: pkgs.runCommandLocal (baseNameOf file) {} "${pkgs.luajit}/bin/luajit -bd -- ${file} $out") vimOptions.extraLuaFiles
else vimOptions.extraLuaFiles;
# Wrap the user's desired (unwrapped) Neovim package with arguments that'll be used to # Wrap the user's desired (unwrapped) Neovim package with arguments that'll be used to
# generate a wrapped Neovim package. # generate a wrapped Neovim package.
neovim-wrapped = inputs.mnw.lib.wrap pkgs { neovim-wrapped = inputs.mnw.lib.wrap pkgs {
@ -107,8 +117,7 @@ inputs: {
plugins = concatLists [builtStartPlugins builtOptPlugins]; plugins = concatLists [builtStartPlugins builtOptPlugins];
appName = "nvf"; appName = "nvf";
extraBinPath = vimOptions.extraPackages; extraBinPath = vimOptions.extraPackages;
initLua = vimOptions.builtLuaConfigRC; luaFiles = [luaConfig] ++ extraLuaFiles;
luaFiles = vimOptions.extraLuaFiles;
inherit (vimOptions) viAlias vimAlias withRuby withNodeJs withPython3; inherit (vimOptions) viAlias vimAlias withRuby withNodeJs withPython3;
inherit extraLuaPackages extraPython3Packages; inherit extraLuaPackages extraPython3Packages;
@ -116,13 +125,13 @@ inputs: {
# Additional helper scripts for printing and displaying nvf configuration # Additional helper scripts for printing and displaying nvf configuration
# in your commandline. # in your commandline.
printConfig = pkgs.writers.writeDashBin "print-nvf-config" '' printConfig = pkgs.writers.writeDashBin "nvf-print-config" ''
cat << EOF cat << EOF
${vimOptions.builtLuaConfigRC} ${vimOptions.builtLuaConfigRC}
EOF EOF
''; '';
printConfigPath = pkgs.writers.writeDashBin "print-nvf-config-path" '' printConfigPath = pkgs.writers.writeDashBin "nvf-print-config-path" ''
realpath ${pkgs.writeTextFile { realpath ${pkgs.writeTextFile {
name = "nvf-init.lua"; name = "nvf-init.lua";
text = vimOptions.builtLuaConfigRC; text = vimOptions.builtLuaConfigRC;

View file

@ -23,6 +23,13 @@ in {
]; ];
options.vim = { options.vim = {
byteCompileLua = mkOption {
type = bool;
default = true;
example = false;
description = "Enable the pre-compilation of lua files using LuaJIT.";
};
enableLuaLoader = mkEnableOption '' enableLuaLoader = mkEnableOption ''
the experimental Lua module loader to speed up the start up process the experimental Lua module loader to speed up the start up process