Skip to content

Instantly share code, notes, and snippets.

@PerchunPak
Created October 10, 2024 18:48
Show Gist options
  • Save PerchunPak/2db1212c23df2538b990ec1ca09be9b5 to your computer and use it in GitHub Desktop.
Save PerchunPak/2db1212c23df2538b990ec1ca09be9b5 to your computer and use it in GitHub Desktop.
WIP automatic nvimRequireCheck for vim plugins (nixpkgs)
diff --git a/maintainers/scripts/pluginupdate-py/pluginupdate.py b/maintainers/scripts/pluginupdate-py/pluginupdate.py
index afe60069dd29..3774bee702cf 100644
--- a/maintainers/scripts/pluginupdate-py/pluginupdate.py
+++ b/maintainers/scripts/pluginupdate-py/pluginupdate.py
@@ -132,6 +132,13 @@ class Repo:
return loaded["rev"], updated
+ @retry(urllib.error.URLError, tries=4, delay=3, backoff=2)
+ def get_path(self) -> Path:
+ log.debug("Get path")
+ loaded = self._prefetch(None)
+ return Path(loaded["path"])
+
+ @functools.cache
def _prefetch(self, ref: Optional[str]):
cmd = ["nix-prefetch-git", "--quiet", "--fetch-submodules", self.uri]
if ref is not None:
@@ -141,6 +148,19 @@ class Repo:
loaded = json.loads(data)
return loaded
+ # {
+ # "url": "https://github.com/euclidianAce/BetterLua.vim/",
+ # "rev": "d2d6c115575d09258a794a6f20ac60233eee59d5",
+ # "date": "2020-08-13T21:25:32-05:00",
+ # "path": "/nix/store/si0d0z69r5plsx4kd9g9dngwypqpdg6w-BetterLua.vim",
+ # "sha256": "1rvlx21kw8865dg6q97hx9i2s1n8mn1nyhn0m7dkx625pghsx3js",
+ # "hash": "sha256-Wo6u4btFmD7bqcBCb4OtyAYtYurwJGxeKwYhPoPodOc=",
+ # "fetchLFS": false,
+ # "fetchSubmodules": true,
+ # "deepClone": false,
+ # "leaveDotGit": false
+ # }
+
def prefetch(self, ref: Optional[str]) -> str:
print("Prefetching %s", self.uri)
loaded = self._prefetch(ref)
diff --git a/pkgs/applications/editors/vim/plugins/aliases.nix b/pkgs/applications/editors/vim/plugins/aliases.nix
index 8a95ceb753e0..e5259bdddf44 100644
--- a/pkgs/applications/editors/vim/plugins/aliases.nix
+++ b/pkgs/applications/editors/vim/plugins/aliases.nix
@@ -93,13 +93,13 @@ mapAliases (with prev; {
neoinclude = neoinclude-vim;
neomru = neomru-vim;
neosnippet = neosnippet-vim;
- nvim-ts-rainbow = throw "nvim-ts-rainbow has been deprecated: Use rainbow-delimiters-nvim"; # Added 2023-11-30
- nvim-ts-rainbow2 = throw "nvim-ts-rainbow2 has been deprecated: Use rainbow-delimiters-nvim"; # Added 2023-11-30
+ # nvim-ts-rainbow = throw "nvim-ts-rainbow has been deprecated: Use rainbow-delimiters-nvim"; # Added 2023-11-30
+ # nvim-ts-rainbow2 = throw "nvim-ts-rainbow2 has been deprecated: Use rainbow-delimiters-nvim"; # Added 2023-11-30
The_NERD_Commenter = nerdcommenter;
The_NERD_tree = nerdtree;
open-browser = open-browser-vim;
pathogen = vim-pathogen;
- peskcolor-vim = throw "peskcolor-vim has been removed: abandoned by upstream"; # Added 2024-08-23
+ # peskcolor-vim = throw "peskcolor-vim has been removed: abandoned by upstream"; # Added 2024-08-23
polyglot = vim-polyglot;
prettyprint = vim-prettyprint;
quickrun = vim-quickrun;
@@ -131,12 +131,12 @@ mapAliases (with prev; {
tlib = tlib_vim;
tmux-navigator = vim-tmux-navigator;
tmuxNavigator = vim-tmux-navigator; # backwards compat, added 2014-10-18
- todo-nvim = throw "todo-nvim has been removed: abandoned by upstream"; # Added 2023-08-23
+ # todo-nvim = throw "todo-nvim has been removed: abandoned by upstream"; # Added 2023-08-23
tslime = tslime-vim;
unite = unite-vim;
UltiSnips = ultisnips;
vim-addon-vim2nix = vim2nix;
- vim-sourcetrail = throw "vim-sourcetrail has been removed: abandoned by upstream"; # Added 2022-08-14
+ # vim-sourcetrail = throw "vim-sourcetrail has been removed: abandoned by upstream"; # Added 2022-08-14
vimproc = vimproc-vim;
vimshell = vimshell-vim;
vinegar = vim-vinegar;
diff --git a/pkgs/applications/editors/vim/plugins/deprecated.json b/pkgs/applications/editors/vim/plugins/deprecated.json
index 05678e61362b..2c63c0851048 100644
--- a/pkgs/applications/editors/vim/plugins/deprecated.json
+++ b/pkgs/applications/editors/vim/plugins/deprecated.json
@@ -1,86 +1,2 @@
{
- "TrueZen-nvim": {
- "date": "2022-07-27",
- "new": "true-zen-nvim"
- },
- "compe-tmux": {
- "date": "2021-12-07",
- "new": "cmp-tmux"
- },
- "fern-vim": {
- "date": "2024-05-12",
- "new": "vim-fern"
- },
- "gina-vim": {
- "date": "2024-05-12",
- "new": "vim-gina"
- },
- "gist-vim": {
- "date": "2020-03-27",
- "new": "vim-gist"
- },
- "lspsaga-nvim-original": {
- "date": "2023-08-08",
- "new": "lspsaga-nvim"
- },
- "lua-dev-nvim": {
- "date": "2022-10-14",
- "new": "neodev-nvim"
- },
- "nvchad-extensions": {
- "date": "2023-08-19",
- "new": "nvchad-ui"
- },
- "nvim-base16": {
- "date": "2024-02-15",
- "new": "base16-nvim"
- },
- "nvim-bufferline-lua": {
- "date": "2021-08-22",
- "new": "bufferline-nvim"
- },
- "nvim-lsp": {
- "date": "2020-08-31",
- "new": "nvim-lspconfig"
- },
- "nvim-toggleterm-lua": {
- "date": "2021-08-22",
- "new": "toggleterm-nvim"
- },
- "orgmode-nvim": {
- "date": "2021-11-28",
- "new": "orgmode"
- },
- "render-markdown": {
- "date": "2024-09-16",
- "new": "render-markdown-nvim"
- },
- "sql-nvim": {
- "date": "2021-09-03",
- "new": "sqlite-lua"
- },
- "suda-vim": {
- "date": "2024-05-12",
- "new": "vim-suda"
- },
- "taskwarrior": {
- "date": "2024-08-13",
- "new": "taskwarrior3 or taskwarrior2"
- },
- "vim-fsharp": {
- "date": "2024-03-16",
- "new": "zarchive-vim-fsharp"
- },
- "vim-jade": {
- "date": "2020-03-27",
- "new": "vim-pug"
- },
- "vundle": {
- "date": "2020-03-27",
- "new": "Vundle-vim"
- },
- "youcompleteme": {
- "date": "2020-03-27",
- "new": "YouCompleteMe"
- }
}
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 0c6a0010845d..bf723b794819 100644
--- a/pkgs/applications/editors/vim/plugins/neovim-require-check-hook.sh
+++ b/pkgs/applications/editors/vim/plugins/neovim-require-check-hook.sh
@@ -2,20 +2,48 @@
echo "Sourcing neovim-require-check-hook.sh"
neovimRequireCheckHook () {
- echo "Executing neovimRequireCheckHook"
+ echo "Executing neovimRequireCheckHook"
- if [ -n "$nvimRequireCheck" ]; then
- echo "Check whether the following module can be imported: $nvimRequireCheck"
+ if [ -z "$nvimRequireCheck" ]; then
+ echo "No nvimRequireCheck set, skipping"
+ return
+ fi
- # editorconfig-checker-disable
- export HOME="$TMPDIR"
- @nvimBinary@ -es --headless -n -u NONE -i NONE --clean -V1 \
- --cmd "set rtp+=$out,${dependencies/ /,}" \
- --cmd "lua require('$nvimRequireCheck')"
+ if [ $(find "$src" -name '*.lua' | wc -l) -eq 0 ]; then
+ echo "Didn't found any .lua files, skipping"
+ return
fi
+
+ if ! [[ "$(declare -p nvimRequireCheck)" =~ "declare -a" ]]; then
+ nvimRequireCheck=(nvimRequireCheck)
+ fi
+
+ echo "Check whether the following module can be imported: ${nvimRequireCheck[*]}"
+
+ CHECK_PASSED=false
+ export HOME="$TMPDIR"
+ set +e
+ for name in "${nvimRequireCheck[@]}"; do
+ @nvimBinary@ -es --headless -n -u NONE -i NONE --clean -V1 \
+ --cmd "set rtp+=$out,${dependencies/ /,}" \
+ --cmd "lua require('$name')" \
+ && CHECK_PASSED=$name
+ done
+ set -e
+
+ printf "\n======================================================\n"
+
+ if [[ "$CHECK_PASSED" == "false" ]]; then
+ echo "Require check failed, try to set 'nvimRequireCheck' variable manually for this plugin."
+ echo "Tried these names: ${nvimRequireCheck[*]}"
+ printf "======================================================\n"
+ exit 1
+ else
+ echo "Successfully required '$CHECK_PASSED', ignore tracebacks in the build log"
+ fi
+
+ printf "======================================================\n"
}
echo "Using neovimRequireCheckHook"
preDistPhases+=" neovimRequireCheckHook"
-
-
diff --git a/pkgs/applications/editors/vim/plugins/overrides.nix b/pkgs/applications/editors/vim/plugins/overrides.nix
index a65e920150fb..0718f18a1d30 100644
--- a/pkgs/applications/editors/vim/plugins/overrides.nix
+++ b/pkgs/applications/editors/vim/plugins/overrides.nix
@@ -139,7 +139,7 @@ let
in
{
alpha-nvim = super.alpha-nvim.overrideAttrs {
- nvimRequireCheck = "alpha";
+ # nvimRequireCheck = "alpha";
};
advanced-git-search-nvim = super.advanced-git-search-nvim.overrideAttrs {
@@ -148,7 +148,7 @@ in
animation-nvim = super.animation-nvim.overrideAttrs {
dependencies = with self; [ middleclass ];
- nvimRequireCheck = "animation";
+ # nvimRequireCheck = "animation";
};
autosave-nvim = super.autosave-nvim.overrideAttrs {
@@ -501,7 +501,7 @@ in
'';
doInstallCheck = true;
- nvimRequireCheck = "codesnap";
+ # nvimRequireCheck = "codesnap";
meta = {
homepage = "https://github.com/mistricky/codesnap.nvim/";
@@ -524,7 +524,7 @@ in
dependencies = [ self.nui-nvim ];
doInstallCheck = true;
- nvimRequireCheck = "competitest";
+ # nvimRequireCheck = "competitest";
};
compe-tabnine = super.compe-tabnine.overrideAttrs {
@@ -542,7 +542,7 @@ in
compiler-nvim = super.compiler-nvim.overrideAttrs {
dependencies = [ self.overseer-nvim ];
- nvimRequireCheck = "compiler";
+ # nvimRequireCheck = "compiler";
};
completion-buffers = super.completion-buffers.overrideAttrs {
@@ -569,7 +569,7 @@ in
copilot-lualine = super.copilot-lualine.overrideAttrs {
dependencies = with self; [ copilot-lua lualine-nvim ];
doInstallCheck = true;
- nvimRequireCheck = "copilot-lualine";
+ # nvimRequireCheck = "copilot-lualine";
};
copilot-vim = super.copilot-vim.overrideAttrs (old: {
@@ -636,7 +636,7 @@ in
'';
doInstallCheck = true;
- nvimRequireCheck = "cord";
+ # nvimRequireCheck = "cord";
meta = {
homepage = "https://github.com/vyfor/cord.nvim";
@@ -763,7 +763,7 @@ in
dependencies = with self; [ plenary-nvim ];
doInstallCheck = true;
- nvimRequireCheck = "diffview";
+ # nvimRequireCheck = "diffview";
};
direnv-vim = super.direnv-vim.overrideAttrs (old: {
@@ -908,7 +908,7 @@ in
dependencies = with self; [ overseer-nvim plenary-nvim ];
doInstallCheck = true;
- nvimRequireCheck = "hardhat";
+ # nvimRequireCheck = "hardhat";
};
harpoon = super.harpoon.overrideAttrs {
@@ -958,7 +958,7 @@ in
dependencies = with self; [ nui-nvim nvim-lspconfig ];
doInstallCheck = true;
- nvimRequireCheck = "idris2";
+ # nvimRequireCheck = "idris2";
};
image-nvim = super.image-nvim.overrideAttrs {
@@ -976,7 +976,7 @@ in
--replace @nix_magick@ ${luajitPackages.magick}
'';
- nvimRequireCheck = "image";
+ # nvimRequireCheck = "image";
};
jedi-vim = super.jedi-vim.overrideAttrs {
@@ -1083,7 +1083,7 @@ in
lsp-progress-nvim = neovimUtils.buildNeovimPlugin {
luaAttr = luaPackages.lsp-progress-nvim;
- nvimRequireCheck = "lsp-progress";
+ # nvimRequireCheck = "lsp-progress";
};
luasnip = super.luasnip.overrideAttrs {
@@ -1167,7 +1167,7 @@ in
middleclass = neovimUtils.buildNeovimPlugin {
luaAttr = luaPackages.middleclass;
- nvimRequireCheck = "middleclass";
+ # nvimRequireCheck = "middleclass";
};
minimap-vim = super.minimap-vim.overrideAttrs {
@@ -1259,7 +1259,7 @@ in
luaAttr = luaPackages.neorg;
doInstallCheck = true;
- nvimRequireCheck = "neorg";
+ # nvimRequireCheck = "neorg";
};
neotest = super.neotest.overrideAttrs {
@@ -1314,7 +1314,7 @@ in
dependencies = with self; [ nvim-dap nvim-nio ];
doInstallCheck = true;
- nvimRequireCheck = "dapui";
+ # nvimRequireCheck = "dapui";
};
nvim-dap-rr = super.nvim-dap-rr.overrideAttrs {
@@ -1325,7 +1325,7 @@ in
dependencies = [ self.dressing-nvim ];
doInstallCheck = true;
- nvimRequireCheck = "genghis";
+ # nvimRequireCheck = "genghis";
};
nvim-lsputils = super.nvim-lsputils.overrideAttrs {
@@ -1497,7 +1497,7 @@ in
'';
doInstallCheck = true;
- nvimRequireCheck = "plenary";
+ # nvimRequireCheck = "plenary";
};
Preview-nvim = super.Preview-nvim.overrideAttrs {
@@ -1835,7 +1835,7 @@ in
todo-comments-nvim = super.todo-comments-nvim.overrideAttrs {
dependencies = [ self.plenary-nvim ];
- nvimRequireCheck = "todo-comments";
+ # nvimRequireCheck = "todo-comments";
};
tssorter-nvim = super.tssorter-nvim.overrideAttrs {
@@ -2255,7 +2255,7 @@ in
windows-nvim = super.windows-nvim.overrideAttrs {
dependencies = with self; [ middleclass animation-nvim ];
- nvimRequireCheck = "windows";
+ # nvimRequireCheck = "windows";
};
wtf-nvim = super.wtf-nvim.overrideAttrs {
diff --git a/pkgs/applications/editors/vim/plugins/update.py b/pkgs/applications/editors/vim/plugins/update.py
index a8525b9018b5..3f25a7fde605 100755
--- a/pkgs/applications/editors/vim/plugins/update.py
+++ b/pkgs/applications/editors/vim/plugins/update.py
@@ -18,6 +18,7 @@
# from Nixpkgs master tree).
#
+import time
import inspect
import os
import logging
@@ -110,7 +111,7 @@ class VimEditor(pluginupdate.Editor):
print(f"updated {outfile}")
def plugin2nix(self, pdesc: PluginDesc, plugin: pluginupdate.Plugin, isNeovim: bool) -> str:
-
+ vim_module_name, nvim_module_name = self.resolve_module_name_for_require_test(plugin, pdesc)
repo = pdesc.repo
content = f" {plugin.normalized_name} = "
@@ -120,6 +121,9 @@ class VimEditor(pluginupdate.Editor):
version = "{plugin.version}";
src = {src_nix};
meta.homepage = "{repo.uri}";
+
+ vimCommandCheck = "{vim_module_name}";
+ nvimRequireCheck = "{nvim_module_name}";
}};
""".format(
@@ -127,6 +131,8 @@ class VimEditor(pluginupdate.Editor):
plugin=plugin,
src_nix=src_nix,
repo=repo,
+ vim_module_name=vim_module_name,
+ nvim_module_name=nvim_module_name,
)
log.debug(content)
return content
@@ -163,6 +169,45 @@ class VimEditor(pluginupdate.Editor):
return
print("no updates to nvim-treesitter grammars")
+ def resolve_module_name_for_require_test(
+ self,
+ plugin: pluginupdate.Plugin,
+ pdesc: pluginupdate.PluginDesc,
+ ) -> tuple[str, str]: # first for vim and second for nvim
+ start = time.time()
+ path = pdesc.repo.get_path()
+ print(time.time() - start)
+
+ for_vim = [
+ p for p in path.glob("plugin/*")
+ if p.is_dir() or p.name.endswith(".vim")
+ ]
+ if len(for_vim) > 1:
+ log.error(
+ "Don't know what to do, more than one"
+ f"vim file in plugin:\n{for_vim[0].resolve()}"
+ )
+ for_vim = ["FIXME"]
+ elif len(for_vim) == 0:
+ log.error(f"Could not find any vim files for {path.resolve()}")
+ for_vim = ["FIXME"]
+
+ for_nvim = [
+ p for p in path.glob("lua/*")
+ if p.is_dir() or p.name.endswith(".lua")
+ ]
+ if len(for_nvim) > 1:
+ log.error(
+ "Don't know what to do, more than one"
+ f"lua file in plugin:\n{for_nvim[0].resolve()}"
+ )
+ for_nvim = ["FIXME"]
+ elif len(for_nvim) == 0:
+ log.error(f"Could not find any lua files for {path.resolve()}")
+ for_nvim = ["FIXME"]
+
+ return for_vim[0], for_nvim[0]
+
def main():
global luaPlugins
diff --git a/pkgs/applications/editors/vim/plugins/vim-command-check-hook.sh b/pkgs/applications/editors/vim/plugins/vim-command-check-hook.sh
index c4ddd8e0c5af..046739593696 100644
--- a/pkgs/applications/editors/vim/plugins/vim-command-check-hook.sh
+++ b/pkgs/applications/editors/vim/plugins/vim-command-check-hook.sh
@@ -2,24 +2,52 @@
echo "Sourcing vim-command-check-hook.sh"
vimCommandCheckHook () {
- echo "Executing vimCommandCheckHook"
+ echo "Executing vimCommandCheckHook"
- if [ -n "$vimCommandCheck" ]; then
- echo "Check whether the following modules can be imported: $vimCommandCheck"
+ if [ -z "$vimCommandCheck" ]; then
+ echo "No vimCommandCheck set, skipping"
+ return
+ fi
- # 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
+ if [ $(find "$src" -name '*.vim' | wc -l) -eq 0 ]; then
+ echo "Didn't found any .vim files, skipping"
+ return
+ fi
+
+ if ! [[ "$(declare -p vimCommandCheck)" =~ "declare -a" ]]; then
+ vimCommandCheck=(vimCommandCheck)
+ fi
+
+ echo "Check whether the following modules can be imported: ${vimCommandCheck[*]}"
+
+ CHECK_PASSED=false
+ export HOME="$TMPDIR"
+ set +e
+ for name in "${vimCommandCheck[@]}"; do
+ @vimBinary@ -es -n -u NONE -i NONE --clean -V1 --cmd "set rtp+=$out" \
+ --cmd "runtime! plugin/*.vim" <<-EOF && CHECK_PASSED=$name
+ if exists(":$name") == 2
cquit 0
else
cquit 1
fi
EOF
- fi
+ done
+ set -e
+
+ printf "\n======================================================\n"
+
+ if [[ "$CHECK_PASSED" == "false" ]]; then
+ echo "Require check failed, try to set 'vimCommandCheck' variable manually for this plugin."
+ echo "Tried these names: ${vimCommandCheck[*]}"
+ printf "======================================================\n"
+ exit 1
+ else
+ echo "Successfully required '$CHECK_PASSED', ignore tracebacks in the build log"
+ fi
+
+ printf "======================================================\n"
}
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 d5536ee3b63a..444cdef8ceab 100644
--- a/pkgs/applications/editors/vim/plugins/vim-utils.nix
+++ b/pkgs/applications/editors/vim/plugins/vim-utils.nix
@@ -415,15 +415,17 @@ rec {
toVimPlugin = drv:
drv.overrideAttrs(oldAttrs: {
+ __structuredAttrs = true; # TODO rebase to staging
name = "vimplugin-${oldAttrs.name}";
# dont move the "doc" folder since vim expects it
forceShare = [ "man" "info" ];
nativeBuildInputs = oldAttrs.nativeBuildInputs or []
++ lib.optionals (stdenv.buildPlatform.canExecute stdenv.hostPlatform) [
- vimCommandCheckHook vimGenDocHook
+ # vimCommandCheckHook
+ vimGenDocHook
# many neovim plugins keep using buildVimPlugin
- neovimRequireCheckHook
+ # neovimRequireCheckHook
];
passthru = (oldAttrs.passthru or {}) // {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment