-
-
Notifications
You must be signed in to change notification settings - Fork 275
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Package does not run on NixOS #428
Comments
Hope I picked the right issue type here. 🙂 |
@klautcomputing It is because the dynamic loader of the binary is pointing to a path that does not exist on NixOS. You can run something like this to fix it:
I put this as
After that, it will work on NixOS. |
@archite Thank you for documenting this! I should have maybe done that myself instead of just mentioning that I patched the elf without actually posting any solution for anyone who stumbles upon this issue. 😅 I would like for the issue to remain open as my question wasn't how to get it to work on an individual level, but instead what the best way would be to automate this in mason. Or whether mason-like functionality could be integrated in something like home-manager? |
@klautcomputing I was curious if I could make a more automated solution for fun. I highly don't suggest this but one could add something ing like this to environment = {
extraSetup = ''
mkdir -p $out/lib64
ln -sf ${pkgs.glibc}/lib64/ld-linux-x86-64.so.2 $out/lib64/ld-linux-x86-64.so.2
'';
};
systemd.tmpfiles.rules = [
"L+ /lib64 - - - - /run/current-system/sw/lib64"
]; Once again, I did this for fun and some quick testing. I'd probably recycle only for nixos containers. |
Hello! Currently the platform detection for Linux systems is a bit too relaxed, causing packages to be installed on systems where they're not supported. I plan on revising these eventually (which effectively will cause these packages to instead fail installation). I've never used NixOS personally, but isn't the notion of centrally and reproducibly (is that a word?) managing ones system dependencies a key value proposition of it? The way Mason handles packages arguably pales in comparison to the Nix way. Just out of pure curiosity - is there anything specific that Mason does that makes it particularly appealing, even on NixOS? As for auto-patching installed binaries, you could probably hack something together like: local mason_registry = require("mason-registry")
local function is_binary(file)
-- ...
end
local function patch_elf(binary_file)
-- ...
end
mason_registry:on("package:install:success", function (pkg)
pkg:get_receipt():if_present(function (receipt)
for bin, rel_path in pairs(receipt.links.bin) do
local bin_abs_path = pkg:get_install_path() .. "/" .. rel_path
if is_binary(bin_abs_path) then
patch_elf(bin_abs_path)
end
end
end)
end) |
I just got this same issue and I don't know how and why it's failing. I can't even run the binary manually:
|
@budimanjojo it's because the binary needs to be patched for the changed ld location. I do this on my arm system because I'm too lazy to patch every binary each time I update nixes: environment.etc = {
"tmpfiles.d/ld-so.conf" = {
text = ''
D /lib 0755 root root - -
L+ /lib/ld-linux-aarch64.so.1 - - - - ${pkgs.glibc}/lib/ld-linux-aarch64.so.1
'';
};
}; Probably a bad idea but I don't run production dev systems. |
@archite thanks! But I can't get it to work by changing I also noticed that it's only affecting |
@budimanjojo on x86_64 it is |
@archite unfortunately it still doesn't work. I tried |
@budimanjojo yeah, that was nixos specific. Sorry. If I get time I'll try and reproduce for you. |
I use I actually managed to make it work with nix-ld but I feel like that's too much hack just for this. I decided to set the |
Hey! I am having the same problem with mason and NixOS, and also want to use mason because I use ubuntu in other computers. @budimanjojo can you explain how you made it work please? |
I got this working by adding the following to my init.lua: local mason_registry = require("mason-registry")
mason_registry:on("package:install:success", function(pkg)
pkg:get_receipt():if_present(function(receipt)
for _, rel_path in pairs(receipt.links.bin) do
local bin_abs_path = pkg:get_install_path() ..
"/extension/server/bin/" .. rel_path
os.execute(
'patchelf --set-interpreter "$(patchelf --print-interpreter $(grep -oE \\/nix\\/store\\/[a-z0-9]+-neovim-unwrapped-[0-9]+\\.[0-9]+\\.[0-9]+\\/bin\\/nvim $(which nvim)))" ' ..
bin_abs_path)
end
end)
end) This uses |
@SergioQuijanoRey The commit to what I did is linked in this issue above. Basically I just set
@s1341 awesome! |
Oh, thanks a lot @budimanjojo and @s1341 for the responses! I am trying to make @s1341 solution work (is more attractive for me) but it is not yet working. I think the problem, for me, is
Also, executing the regex in my terminal does not work, I have to quote the regex to get results. |
The regex is escaped for inclusion in a lua string. What we actually have to do is figure out where all the executables are in the package and patch them all. |
I've modified your function this way: local function osExecute(cmd)
local fileHandle = assert(io.popen(cmd, 'r'))
local commandOutput = assert(fileHandle:read('*a'))
local returnTable = {fileHandle:close()}
return commandOutput,returnTable[3] -- rc[3] contains returnCode
end
-- Make mason packages work with nixos
-- We're using patchelf to mathe that work
-- Thanks to: https://github.com/williamboman/mason.nvim/issues/428#issuecomment-1357192515
local mason_registry = require("mason-registry")
mason_registry:on("package:install:success", function(pkg)
pkg:get_receipt():if_present(function(receipt)
-- Figure out the interpreter inspecting nvim itself
-- This is the same for all packages, so compute only once
local interpreter = osExecute(
"patchelf --print-interpreter $(grep -oE '\\/nix\\/store\\/[a-z0-9]+-neovim-unwrapped-[0-9]+\\.[0-9]+\\.[0-9]+\\/bin\\/nvim' $(which nvim))"
)
for _, rel_path in pairs(receipt.links.bin) do
local bin_abs_path = pkg:get_install_path() .. "/extension/server/bin/" .. rel_path
print("TODO -- bin_abs_path is " .. bin_abs_path)
print("TODO -- interpreter is " .. interpreter)
-- Set the interpreter on the binary
os.execute(
'patchelf --set-interpreter ' .. interpreter .. " " .. bin_abs_path
)
end
end)
end) This gives me the following messages after installing a package:
Mason fails with following message:
When changing Thanks you in advance for your patience. |
What is the actual path to the file you want to patch? |
So to generalize this you'd need to exclude the I'd do something like this: local mason_registry = require("mason-registry")
mason_registry:on("package:install:success", function(pkg)
pkg:get_receipt():if_present(function(receipt)
-- Figure out the interpreter inspecting nvim itself
-- This is the same for all packages, so compute only once
local interpreter = os.execute(
("patchelf --print-interpreter %q"):format(
"$(grep -oE '\\/nix\\/store\\/[a-z0-9]+-neovim-unwrapped-[0-9]+\\.[0-9]+\\.[0-9]+\\/bin\\/nvim' $(which nvim))"
)
)
for _, rel_path in pairs(receipt.links.bin) do
local bin_abs_path = pkg:get_install_path() .. "/" .. rel_path
if pkg.name == "lua-language-server" then
bin_abs_path = pkg:get_install_path() .. "/extension/server/bin/lua-language-server"
end
-- Set the interpreter on the binary
os.execute(
("patchelf --set-interpreter %q %q"):format(interpreter, bin_abs_path)
)
end
end)
end) Note: I use string templates with "%q" placeholders to avoid word splitting when calling |
Btw I'd probably be open to exposing APIs to hook into the "linking" process during installation, allowing people to register a middleware that patches binaries within the installation lifecycle itself, instead of after the fact. This would also allow it to fail the installation should it be unable to patch the binary, resulting in better feedback. I'm thinking something like this (but more thought through): require("mason-core.installer").register_link_middleware(function (target)
if is_binary(target) then
patch_elf(target)
end
end) Let me think some more about it. |
I am trying to install marksman through mason. NixOS has no package for it so its a real use case for Mason in NixOS. After doing normal Mason install for that LSP I've got:
So I guess that I want to patch file Doing so with prev lua code does nothing, as |
Check :LspInfo. Could be it is working. |
|
LspInfo gives me:
LspLog gives me:
Any idea what is happening? Again, thank you both for your immense patience |
It looks like marksman need zlib. You need to make that available in the shell you are running neovim from with e.g. nix-shell -p zlib |
@williamboman did you give any more thought to the middleware api? How about including nixos support directly in mason? |
Adds the nvim LSP/Linter/Formatter packages instead of relying on Mason. Mason binaries are a little broken on NixOS (check: williamboman/mason.nvim#428) Related: realeinherjar/nvim#1
Adds the nvim LSP/Linter/Formatter packages instead of relying on Mason. Mason binaries are a little broken on NixOS (check: williamboman/mason.nvim#428) Related: realeinherjar/nvim#1
Adds the nvim LSP/Linter/Formatter packages instead of relying on Mason. Mason binaries are a little broken on NixOS (check: williamboman/mason.nvim#428) Related: realeinherjar/nvim#1
Would it be possible for Mason to expose an install/uninstall api? So NixOs users or others that are unable or unwilling to use pip, npm, raw binaries or other things, can specify their own way of installation. Then you can still use Mason for it's UI, events, registry and such, but use a different approach for installing packages. Whilst keeping your config somewhat portable. |
a noob NixOS user here... Mason is absolutely amazing for giving a pinless dev experience, and i agree with @williamboman that when we are trying to make mason work on nix, it's like fighting against nix philosophy. But one advantage for nixos is not having to deal dependy issues and get instant dev environment, except for neovim, where it's hard to find proper lsp servers and configure correctly... which takes away the fun of using nixos but from a reddit post, i found this thing called steam-run.. which emulates a traditional distro and work absolutely fantastic,
for me, i am using lazyvim(in a different folder than personal config) with zsh, so
or just global install steam-run by adding to home-manager or configuration.nix and for permanent setups like something that we going to use everyday, it doesn't hurt to install it in home-manager for reproducibility |
In my personal experience, is easier to just rely on NixOS for installing LSPs, linters... So for now I just stopped using mason. Most of the time I am using flakes in each coding project (so system rebuilds are faster). So if I stop using NixOS, I still have my project flakes that give me the needed tools. I am pretty sure that we can write a plugin in top of mason to handle the corner cases of NixOS but IMHO it's not worth the time |
any idea how can i use somwthing like lazyvim with manually installed lsps? |
I am currently using lazyvim with manually installed (through NixOS and flakes per each project) LSPs without any problem. You just install the LSP and using something like lsp-config invoke the LSP. See my dotfiles for more detail and don't hesitate to reach me out if you need help 😄 |
😃 thanks... i will checkout got it... so you are installing all languages globally, in retropect,that would havr been much better than struggling with flakes and dotenv like i currently do |
check buildFHSEnv .maybe work |
Yeah, but I still use configs in project dependent flakes. For example some Ocaml and Python projects (python packages are very problematic). So you can combine both approaches |
One way to solve it is to explicitly call the loader before the executable. To find it just read the one that launched nvim (readlf -x .interp $0) should do the trick unless you are on a static platforms in which case this issue isn't present. this should handle ld-linux-x86_64 and ld-musl-x86_64 and other exotic platforms. another way easier but might be wrong or fail on some more exotic platforms is to locate with which (reading PATH to locate the loader) Elf can be launched like that
PS: I don't use mason only nix just helping someone nix/guix user that want to use it. |
This fixed it for me. I added rust-analyzer to my nix config. |
What is suposted means? You setting as a home manager dofile or something like this? |
I tried with nix-ld and it works, tho once installed u need to login back again/reboot to make it work for the first time. |
@williamboman is there a way to disable the install/update and just to visualize the list of the installed LSPs? So in this way LSPs can be managed by Nix/NixOs and simply mason can be a nice UI tool |
- Mason doesn't work very well with NixOS as shown here: williamboman/mason.nvim#428
* feat: add wsl host and home-manager config * feat: powerlevel10k * refactor: re-order * refactor: append zsh extension to zsh files * refactor: detect environment * refactor: zsh as default shell * feat: tmux * feat: add fd * feat: zsh plugins * refactor: remove unused SSH public keys * fix: ignore unbound variables * refactor: prefer home-manager options over tmux config * feat: lazyvim, lsp is broken williamboman/mason.nvim#428 * fix: neovim and mason * refactor: remove hardware-configuration.nix * doc: add comments of source
@alexandru0-dev mind sharing your NixOS
however, when I run this in the terminal I couldn't get the LSP (gopls) to work
any advice? rebooting doesn't work for me. |
@adibfarrasy i moved away from nix-ld pretty fast, as it wasn't working really that great with mason unfortunately |
https://github.com/dundalek/lazy-lsp.nvim might be worth a look. |
wow, thanks.. i was going to move away from nix just because of the lsp issues... means for some lanauges, somehow globally installing itself wasn't working.... |
Mason was failing previously on nixos because it couldn't install the LSPs it wanted due to how NixOS works. As a workaround, i have tweaked it (based on williamboman/mason.nvim#428) so that it attempts to look for LSPs installed on the system before installing its own version. This prevents the issue without requiring me to remove mason completely (which i want for non-NixOS systems)
I believe this to be an issue that should be addressed by maintainers of mason.nvim.
Why do you think this is an issue with mason.nvim?
This is very much a NixOS problem and I would like to find a way of addressing it. Whether that is through mason or NixOS is tbd. But I haven't found any mention of it anywhere here so I thought it would be worth having the discussion and maybe we can find a way of making it work.
Neovim version (>= 0.7)
NVIM v0.7.2
Build type: Release
LuaJIT 2.1.0-beta3
Compiled by nixbld
Features: +acl +iconv +tui
See ":help feature-compile"
system vimrc file: "$VIM/sysinit.vim"
fall-back for $VIM: "
/nix/store/jnfqzl7lzqshbqfm9mkl27024nsbcgvz-neovim-unwrapped-0.7.2/share/nvim
"
Run :checkhealth for more info
Operating system/version
Linux xray 5.19.5 #1-NixOS SMP PREEMPT_DYNAMIC Mon Aug 29 09:18:05 UTC 2022 x86_64 GNU/Linux
I've manually reviewed logs to find potential errors
I've recently downloaded the latest plugin version of mason.nvim
Affected packages
All
Problem description
When installing packages through mason.vim it installs binaries that are not executable on NixOS because shared libraries not working the same on NixOS.
Steps to reproduce
Run NixOS :)
Actual behavior
[ERROR][2022-09-15 00:17:55] .../vim/lsp/rpc.lua:420 "rpc" "lua-language-server" "stderr" "/home/leex/.local/share/nvim/mason/bin/lua-language-server: line 3: /home/leex/.local/share/nvim/mason/packages/lua-language-server/extension/server/bin/lua-language-server: No such file or directory\n"
Expected behavior
Maybe we can have a post install hook where we patch the elf or we maybe that is just the wrong way and the right way would be to bring mason into home-manager. 🤷 That's why I am asking 🙂
Healthcheck
Screenshots or recordings
No response
The text was updated successfully, but these errors were encountered: