Lua packages not immediately available?
Closed this issue · 7 comments
When using image.nvim and opening a neorg file directly by nvim file.norg
(not necessarily containing an image), I get the following error:
image.nvim: magick rock not found, please install it and restart your editor. Error: "...ajit2.1-magick-1.6.0-1/share/lua/5.1/magick/wand/lib.lua:206: /nix/store/rhj9b0ssrqnhwbbbplslngq9a1dky8a9-gcc-10.3.0-lib/lib/libstdc++.so.6: version `GLIBCXX_3.4.29' not found (required by /nix/store/0fnb6g07y484cpl191vkf40f3zlfmv64-libjxl-0.10.3/lib/libjxl.so.0.10)"
This does not happen when opening the file from a started neovim instance, as the dependencies (magick
and imagemagick
) are installed as extraLuaPackages
and lspAndRuntimeDeps
, respectively.
Just to clarify, you installed magick like so?
extraLuaPackages = {
someCategoryName = [ (lp: with lp; [ magick ]) ];
};
Those are added to $LUA_PATH and $LUA_CPATH for the luajit process that is ran via nvim.
This means when neovim starts its luajit environment, they will already be in the package.path and package.cpath
They should be available well before nvim starts processing any config or plugins.
I simply combine the functions from the categories by putting them in a new function that passes them all the argument and then merges the resulting lists using this function called here
I then pass the resulting function directly to neovim-unwrapped.lua.withPackages and also set the environment variables which is the same thing that makeNeovimConfig from nixpkgs does with them. In addition, I go through the packpath and grab propagated dependencies from plugins in the packpath and add them to the LUA_PATH and LUA_CPATH here which is a fix that was added to nixpkgs a while back to allow plugins to declare such dependencies themselves from within their nixpkgs definition.
And all lspAndRuntimeDeps does is add the derivation's bin
directory to the $PATH
I really have no idea why you might be encountering that issue.
In fact, I just tried it out. I have the same one....
image.nvim: magick rock not found, please install it and restart your editor. Error: "...ajit2.1-magick-1.6.0-1/share/lua/5.1/magick/wand/lib.lua:206: /nix/store/rhj9b0ssrqnhwbbbplslngq9a1dky8a9-gcc-10.3.0-lib/lib
/libstdc++.so.6: version `GLIBCXX_3.4.29' not found (required by /nix/store/0fnb6g07y484cpl191vkf40f3zlfmv64-libjxl-0.10.3/lib/libjxl.so.0.10)"
This error seems to not be saying that it cant find magick. It definitely seems to be finding magick.
This error seems to be saying that magick cant find one of its c dependencies (the c++ standard lib?), and thus is failing, and thus cant be loaded and thus "magick rock not found" because it failed to load, not because it wasnt found at all
(side note, "magick rock" is an amusing phrasing)
The weird thing is, it seems to work outside of neorg files, I use image.nvim personally and havent had an issue, but I tried it out in a norg file and, yeah, I get the error too.
I actually get it regardless of how I enter the file. I have neorg installed but I really dont use it, so I didnt notice the error. But when I installed it, way back when, I didnt get this error, or at least, if I did I dont remember it.
I dont get the error in any other type of file...
So..... yeah hmmmmmmm....
But yeah its definitely finding the magick rock. You can see that it knows the path to it in the error you posted.
But it is failing to actually load it properly, but only in norg files, due to a c dependency that seemingly is only missing when you enter a norg file?
Very confusing. I have no idea why a norg file would have a different set of c dependencies available to it, compared to any other type of file. I dont do anything different for different filetypes that would cause this that I know of.
Edit: did they add a new dependency for specifically processing norg files? And then maybe nobody added it to the nixpkgs override?
I am not convinced that this error is a problem with nixCats yet. It is possible, but feels unlikely given that it is, in fact, finding magick, even when it errors, and also the fact that it works fine in other filetypes
This error should be present in the programs.neovim nixpkgs/hm module, pkgs.wrapNeovim, pkgs.wrapNeovimUnstable, and likely nixvim as well. Id be surprised if there exists wrappers without this issue, as this seems to be the way they all provide lua dependencies.
But there is definitely a problem somewhere. Likely it will need to be fixed in nixpkgs and/or the neorg overlay.
You could attempt adding the correct c library to sharedLibraries section in categoryDefinitions? Hopefully that would work? It would add the derivation's lib
directory to LD_LIBRARY_PATH for every subprocess for nvim, so for nvim and all the plugins and all the programs the plugins start too.
But if it did work it still wouldnt explain why the error only happens in norg files, as it seems to be able find the library just fine in other filetypes.
Unfortunately I dont really have the time to look into it further right now, as doing so would require a good bit of digging around neorg, magick, image.nvim, and nixpkgs, and I like, really dont use neorg and know very little about it, despite having it installed
So yeah, conclusion
A, the path to magick is directly patched into image.nvim and you dont need to include it manually (I did not know that, but now I do)
B. if you did need to include it manually, it would be available before any config or plugin was processed.
C. it is finding magick, its just throwing an error while loading it due to not being able to find libstdc++.so (but only in norg files?)
D. I have no idea why that doesnt work in norg files but works everywhere else.
E. Im 99.99% sure that this isnt a problem with nixCats, and should be fixed somewhere else so that more people may benefit from the fix compared to only those that use nixCats. Where though, I am not sure. but here would be a good place to start looking at least
If you wish to submit an issue to nixpkgs, it will be answered more quickly if you edit the following to include a minimal reproduction example, but doing so is not technically necessary.
Despite how similar the inner workings of nixCats are to the nixpkgs neovim wrapper in many of the ways that matter for actually including the dependencies themselves (nixcats only adds to the set they provide a couple more types of things you can add, and does the whole category and multiple package thing, and includes a directory properly for you, and does the message passing with the nixCats plugin thing), they prefer minimal reproduction cases that use the nixpkgs wrapper
{
description = ''
A minimal configuration skeleton for nvim
using pkgs.wrapNeovim for use in making minimal
reproduction cases for bug reports to nixpkgs.
Also uses nixToLua to pass a table,
and loads the directory as a config directory.
'';
inputs = {
nixpkgs = {
url = "github:nixos/nixpkgs/nixpkgs-unstable";
};
neovim-nightly = {
url = "github:nix-community/neovim-nightly-overlay";
# inputs.nixpkgs.follows = "nixpkgs";
};
nixToLua.url = "github:BirdeeHub/nixToLua";
};
outputs = { nixpkgs, neovim-nightly, nixToLua, ...}: let
forAllSys = nixpkgs.lib.genAttrs nixpkgs.lib.platforms.all;
extraOverlays = [];
overlayMyNeovim = nvim: prev: final: {
myNeovim = let
valuesToPass = {
};
luaRC = final.writeText "init.lua" /*lua*/''
-- create require('nixvals') table
package.preload["nixvals"] = function()
return ${nixToLua.prettyNoModify valuesToPass}
end
-- load current directory as config directory
vim.opt.rtp:remove(vim.fn.stdpath("config"))
vim.opt.packpath:remove(vim.fn.stdpath("config"))
vim.opt.rtp:remove(vim.fn.stdpath("config") .. "/after")
vim.opt.rtp:prepend("${./.}")
vim.opt.packpath:prepend("${./.}")
vim.opt.rtp:append("${./.}/after")
if vim.fn.filereadable("${./.}/init.lua") == 1 then
dofile("${./.}/init.lua")
end
'';
in
final.wrapNeovim (if nvim != null then nvim else final.neovim-unwrapped) {
configure = {
customRC = ''lua dofile("${luaRC}")'';
packages.all.start = with final.vimPlugins; [
];
packages.all.opt = with final.vimPlugins; [
];
};
extraMakeWrapperArgs = builtins.concatStringsSep " " [
''--prefix PATH : "${final.lib.makeBinPath (with final; [ stdenv.cc.cc ])}"''
];
extraLuaPackages = (_: []);
extraPythonPackages = (_: []);
withPython3 = true;
extraPython3Packages = (_: []);
withNodeJs = false;
withRuby = true;
vimAlias = false;
viAlias = false;
extraName = "";
};
};
in
{
packages = forAllSys (system: let
configuredNvimOverlay = extraOverlays ++ [ (overlayMyNeovim null) ];
configuredNvimNightlyOverlay = extraOverlays ++ [ (overlayMyNeovim neovim-nightly.packages.${system}.neovim) ];
pkgs = import nixpkgs {
inherit system;
overlays = configuredNvimOverlay;
};
pkgs_nightly = import nixpkgs {
inherit system;
overlays = configuredNvimNightlyOverlay;
};
in
{
default = pkgs.myNeovim;
nightly = pkgs_nightly.myNeovim;
});
};
}
Idk why, but its resolved for me now.
Maybe something got fixed upstream but I havent done anything that should or should not fix it XD
Since I can no longer reproduce this issue, I will close it?
If something crops up again, do let me know :)