Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 41 additions & 33 deletions pkgs/applications/editors/neovim/tests/default.nix
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
# run tests by building `neovim.tests`
{ vimUtils, writeText, neovim, vimPlugins
, lib, fetchFromGitHub, neovimUtils, wrapNeovimUnstable
{ vimUtils
, writeText
, neovim
, vimPlugins
, lib
, fetchFromGitHub
, neovimUtils
, wrapNeovimUnstable
, neovim-unwrapped
, fetchFromGitLab
, runCommandLocal
Expand All @@ -9,8 +15,6 @@
let
inherit (neovimUtils) makeNeovimConfig;

packages.myVimPackage.start = with vimPlugins; [ vim-nix ];

plugins = with vimPlugins; [
{
plugin = vim-obsession;
Expand Down Expand Up @@ -47,11 +51,8 @@ let

nvimAutoDisableWrap = makeNeovimConfig { };

nvimConfDontWrap = makeNeovimConfig {
inherit plugins;
customRC = ''
" just a comment
'';
neovimWithCyan = neovim.override {
configure.packages.all.start = [ vimPlugins.nvim-teal-maker ];
};

wrapNeovim2 = suffix: config:
Expand All @@ -68,7 +69,7 @@ let

# this plugin checks that it's ftplugin/vim.tex is loaded before $VIMRUNTIME/ftplugin/vim.tex
# the answer is store in `plugin_was_loaded_too_late` in the cwd
texFtplugin = (pkgs.runCommandLocal "tex-ftplugin" {} ''
texFtplugin = (pkgs.runCommandLocal "tex-ftplugin" { } ''
mkdir -p $out/ftplugin
echo 'call system("echo ". exists("b:did_ftplugin") . " > plugin_was_loaded_too_late")' > $out/ftplugin/tex.vim
echo ':q!' >> $out/ftplugin/tex.vim
Expand All @@ -77,30 +78,32 @@ let

# neovim-drv must be a wrapped neovim
runTest = neovim-drv: buildCommand:
runCommandLocal "test-${neovim-drv.name}" ({
nativeBuildInputs = [ ];
meta.platforms = neovim-drv.meta.platforms;
}) (''
runCommandLocal "test-${neovim-drv.name}"
{
nativeBuildInputs = [ ];
meta.platforms = neovim-drv.meta.platforms;
} ''
source ${nmt}/bash-lib/assertions.sh
vimrc="${writeText "init.vim" neovim-drv.initRc}"
vimrcGeneric="$out/patched.vim"
mkdir $out
${pkgs.perl}/bin/perl -pe "s|\Q$NIX_STORE\E/[a-z0-9]{32}-|$NIX_STORE/eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee-|g" < "$vimrc" > "$vimrcGeneric"
'' + buildCommand);
${buildCommand}
'';

in
pkgs.recurseIntoAttrs (
rec {

pkgs.recurseIntoAttrs rec {
vim_empty_config = vimUtils.vimrcFile { beforePlugins = ""; customRC = ""; };

### neovim tests
##################
nvim_with_plugins = wrapNeovim2 "-with-plugins" nvimConfNix;

singlelinesconfig = runTest (wrapNeovim2 "-single-lines" nvimConfSingleLines) ''
assertFileContent \
"$vimrcGeneric" \
"${./init-single-lines.vim}"
assertFileContent \
"$vimrcGeneric" \
"${./init-single-lines.vim}"
'';

nvim_via_override = neovim.override {
Expand All @@ -123,7 +126,7 @@ rec {
extraName = "-with-plug";
configure.packages.plugins = with pkgs.vimPlugins; {
start = [
(base16-vim.overrideAttrs(old: { pname = old.pname + "-unique-for-tests-please-dont-use"; }))
(base16-vim.overrideAttrs (old: { pname = old.pname + "-unique-for-tests-please-dont-use"; }))
];
};
configure.customRC = ''
Expand Down Expand Up @@ -159,7 +162,7 @@ rec {

# check that the vim-doc hook correctly generates the tag
# we know for a fact packer has a doc folder
checkForTags = vimPlugins.packer-nvim.overrideAttrs(oldAttrs: {
checkForTags = vimPlugins.packer-nvim.overrideAttrs (oldAttrs: {
doInstallCheck = true;
installCheckPhase = ''
[ -f $out/doc/tags ]
Expand All @@ -179,25 +182,25 @@ rec {
});

force-nowrap = runTest nvimDontWrap ''
! grep -F -- ' -u' ${nvimDontWrap}/bin/nvim
! grep -F -- ' -u' ${nvimDontWrap}/bin/nvim
'';

nvim_via_override-test = runTest nvim_via_override ''
assertFileContent \
"$vimrcGeneric" \
"${./init-override.vim}"
assertFileContent \
"$vimrcGeneric" \
"${./init-override.vim}"
'';


checkAliases = runTest nvim_with_aliases ''
folder=${nvim_with_aliases}/bin
assertFileExists "$folder/vi"
assertFileExists "$folder/vim"
folder=${nvim_with_aliases}/bin
assertFileExists "$folder/vi"
assertFileExists "$folder/vim"
'';

# having no RC generated should autodisable init.vim wrapping
nvim_autowrap = runTest nvim_via_override ''
! grep "-u" ${nvimShouldntWrap}/bin/nvim
! grep "-u" ${nvimShouldntWrap}/bin/nvim
'';


Expand All @@ -211,7 +214,7 @@ rec {
};

nvimWithLuaPackages = wrapNeovim2 "-with-lua-packages" (makeNeovimConfig {
extraLuaPackages = ps: [ps.mpack];
extraLuaPackages = ps: [ ps.mpack ];
customRC = ''
lua require("mpack")
'';
Expand All @@ -227,7 +230,7 @@ rec {
extraName = "-with-opt-plugin";
configure.packages.opt-plugins = with pkgs.vimPlugins; {
opt = [
(dashboard-nvim.overrideAttrs(old: { pname = old.pname + "-unique-for-tests-please-dont-use-opt"; }))
(dashboard-nvim.overrideAttrs (old: { pname = old.pname + "-unique-for-tests-please-dont-use-opt"; }))
];
};
configure.customRC = ''
Expand Down Expand Up @@ -261,4 +264,9 @@ rec {
export HOME=$TMPDIR
${nvim_with_opt_plugin}/bin/nvim -i NONE +quit! -e
'';
})

pathDeps = runTest neovimWithCyan ''
export HOME=$(mktemp -d)
${neovimWithCyan}/bin/nvim --headless -ei NONE '+!cyan version' +quit!
'';
}
42 changes: 23 additions & 19 deletions pkgs/applications/editors/neovim/utils.nix
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ let

# expects a list of plugin configuration
# expects { plugin=far-vim; config = "let g:far#source='rg'"; optional = false; }
, plugins ? []
, plugins ? [ ]
# custom viml config appended after plugin-specific config
, customRC ? ""

Expand All @@ -59,23 +59,25 @@ let
in
map (x: defaultPlugin // (if (x ? plugin) then x else { plugin = x; })) plugins;

pluginRC = lib.foldl (acc: p: if p.config != null then acc ++ [p.config] else acc) [] pluginsNormalized;
pluginRC = lib.foldl (acc: p: if p.config != null then acc ++ [ p.config ] else acc) [ ] pluginsNormalized;

pluginsPartitioned = lib.partition (x: x.optional == true) pluginsNormalized;
requiredPlugins = vimUtils.requiredPluginsForPackage myVimPackage;
getDeps = attrname: map (plugin: plugin.${attrname} or (_: [ ]));
myVimPackage = {
start = map (x: x.plugin) pluginsPartitioned.wrong;
opt = map (x: x.plugin) pluginsPartitioned.right;
start = map (x: x.plugin) pluginsPartitioned.wrong;
opt = map (x: x.plugin) pluginsPartitioned.right;
};

pathDependencies = lib.concatMap (plugin: plugin.pathDependencies or [ ]) requiredPlugins;

pluginPython3Packages = getDeps "python3Dependencies" requiredPlugins;
python3Env = python3Packages.python.withPackages (ps:
[ ps.pynvim ]
++ (extraPython3Packages ps)
++ (lib.concatMap (f: f ps) pluginPython3Packages));

luaEnv = neovim-unwrapped.lua.withPackages(extraLuaPackages);
luaEnv = neovim-unwrapped.lua.withPackages extraLuaPackages;

# Mapping a boolean argument to a key that tells us whether to add or not to
# add to nvim's 'embedded rc' this:
Expand All @@ -91,11 +93,13 @@ let
};
## Here we calculate all of the arguments to the 1st call of `makeWrapper`
# We start with the executable itself NOTE we call this variable "initial"
# because if configure != {} we need to call makeWrapper twice, in order to
# because if configure != { } we need to call makeWrapper twice, in order to
# avoid double wrapping, see comment near finalMakeWrapperArgs
makeWrapperArgs =
let
binPath = lib.makeBinPath (lib.optionals withRuby [ rubyEnv ] ++ lib.optionals withNodeJs [ nodejs ]);
binPath = lib.makeBinPath (pathDependencies
++ lib.optionals withRuby [ rubyEnv ]
++ lib.optionals withNodeJs [ nodejs ]);

hostProviderViml = lib.mapAttrsToList genProviderSettings hostprog_check_table;

Expand All @@ -107,7 +111,7 @@ let
"--cmd" (lib.intersperse "|" hostProviderViml)
"--cmd" "set packpath^=${vimUtils.packDir packDirArgs}"
"--cmd" "set rtp^=${vimUtils.packDir packDirArgs}"
];
];
in
[
"--inherit-argv0" "--add-flags" (lib.escapeShellArgs flags)
Expand All @@ -120,13 +124,13 @@ let
"--prefix" "LUA_CPATH" ";" (neovim-unwrapped.lua.pkgs.luaLib.genLuaCPathAbsStr luaEnv)
];

manifestRc = vimUtils.vimrcContent ({ customRC = ""; }) ;
manifestRc = vimUtils.vimrcContent { customRC = ""; } ;
# we call vimrcContent without 'packages' to avoid the init.vim generation
neovimRcContent = vimUtils.vimrcContent ({
neovimRcContent = vimUtils.vimrcContent {
beforePlugins = "";
customRC = lib.concatStringsSep "\n" (pluginRC ++ [customRC]);
packages = null;
});
};
in

builtins.removeAttrs args ["plugins"] // {
Expand All @@ -151,16 +155,16 @@ let
legacyWrapper = neovim: {
extraMakeWrapperArgs ? ""
/* the function you would have passed to python.withPackages */
, extraPythonPackages ? (_: [])
, extraPythonPackages ? (_: [ ])
/* the function you would have passed to python.withPackages */
, withPython3 ? true, extraPython3Packages ? (_: [])
, withPython3 ? true, extraPython3Packages ? (_: [ ])
/* the function you would have passed to lua.withPackages */
, extraLuaPackages ? (_: [])
, extraLuaPackages ? (_: [ ])
, withNodeJs ? false
, withRuby ? true
, vimAlias ? false
, viAlias ? false
, configure ? {}
, configure ? { }
, extraName ? ""
}:
let
Expand All @@ -169,8 +173,8 @@ let
plugins = if builtins.hasAttr "plug" configure then
throw "The neovim legacy wrapper doesn't support configure.plug anymore, please setup your plugins via 'configure.packages' instead"
else
lib.flatten (lib.mapAttrsToList genPlugin (configure.packages or {}));
genPlugin = packageName: {start ? [], opt ? []}:
lib.flatten (lib.mapAttrsToList genPlugin (configure.packages or { }));
genPlugin = packageName: {start ? [ ], opt ? [ ]}:
start ++ (map (p: { plugin = p; optional = true; }) opt);

res = makeNeovimConfig {
Expand All @@ -185,8 +189,8 @@ let
in
wrapNeovimUnstable neovim (res // {
wrapperArgs = lib.escapeShellArgs res.wrapperArgs + " " + extraMakeWrapperArgs;
wrapRc = (configure != {});
});
wrapRc = configure != { };
});
in
{
inherit makeNeovimConfig;
Expand Down
5 changes: 1 addition & 4 deletions pkgs/applications/editors/vim/plugins/overrides.nix
Original file line number Diff line number Diff line change
Expand Up @@ -674,10 +674,7 @@ self: super: {
});

nvim-teal-maker = super.nvim-teal-maker.overrideAttrs (old: {
postPatch = ''
substituteInPlace lua/tealmaker/init.lua \
--replace cyan ${luaPackages.cyan}/bin/cyan
'';
passthru.pathDependencies = [ luaPackages.cyan ];
Copy link
Copy Markdown
Member

@Frontear Frontear Nov 1, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you elaborate on this change. How does it replicate the substituteInPlace from the previous diff?

Ah I see, this passes the derivation directly into makeWrapper, very cool, but a little bit indirect. I think some form of propagated deps may be better here.

vimCommandCheck = "TealBuild";
});

Expand Down