diff options
author | Matthieu Coudron <mcoudron@hotmail.com> | 2022-04-29 10:09:40 +0200 |
---|---|---|
committer | Matthieu Coudron <teto@users.noreply.github.com> | 2022-04-30 23:54:25 +0200 |
commit | 9663a29afa9ae4ad8a5bd69b8fd307d9c4563180 (patch) | |
tree | b54bb9bde38fda811858a143a7a6aa879f501b7c | |
parent | 2415f1e0a5ec933ca8bf5ff6b91a36cf79ddaf2b (diff) |
buildVimPlugin: add vimCommandCheckHook
Modeled after pythonImportCheckHook, this checks a command can be run once the plugin is installed
5 files changed, 47 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 3d36edb32325c..187c068c0f093 100644 --- a/pkgs/applications/editors/vim/plugins/build-vim-plugin.nix +++ b/pkgs/applications/editors/vim/plugins/build-vim-plugin.nix @@ -1,6 +1,7 @@ { lib, stdenv , rtpPath , vim +, vimCommandCheckHook , vimGenDocHook }: @@ -30,6 +31,7 @@ rec { forceShare= [ "man" "info" ]; nativeBuildInputs = attrs.nativeBuildInputs or [] + ++ [ vimCommandCheckHook ] ++ lib.optional (stdenv.hostPlatform == stdenv.buildPlatform) vimGenDocHook; inherit unpackPhase configurePhase buildPhase addonInfo preInstall postInstall; diff --git a/pkgs/applications/editors/vim/plugins/default.nix b/pkgs/applications/editors/vim/plugins/default.nix index 1e847e695403f..cd5a1f9d6e509 100644 --- a/pkgs/applications/editors/vim/plugins/default.nix +++ b/pkgs/applications/editors/vim/plugins/default.nix @@ -3,7 +3,7 @@ let - inherit (vimUtils.override {inherit vim;}) buildVimPluginFrom2Nix vimGenDocHook; + inherit (vimUtils.override {inherit vim;}) buildVimPluginFrom2Nix vimGenDocHook vimCommandCheckHook; inherit (lib) extends; @@ -12,7 +12,10 @@ let toVimPlugin = drv: drv.overrideAttrs(oldAttrs: { - nativeBuildInputs = oldAttrs.nativeBuildInputs or [] ++ [ vimGenDocHook ]; + nativeBuildInputs = oldAttrs.nativeBuildInputs or [] ++ [ + vimGenDocHook + vimCommandCheckHook + ]; passthru = (oldAttrs.passthru or {}) // { vimPlugin = true; }; diff --git a/pkgs/applications/editors/vim/plugins/overrides.nix b/pkgs/applications/editors/vim/plugins/overrides.nix index f59317d1cf5de..e294ea0b5a2b1 100644 --- a/pkgs/applications/editors/vim/plugins/overrides.nix +++ b/pkgs/applications/editors/vim/plugins/overrides.nix @@ -450,11 +450,8 @@ self: super: { --replace "code-minimap" "${code-minimap}/bin/code-minimap" ''; - doCheck = true; - checkPhase = '' - ${neovim-unwrapped}/bin/nvim -n -u NONE -i NONE -V1 --cmd "set rtp+=$out" --cmd "runtime! plugin/*.vim" -c "MinimapToggle" +quit! - ''; - + doInstallCheck = true; + vimCommandCheck = "MinimapToggle"; }); ncm2 = super.ncm2.overrideAttrs (old: { diff --git a/pkgs/applications/editors/vim/plugins/vim-command-check-hook.sh b/pkgs/applications/editors/vim/plugins/vim-command-check-hook.sh new file mode 100644 index 0000000000000..c4ddd8e0c5af7 --- /dev/null +++ b/pkgs/applications/editors/vim/plugins/vim-command-check-hook.sh @@ -0,0 +1,25 @@ +# Setup hook for checking whether a vim command exists +echo "Sourcing vim-command-check-hook.sh" + +vimCommandCheckHook () { + echo "Executing vimCommandCheckHook" + + if [ -n "$vimCommandCheck" ]; then + echo "Check whether the following modules can be imported: $vimCommandCheck" + + # editorconfig-checker-disable + export HOME="$TMPDIR" + @vimBinary@ -es -n -u NONE -i NONE --clean -V1 --cmd "set rtp+=$out" \ + --cmd "runtime! plugin/*.vim" <<-EOF + if exists(":$vimCommandCheck") == 2 + cquit 0 + else + cquit 1 + fi + EOF + fi +} + +echo "Using vimCommandCheckHook" +preDistPhases+=" vimCommandCheckHook" + diff --git a/pkgs/applications/editors/vim/plugins/vim-utils.nix b/pkgs/applications/editors/vim/plugins/vim-utils.nix index b291928f25aaf..5e19d33d19d19 100644 --- a/pkgs/applications/editors/vim/plugins/vim-utils.nix +++ b/pkgs/applications/editors/vim/plugins/vim-utils.nix @@ -521,8 +521,19 @@ rec { }; } ./vim-gen-doc-hook.sh) {}; - inherit (import ./build-vim-plugin.nix { inherit lib stdenv rtpPath vim vimGenDocHook; }) - buildVimPlugin buildVimPluginFrom2Nix; + vimCommandCheckHook = callPackage ({ neovim-unwrapped }: + makeSetupHook { + name = "vim-command-check-hook"; + deps = [ neovim-unwrapped ]; + substitutions = { + vimBinary = "${neovim-unwrapped}/bin/nvim"; + inherit rtpPath; + }; + } ./vim-command-check-hook.sh) {}; + + inherit (import ./build-vim-plugin.nix { + inherit lib stdenv rtpPath vim vimGenDocHook vimCommandCheckHook; + }) buildVimPlugin buildVimPluginFrom2Nix; # used to figure out which python dependencies etc. neovim needs requiredPlugins = { |