diff --git a/docs/release-notes/rl-0.7.md b/docs/release-notes/rl-0.7.md index 21edbdd..9977a81 100644 --- a/docs/release-notes/rl-0.7.md +++ b/docs/release-notes/rl-0.7.md @@ -102,6 +102,8 @@ configuration formats. yourself by adding `vim.opt.listchars:append({ eol = '' })` to your 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() - 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 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 using neovimConfig or `programs.nvf.enable`. - - `print-nvf-config` will display your `init.lua`, in full. - - `print-nvf-config-path` will display the path to _a clone_ of your + - `nvf-print-config` will display your `init.lua`, in full. + - `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 identical clone. diff --git a/modules/default.nix b/modules/default.nix index 227cf20..76cccec 100644 --- a/modules/default.nix +++ b/modules/default.nix @@ -7,11 +7,10 @@ inputs: { extraModules ? [], }: let inherit (pkgs) vimPlugins; - inherit (pkgs.vimUtils) buildVimPlugin; inherit (lib.strings) isString toString; inherit (lib.lists) filter map concatLists; inherit (lib.attrsets) recursiveUpdate getAttr; - inherit (lib.asserts) assertMsg; + inherit (builtins) baseNameOf; # import modules.nix with `check`, `pkgs` and `lib` as arguments # check can be disabled while calling this file is called @@ -37,8 +36,16 @@ inputs: { src = getAttr ("plugin-" + pname) inputs; in pkgs.stdenvNoCC.mkDerivation ({ - inherit src; version = src.shortRev or src.shortDirtyRev or "dirty"; + + inherit src; + + buildPhase = lib.optionalString vimOptions.byteCompileLua '' + runHook preBuild + find . -type f -name '*.lua' -exec luajit -bd -- {} {} \; + runHook postBuild + ''; + installPhase = '' runHook preInstall @@ -50,15 +57,6 @@ inputs: { } // 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); buildConfigPlugins = plugins: @@ -78,7 +76,7 @@ inputs: { patches = [../patches/flutter-tools.patch]; } ) - else noBuildPlug {pname = plug;} + else buildPlug {pname = plug;} ) else plug )) @@ -100,6 +98,16 @@ inputs: { extraLuaPackages = ps: map (x: ps.${x}) vimOptions.luaPackages; 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 # generate a wrapped Neovim package. neovim-wrapped = inputs.mnw.lib.wrap pkgs { @@ -107,8 +115,7 @@ inputs: { plugins = concatLists [builtStartPlugins builtOptPlugins]; appName = "nvf"; extraBinPath = vimOptions.extraPackages; - initLua = vimOptions.builtLuaConfigRC; - luaFiles = vimOptions.extraLuaFiles; + luaFiles = [luaConfig] ++ extraLuaFiles; inherit (vimOptions) viAlias vimAlias withRuby withNodeJs withPython3; inherit extraLuaPackages extraPython3Packages; @@ -116,13 +123,13 @@ inputs: { # Additional helper scripts for printing and displaying nvf configuration # in your commandline. - printConfig = pkgs.writers.writeDashBin "print-nvf-config" '' + printConfig = pkgs.writers.writeDashBin "nvf-print-config" '' cat << EOF ${vimOptions.builtLuaConfigRC} EOF ''; - printConfigPath = pkgs.writers.writeDashBin "print-nvf-config-path" '' + printConfigPath = pkgs.writers.writeDashBin "nvf-print-config-path" '' realpath ${pkgs.writeTextFile { name = "nvf-init.lua"; text = vimOptions.builtLuaConfigRC; diff --git a/modules/wrapper/rc/options.nix b/modules/wrapper/rc/options.nix index 4165da6..5cd5310 100644 --- a/modules/wrapper/rc/options.nix +++ b/modules/wrapper/rc/options.nix @@ -23,6 +23,13 @@ in { ]; options.vim = { + byteCompileLua = mkOption { + type = bool; + default = true; + example = false; + description = "Enable the pre-compilation of lua files using LuaJIT."; + }; + enableLuaLoader = mkEnableOption '' the experimental Lua module loader to speed up the start up process