From 08b6ad0ea504ff34e58638319ea717ef7fac09a4 Mon Sep 17 00:00:00 2001 From: Matthieu Coudron Date: Fri, 29 Apr 2022 12:05:37 +0200 Subject: [PATCH 1/3] buildVimPlugin: check that neovim can require the module. Add: ``` doInstallCheck = true; nvimRequireCheck = "toto"; ``` to your vimPluginCall. --- .../editors/vim/plugins/build-vim-plugin.nix | 3 ++- .../vim/plugins/neovim-require-check-hook.sh | 21 +++++++++++++++++++ .../editors/vim/plugins/overrides.nix | 3 +++ .../editors/vim/plugins/vim-utils.nix | 12 ++++++++++- 4 files changed, 37 insertions(+), 2 deletions(-) create mode 100644 pkgs/applications/editors/vim/plugins/neovim-require-check-hook.sh diff --git a/pkgs/applications/editors/vim/plugins/build-vim-plugin.nix b/pkgs/applications/editors/vim/plugins/build-vim-plugin.nix index 187c068c0f09..e0978db4527e 100644 --- a/pkgs/applications/editors/vim/plugins/build-vim-plugin.nix +++ b/pkgs/applications/editors/vim/plugins/build-vim-plugin.nix @@ -3,6 +3,7 @@ , vim , vimCommandCheckHook , vimGenDocHook +, neovimRequireCheckHook }: rec { @@ -31,7 +32,7 @@ rec { forceShare= [ "man" "info" ]; nativeBuildInputs = attrs.nativeBuildInputs or [] - ++ [ vimCommandCheckHook ] + ++ [ vimCommandCheckHook neovimRequireCheckHook ] ++ lib.optional (stdenv.hostPlatform == stdenv.buildPlatform) vimGenDocHook; inherit unpackPhase configurePhase buildPhase addonInfo preInstall postInstall; diff --git a/pkgs/applications/editors/vim/plugins/neovim-require-check-hook.sh b/pkgs/applications/editors/vim/plugins/neovim-require-check-hook.sh new file mode 100644 index 000000000000..590f530954d1 --- /dev/null +++ b/pkgs/applications/editors/vim/plugins/neovim-require-check-hook.sh @@ -0,0 +1,21 @@ +# Setup hook for checking whether Python imports succeed +echo "Sourcing neovim-require-check-hook.sh" + +neovimRequireCheckHook () { + echo "Executing neovimRequireCheckHook" + + if [ -n "$nvimRequireCheck" ]; then + echo "Check whether the following module can be imported: $nvimRequireCheck" + + # editorconfig-checker-disable + export HOME="$TMPDIR" + @nvimBinary@ -es -n -u NONE -i NONE --clean -V1 \ + --cmd "set rtp+=$out" \ + --cmd "lua require('$nvimRequireCheck')" + fi +} + +echo "Using neovimRequireCheckHook" +preDistPhases+=" neovimRequireCheckHook" + + diff --git a/pkgs/applications/editors/vim/plugins/overrides.nix b/pkgs/applications/editors/vim/plugins/overrides.nix index e294ea0b5a2b..078989406a80 100644 --- a/pkgs/applications/editors/vim/plugins/overrides.nix +++ b/pkgs/applications/editors/vim/plugins/overrides.nix @@ -321,6 +321,9 @@ self: super: { sed -Ei lua/plenary/curl.lua \ -e 's@(command\s*=\s*")curl(")@\1${curl}/bin/curl\2@' ''; + + doInstallCheck = true; + nvimRequireCheck = "plenary"; }); gruvbox-nvim = super.gruvbox-nvim.overrideAttrs (old: { diff --git a/pkgs/applications/editors/vim/plugins/vim-utils.nix b/pkgs/applications/editors/vim/plugins/vim-utils.nix index e685e398fc2b..69633d24c3c3 100644 --- a/pkgs/applications/editors/vim/plugins/vim-utils.nix +++ b/pkgs/applications/editors/vim/plugins/vim-utils.nix @@ -531,8 +531,18 @@ rec { }; } ./vim-command-check-hook.sh) {}; + neovimRequireCheckHook = callPackage ({ neovim-unwrapped }: + makeSetupHook { + name = "neovim-require-check-hook"; + deps = [ neovim-unwrapped ]; + substitutions = { + nvimBinary = "${neovim-unwrapped}/bin/nvim"; + inherit rtpPath; + }; + } ./neovim-require-check-hook.sh) {}; + inherit (import ./build-vim-plugin.nix { - inherit lib stdenv rtpPath vim vimGenDocHook vimCommandCheckHook; + inherit lib stdenv rtpPath vim vimGenDocHook vimCommandCheckHook neovimRequireCheckHook; }) buildVimPlugin buildVimPluginFrom2Nix; From 0dbca90d4129b6c4296b66899fd2750584b24c4f Mon Sep 17 00:00:00 2001 From: Matthieu Coudron Date: Tue, 10 May 2022 14:30:50 +0200 Subject: [PATCH 2/3] buildNeovimPluginFrom2Nix: use neovimRequireCheckHook and removed the addRtp call that was breaking overrideAttrs --- .../editors/vim/plugins/build-vim-plugin.nix | 9 ++------- .../editors/vim/plugins/neovim-require-check-hook.sh | 2 +- pkgs/applications/editors/vim/plugins/vim-utils.nix | 4 +++- 3 files changed, 6 insertions(+), 9 deletions(-) diff --git a/pkgs/applications/editors/vim/plugins/build-vim-plugin.nix b/pkgs/applications/editors/vim/plugins/build-vim-plugin.nix index e0978db4527e..9dc5344ed285 100644 --- a/pkgs/applications/editors/vim/plugins/build-vim-plugin.nix +++ b/pkgs/applications/editors/vim/plugins/build-vim-plugin.nix @@ -7,11 +7,6 @@ }: rec { - addRtp = path: attrs: derivation: - derivation // { rtp = "${derivation}"; } // { - overrideAttrs = f: buildVimPlugin (attrs // f attrs); - }; - buildVimPlugin = attrs@{ name ? "${attrs.pname}-${attrs.version}", namePrefix ? "vimplugin-", @@ -25,14 +20,14 @@ rec { addonInfo ? null, ... }: - addRtp "${rtpPath}/${path}" attrs (stdenv.mkDerivation (attrs // { + (stdenv.mkDerivation (attrs // { name = namePrefix + name; # dont move the doc folder since vim expects it forceShare= [ "man" "info" ]; nativeBuildInputs = attrs.nativeBuildInputs or [] - ++ [ vimCommandCheckHook neovimRequireCheckHook ] + ++ [ vimCommandCheckHook ] ++ lib.optional (stdenv.hostPlatform == stdenv.buildPlatform) vimGenDocHook; inherit unpackPhase configurePhase buildPhase addonInfo preInstall postInstall; diff --git a/pkgs/applications/editors/vim/plugins/neovim-require-check-hook.sh b/pkgs/applications/editors/vim/plugins/neovim-require-check-hook.sh index 590f530954d1..5b454e0ff01b 100644 --- a/pkgs/applications/editors/vim/plugins/neovim-require-check-hook.sh +++ b/pkgs/applications/editors/vim/plugins/neovim-require-check-hook.sh @@ -9,7 +9,7 @@ neovimRequireCheckHook () { # editorconfig-checker-disable export HOME="$TMPDIR" - @nvimBinary@ -es -n -u NONE -i NONE --clean -V1 \ + @nvimBinary@ -es --headless -n -u NONE -i NONE --clean -V1 \ --cmd "set rtp+=$out" \ --cmd "lua require('$nvimRequireCheck')" fi diff --git a/pkgs/applications/editors/vim/plugins/vim-utils.nix b/pkgs/applications/editors/vim/plugins/vim-utils.nix index 69633d24c3c3..9511e4da1952 100644 --- a/pkgs/applications/editors/vim/plugins/vim-utils.nix +++ b/pkgs/applications/editors/vim/plugins/vim-utils.nix @@ -548,7 +548,9 @@ rec { # TODO placeholder to ease working on automatic plugin detection # this should be a luarocks "flat" install with appropriate vim hooks - buildNeovimPluginFrom2Nix = buildVimPluginFrom2Nix; + buildNeovimPluginFrom2Nix = attrs: let drv = (buildVimPluginFrom2Nix attrs); in drv.overrideAttrs(oa: { + nativeBuildInputs = oa.nativeBuildInputs ++ [ neovimRequireCheckHook ]; + }); # used to figure out which python dependencies etc. neovim needs requiredPlugins = { From da8a322e7314ec27f24b50304bf5b0fe1f0c9897 Mon Sep 17 00:00:00 2001 From: Matthieu Coudron Date: Wed, 11 May 2022 11:31:47 +0200 Subject: [PATCH 3/3] buildLuaPlugin: convert the addRtp call since it was breaking overrideAttrs. --- pkgs/applications/editors/vim/plugins/build-vim-plugin.nix | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/pkgs/applications/editors/vim/plugins/build-vim-plugin.nix b/pkgs/applications/editors/vim/plugins/build-vim-plugin.nix index 9dc5344ed285..4773cfb9e43e 100644 --- a/pkgs/applications/editors/vim/plugins/build-vim-plugin.nix +++ b/pkgs/applications/editors/vim/plugins/build-vim-plugin.nix @@ -20,7 +20,7 @@ rec { addonInfo ? null, ... }: - (stdenv.mkDerivation (attrs // { + let drv = stdenv.mkDerivation (attrs // { name = namePrefix + name; # dont move the doc folder since vim expects it @@ -40,7 +40,10 @@ rec { runHook postInstall ''; - })); + }); + in drv.overrideAttrs(oa: { + rtp = "${drv}"; + }); buildVimPluginFrom2Nix = attrs: buildVimPlugin ({ # vim plugins may override this