From afa5e3594b00c265956617f01199cab395bdabce Mon Sep 17 00:00:00 2001 From: diniamo Date: Mon, 5 Aug 2024 12:51:03 +0200 Subject: [PATCH 1/9] feat: print-nvf-config(-path) -> nvf-print-config(-path) --- docs/release-notes/rl-0.7.md | 6 +++--- modules/default.nix | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/docs/release-notes/rl-0.7.md b/docs/release-notes/rl-0.7.md index 87bd3b6..e789aa6 100644 --- a/docs/release-notes/rl-0.7.md +++ b/docs/release-notes/rl-0.7.md @@ -140,10 +140,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..86d4972 100644 --- a/modules/default.nix +++ b/modules/default.nix @@ -116,13 +116,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; From 97d49d331caa56e8e2fa544ea9d9da1f8da74be6 Mon Sep 17 00:00:00 2001 From: diniamo Date: Mon, 5 Aug 2024 13:16:30 +0200 Subject: [PATCH 2/9] feat: vim.byteCompileLua --- docs/release-notes/rl-0.7.md | 2 ++ modules/default.nix | 18 ++++++++++++++---- modules/wrapper/rc/options.nix | 7 +++++++ 3 files changed, 23 insertions(+), 4 deletions(-) diff --git a/docs/release-notes/rl-0.7.md b/docs/release-notes/rl-0.7.md index e789aa6..959e51c 100644 --- a/docs/release-notes/rl-0.7.md +++ b/docs/release-notes/rl-0.7.md @@ -99,6 +99,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 diff --git a/modules/default.nix b/modules/default.nix index 86d4972..a68646d 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 @@ -100,6 +99,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;} "echo -n \"$text\" | ${pkgs.luajit}/bin/luajit -bd -- - $out" + 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 +116,9 @@ inputs: { plugins = concatLists [builtStartPlugins builtOptPlugins]; appName = "nvf"; extraBinPath = vimOptions.extraPackages; - initLua = vimOptions.builtLuaConfigRC; - luaFiles = vimOptions.extraLuaFiles; + # initLua = vimOptions.builtLuaConfigRC; + # luaFiles = vimOptions.extraLuaFiles; + luaFiles = [luaConfig] ++ extraLuaFiles; inherit (vimOptions) viAlias vimAlias withRuby withNodeJs withPython3; inherit extraLuaPackages extraPython3Packages; 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 From 13cc59ab99f616ca2dc582b195d4cdd306453332 Mon Sep 17 00:00:00 2001 From: diniamo Date: Mon, 5 Aug 2024 14:10:31 +0200 Subject: [PATCH 3/9] feat: use `<<<` instead of `echo -n |` --- modules/default.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/default.nix b/modules/default.nix index a68646d..b7b0e92 100644 --- a/modules/default.nix +++ b/modules/default.nix @@ -101,7 +101,7 @@ inputs: { luaConfig = if vimOptions.byteCompileLua - then pkgs.runCommandLocal "init.lua" {text = vimOptions.builtLuaConfigRC;} "echo -n \"$text\" | ${pkgs.luajit}/bin/luajit -bd -- - $out" + then pkgs.runCommandLocal "init.lua" {text = vimOptions.builtLuaConfigRC;} "${pkgs.luajit}/bin/luajit -bd -- - $out <<< \"$text\"" else pkgs.writeText "init.lua" vimOptions.builtLuaConfigRC; extraLuaFiles = From 5c79c458fcadbd00755ed97299a3d27d0f470701 Mon Sep 17 00:00:00 2001 From: diniamo Date: Mon, 5 Aug 2024 14:57:02 +0200 Subject: [PATCH 4/9] feat: byte-compile plugins --- modules/default.nix | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/modules/default.nix b/modules/default.nix index b7b0e92..f7041cd 100644 --- a/modules/default.nix +++ b/modules/default.nix @@ -36,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 @@ -49,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: @@ -77,7 +76,7 @@ inputs: { patches = [../patches/flutter-tools.patch]; } ) - else noBuildPlug {pname = plug;} + else buildPlug {pname = plug;} ) else plug )) From fa660627fcbdc962790501fb7c8edb517e256620 Mon Sep 17 00:00:00 2001 From: diniamo Date: Thu, 8 Aug 2024 12:34:16 +0200 Subject: [PATCH 5/9] style: remove leftover commented code --- modules/default.nix | 2 -- 1 file changed, 2 deletions(-) diff --git a/modules/default.nix b/modules/default.nix index f7041cd..76cccec 100644 --- a/modules/default.nix +++ b/modules/default.nix @@ -115,8 +115,6 @@ 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; From 1340eb34a0a4698449cb6c21362c8ac67e77dc3c Mon Sep 17 00:00:00 2001 From: diniamo Date: Fri, 9 Aug 2024 09:29:29 +0200 Subject: [PATCH 6/9] style: improve code clarity --- modules/default.nix | 45 ++++++++++++++++++++------------------------- 1 file changed, 20 insertions(+), 25 deletions(-) diff --git a/modules/default.nix b/modules/default.nix index 76cccec..5036454 100644 --- a/modules/default.nix +++ b/modules/default.nix @@ -9,7 +9,7 @@ inputs: { inherit (pkgs) vimPlugins; inherit (lib.strings) isString toString; inherit (lib.lists) filter map concatLists; - inherit (lib.attrsets) recursiveUpdate getAttr; + inherit (lib.attrsets) recursiveUpdate; inherit (builtins) baseNameOf; # import modules.nix with `check`, `pkgs` and `lib` as arguments @@ -32,8 +32,8 @@ inputs: { # build a vim plugin with the given name and arguments # if the plugin is nvim-treesitter, warn the user to use buildTreesitterPlug # instead - buildPlug = {pname, ...} @ attrs: let - src = getAttr ("plugin-" + pname) inputs; + buildPlug = attrs: let + src = inputs."plugin-${attrs.pname}"; in pkgs.stdenvNoCC.mkDerivation ({ version = src.shortRev or src.shortDirtyRev or "dirty"; @@ -59,30 +59,25 @@ inputs: { 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 - ( - if (plug == "nvim-treesitter") - then (buildTreesitterPlug vimOptions.treesitter.grammars) - else if (plug == "flutter-tools-patched") - then - ( - buildPlug - { - pname = "flutter-tools"; - patches = [../patches/flutter-tools.patch]; - } - ) - else buildPlug {pname = plug;} - ) - else plug - )) - (filter - (f: f != null) - plugins); + ( + plug: + if (isString plug) + then pluginBuilders.${plug} or (buildPlug {pname = plug;}) + else plug + ) + (filter (f: f != null) plugins); # built (or "normalized") plugins that are modified builtStartPlugins = buildConfigPlugins vimOptions.startPlugins; From d48f52f065c24ad1e23b8704f0c0c68c3d2c08be Mon Sep 17 00:00:00 2001 From: diniamo Date: Fri, 9 Aug 2024 09:29:41 +0200 Subject: [PATCH 7/9] fix: add Gerg's suggestion --- modules/default.nix | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/modules/default.nix b/modules/default.nix index 5036454..b466d2e 100644 --- a/modules/default.nix +++ b/modules/default.nix @@ -40,6 +40,13 @@ inputs: { 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 -- {} {} \; From 78c01d50ed66d64ad05a093d6ce593775c101435 Mon Sep 17 00:00:00 2001 From: diniamo Date: Sat, 10 Aug 2024 09:05:06 +0200 Subject: [PATCH 8/9] fix: use luajit from the neovim package's lua attribute --- modules/default.nix | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/modules/default.nix b/modules/default.nix index b466d2e..2bd72d7 100644 --- a/modules/default.nix +++ b/modules/default.nix @@ -29,6 +29,8 @@ inputs: { # alias to the internal configuration vimOptions = module.config.vim; + luajit = vimOptions.package.lua; + # build a vim plugin with the given name and arguments # if the plugin is nvim-treesitter, warn the user to use buildTreesitterPlug # instead @@ -41,6 +43,8 @@ inputs: { inherit src; nativeBuildInputs = with pkgs.vimUtils; [ + luajit + vimCommandCheckHook vimGenDocHook neovimRequireCheckHook @@ -102,12 +106,12 @@ inputs: { luaConfig = if vimOptions.byteCompileLua - then pkgs.runCommandLocal "init.lua" {text = vimOptions.builtLuaConfigRC;} "${pkgs.luajit}/bin/luajit -bd -- - $out <<< \"$text\"" + then pkgs.runCommandLocal "init.lua" {text = vimOptions.builtLuaConfigRC;} "${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 + then map (file: pkgs.runCommandLocal (baseNameOf file) {} "${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 From 1c0b31cc10584ca356ffe52dfe9669d4d9bb3846 Mon Sep 17 00:00:00 2001 From: diniamo Date: Sat, 10 Aug 2024 16:52:14 +0200 Subject: [PATCH 9/9] improve helper functions --- modules/default.nix | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/modules/default.nix b/modules/default.nix index 2bd72d7..fc996e4 100644 --- a/modules/default.nix +++ b/modules/default.nix @@ -127,20 +127,11 @@ inputs: { 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 << EOF - ${vimOptions.builtLuaConfigRC} - EOF - ''; - - printConfigPath = pkgs.writers.writeDashBin "nvf-print-config-path" '' - realpath ${pkgs.writeTextFile { - name = "nvf-init.lua"; - text = vimOptions.builtLuaConfigRC; - }} - ''; + printConfig = pkgs.writers.writeDashBin "nvf-print-config" "cat ${dummyInit}"; + printConfigPath = pkgs.writers.writeDashBin "nvf-print-config-path" "echo -n ${dummyInit}"; in { inherit (module) options config; inherit (module._module.args) pkgs; @@ -150,7 +141,7 @@ in { neovim = pkgs.symlinkJoin { name = "nvf-with-helpers"; paths = [neovim-wrapped printConfig printConfigPath]; - postBuild = "echo helpers added"; + postBuild = "echo Helpers added"; meta = { description = "Wrapped version of Neovim with additional helper scripts";