Skip to content
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

Open
3 tasks done
klautcomputing opened this issue Sep 15, 2022 · 47 comments
Open
3 tasks done

Package does not run on NixOS #428

klautcomputing opened this issue Sep 15, 2022 · 47 comments

Comments

@klautcomputing
Copy link

klautcomputing commented Sep 15, 2022

I believe this to be an issue that should be addressed by maintainers of mason.nvim.

  • Yes

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

  • Yes

I've recently downloaded the latest plugin version of mason.nvim

  • Yes

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

mason: require("mason.health").check()
========================================================================
## mason.nvim report
  - OK: neovim version >= 0.7.0
  - WARNING: **Go**: not available
  - OK: **cargo**: `cargo 1.65.0-nightly (646e9a0b9 2022-09-02)`
  - WARNING: **luarocks**: not available
  - OK: **Ruby**: `ruby 3.0.4p208 (2022-04-12 revision 3fa771dded) [x86_64-linux]`
  - OK: **RubyGem**: `3.3.20`
  - WARNING: **Composer**: not available
  - WARNING: **PHP**: not available
  - OK: **npm**: `8.19.1`
  - OK: **node**: `v18.9.0`
  - OK: **python3**: `Python 3.10.6`
  - OK: **pip3**: `pip 22.2.2 from /home/leex/.local/lib/python3.10/site-packages/pip (python 3.10)`
  - OK: **javac**: `javac 17.0.4`
  - OK: **java**: `Picked up _JAVA_OPTIONS: -Dsun.java2d.uiScale=2`
  - WARNING: **julia**: not available
  - OK: **wget**: `GNU Wget 1.21.3 built on linux-gnu.`
  - OK: **curl**: `curl 7.84.0 (x86_64-pc-linux-gnu) libcurl/7.84.0 OpenSSL/1.1.1q zlib/1.2.12 brotli/1.0.9 zstd/1.5.2 libidn2/2.3.2 libssh2/1.10.0 nghttp2/1.47.0`
  - OK: **gzip**: `gzip 1.12`
  - OK: **tar**: `tar (GNU tar) 1.34`
  - OK: **bash**: `GNU bash, version 5.1.16(1)-release (x86_64-pc-linux-gnu)`
  - OK: **sh**: `Ok`
  - OK: **python3_host_prog**: `Python 3.10.6`
  - OK: GitHub API rate limit. Used: 1. Remaining: 59. Limit: 60. Reset: Thu 15 Sep 2022 12:46:29 PM PDT.

Screenshots or recordings

No response

@klautcomputing
Copy link
Author

klautcomputing commented Sep 15, 2022

Hope I picked the right issue type here. 🙂

@archite
Copy link

archite commented Sep 27, 2022

@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:

#! /usr/bin/env nix-shell
#! nix-shell -i bash -p patchelf

for binary in ${@}
do
  patchelf \
    --set-interpreter "$(cat ${NIX_CC}/nix-support/dynamic-linker)" \
    "${binary}"
done

I put this as fx_loader.sh. You can then call something like this:

./fix_linker.sh ~/.local/share/nvim/mason/packages/lua-language-server/extension/server/bin/lua-language-server

After that, it will work on NixOS.

@klautcomputing
Copy link
Author

@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?
I would like to explore what the best way could be to address this for all NixOS users. Patching the elf by hand all the time isn't ergonomic and definitely does not allow for other plugins like mason-tool-installer to be used.

@archite
Copy link

archite commented Sep 27, 2022

@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 configuration.nix:

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.

@williamboman
Copy link
Owner

williamboman commented Sep 27, 2022

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)

@budimanjojo
Copy link

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:

 ~/.local/share/nvim/mason/packages/lua-language-server/extension/server/bin/lua-language-server
exec: Failed to execute process '/home/budiman/.local/share/nvim/mason/packages/lua-language-server/extension/server/bin/lua-language-server': The file exists and is executable. Check the interpreter or linker?
 ~/.local/share/nvim/mason/bin/lua-language-server
/home/budiman/.local/share/nvim/mason/bin/lua-language-server: line 3: /home/budiman/.local/share/nvim/mason/pack
ages/lua-language-server/extension/server/bin/lua-language-server: No such file or directory

@archite
Copy link

archite commented Oct 13, 2022

@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.

@budimanjojo
Copy link

@archite thanks! But I can't get it to work by changing ld-linux-aarch64 to ld-linux-x86-64.

I also noticed that it's only affecting lua-language-server. All the others (most of them are nodejs applications and I also have mason-tool-installer to manage linting tools) are working fine in NixOS. Wondering if this is specific issue with sumneko_lua or the way mason handle it.
I think mason should declare where the ld location just like how it "force" neovim to use its own PATH? Or am I completely wrong?

@archite
Copy link

archite commented Oct 13, 2022

@budimanjojo on x86_64 it is ld-linux-x86-64.so.2. Many LSP servers are written in Node but a good number are not such as clangd, rnix, and many more. The problem I run into is that patching must be done anytime glibc changes which can be frustrating.

@budimanjojo
Copy link

@archite unfortunately it still doesn't work. I tried ld-linux-x86-64.so.2, ld-linux-x86_64.so.2 and ld-linux.so.2 (because it's in this path on my Ubuntu machine). Maybe I got another problem?

@archite
Copy link

archite commented Oct 13, 2022

@budimanjojo yeah, that was nixos specific. Sorry. If I get time I'll try and reproduce for you.

budimanjojo added a commit to budimanjojo/nix-config that referenced this issue Nov 18, 2022
@budimanjojo
Copy link

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?

I use mason instead of nixos to handle the binaries because I was already using mason before moving to nixos. And I still have some machines not using nix yet and I share the same nvimrc for all of them.

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 PATH settings in mason to append instead of prepend so I can just default to nixos provided package for stuffs that doesn't work in nixos (currently only sumneko-lua in my case).

@SergioQuijanoRey
Copy link

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?

@s1341
Copy link
Contributor

s1341 commented Dec 19, 2022

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 patchelf to both figure out what the interpreter should be (by inspecting nvim itself) and then to set the interpreter on the target binary. Non-ELF files will be ignored.

@budimanjojo
Copy link

budimanjojo commented Dec 19, 2022

@SergioQuijanoRey The commit to what I did is linked in this issue above. Basically I just set mason to prefer using system installed program if it's available with:

require('mason').setup {
  PATH = "append",
}

@s1341 awesome!

@SergioQuijanoRey
Copy link

SergioQuijanoRey commented Dec 19, 2022

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 bin_abs_path. My file structure is the following:

/home/sergio/.local/share/nvim/mason
├── bin
│  └── marksman -> ../packages/marksman/marksman
└── packages
   └── marksman
      ├── marksman
      └── mason-receipt.json

Also, executing the regex in my terminal does not work, I have to quote the regex to get results.

@s1341
Copy link
Contributor

s1341 commented Dec 19, 2022

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.

@SergioQuijanoRey
Copy link

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:

TODO -- bin_abs_path is /home/sergio/.local/share/nvim/mason/packages/marksman/extension/server/bin/marksman
TODO -- interpreter is /nix/store/hsk71z8admvgykn7vzjy11dfnar9f4r1-glibc-2.35-163/lib/ld-linux-x86-64.so.2

Mason fails with following message:

/home/sergio/.local/share/nvim/mason/packages/marksman/extension/server/bin/marksman: No such file or directory

When changing local bin_abs_path = pkg:get_install_path() .. "/" .. rel_path same Mason error shows (with different path of course). Any idea of what I am doing wrong?

Thanks you in advance for your patience.

@s1341
Copy link
Contributor

s1341 commented Dec 19, 2022

What is the actual path to the file you want to patch?

@williamboman
Copy link
Owner

So to generalize this you'd need to exclude the "/extension/server/bin/" component, as this is specific to the lua-language- server. This is needed because Mason has to write a wrapper bash script for lua-language-server because of reasons (I believe lua-language-server is currently the only package that installs a wrapper bash script, so it can be managed as an edge case).

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 os.execute.

@williamboman
Copy link
Owner

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.

@SergioQuijanoRey
Copy link

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:

/home/sergio/.local/share/nvim/mason
├── bin
│  └── marksman -> ../packages/marksman/marksman
└── packages
   └── marksman
      ├── marksman
      └── mason-receipt.json

So I guess that I want to patch file /home/sergio/.local/share/nvim/mason/marksman/marksman.

Doing so with prev lua code does nothing, as Client 1 quit with exit code 127 and signal 0 error keeps showing up.

@s1341
Copy link
Contributor

s1341 commented Dec 19, 2022

Check :LspInfo. Could be it is working.

@williamboman
Copy link
Owner

:LspLog is helpful for debugging too. You can also change log level :h vim.lsp.set_log_level()

@SergioQuijanoRey
Copy link

LspInfo gives me:

 Detected filetype:   markdown
 
 0 client(s) attached to this buffer: 
 
 Other clients that match the filetype: markdown
 
 Config: marksman
 	Refer to :h lspconfig-root-detection for help.
 	filetypes:         markdown
 	root directory:    Not found.
 	cmd:               marksman server
 	cmd is executable: true
 	autostart:         true
 	custom handlers:   
 
 Configured servers list: /texlab, r_language_server, sumneko_lua, marksman, rust_analyzer, pylsp, clangd, rnix

LspLog gives me:

[START][2022-12-19 20:33:49] LSP logging initiated
[ERROR][2022-12-19 20:33:49] .../vim/lsp/rpc.lua:733	"rpc"	"marksman"	"stderr"	"marksman: error while loading shared libraries: libz.so.1: cannot open shared object file: No such file or directory\n"

Any idea what is happening?

Again, thank you both for your immense patience

@s1341
Copy link
Contributor

s1341 commented Dec 19, 2022

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

@s1341
Copy link
Contributor

s1341 commented Dec 20, 2022

@williamboman did you give any more thought to the middleware api?

How about including nixos support directly in mason?

realeinherjar added a commit to realeinherjar/flakes that referenced this issue Jun 22, 2023
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
realeinherjar added a commit to realeinherjar/flakes that referenced this issue Jun 22, 2023
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
realeinherjar added a commit to realeinherjar/flakes that referenced this issue Jun 23, 2023
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
@lucascool12
Copy link

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.

@Vaisakhkm2625
Copy link

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,

NIXPKGS_ALLOW_UNFREE=1 nix-shell -p steam-run 
steam-run nvim 

for me, i am using lazyvim(in a different folder than personal config) with zsh, so

NIXPKGS_ALLOW_UNFREE=1 nix-shell -p steam-run --command zsh
NVIM_APPNAME=Lazyvim steam-run nvim

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

@SergioQuijanoRey
Copy link

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

@Vaisakhkm2625
Copy link

Vaisakhkm2625 commented Oct 19, 2023

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?
currently i am using steam-run trick, and,i it's amazingly just works, and doesn't add any delay... but internally in my mind, it feels wrong.😅

@SergioQuijanoRey
Copy link

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 😄

@Vaisakhkm2625
Copy link

Vaisakhkm2625 commented Oct 20, 2023

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

https://github.com/SergioQuijanoRey/dotfiles/blob/master/config_files/.config/nixos/shared/dev_packages.nix#L102-L130

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

@qwqawawow
Copy link

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

https://github.com/SergioQuijanoRey/dotfiles/blob/master/config_files/.config/nixos/shared/dev_packages.nix#L102-L130

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

@SergioQuijanoRey
Copy link

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

https://github.com/SergioQuijanoRey/dotfiles/blob/master/config_files/.config/nixos/shared/dev_packages.nix#L102-L130

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

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

@Et7f3
Copy link

Et7f3 commented Nov 8, 2023

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

loader /usr/bin/vim instead of /usr/bin/vim

PS: I don't use mason only nix just helping someone nix/guix user that want to use it.

@Fish1
Copy link

Fish1 commented Nov 16, 2023

This fixed it for me.

I added rust-analyzer to my nix config.
I installed rust-analyzer in mason.
Then I ran mv ~/.local/share/nvim/mason/bin/rust-analyzer ~/.local/share/nvim/mason/bin/rust-analyzer-backup
Then I ran cp /run/current-system/sw/bin/rust-analyzer ~/.local/share/nvim/mason/bin/

@victorfernandesraton
Copy link

This fixed it for me.

I added rust-analyzer to my nix config. I installed rust-analyzer in mason. Then I ran mv ~/.local/share/nvim/mason/bin/rust-analyzer ~/.local/share/nvim/mason/bin/rust-analyzer-backup Then I ran cp /run/current-system/sw/bin/rust-analyzer ~/.local/share/nvim/mason/bin/

What is suposted means? You setting as a home manager dofile or something like this?

@alexandru0-dev
Copy link

any idea how can i use somwthing like lazyvim with manually installed lsps?
currently i am using steam-run trick, and,i it's amazingly just works, and doesn't add any delay... but internally in my mind, it feels wrong.😅

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.
No need to call for
Only issue would be that if a package at some point needs a library which hasn't been "added" u need to add it to the nix-ld.libraries option.

@alexandru0-dev
Copy link

@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

aikooo7 pushed a commit to aikooo7/nvim-config that referenced this issue Jan 6, 2024
- Mason doesn't work very well with NixOS as shown here: williamboman/mason.nvim#428
henry40408 added a commit to henry40408/nixos-config that referenced this issue Jan 11, 2024
henry40408 added a commit to henry40408/nixos-config that referenced this issue Jan 13, 2024
* 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
@adibfarrasy
Copy link

adibfarrasy commented Mar 22, 2024

@alexandru0-dev mind sharing your NixOS configuration.nix? mine is something like this

{ config, pkgs, ... }:
{
  environment = {
    sessionVariables = rec {
      NIX_LD = pkgs.lib.mkForce "${pkgs.stdenv.cc}/nix-support/dynamic-linker";
    };
    variables = { 
      # Added only to satisfy the build. I don't use this as I rarely (if ever) use `nix-shell`.
      NIX_LD = pkgs.lib.mkForce "${pkgs.stdenv.cc}/nix-support/dynamic-linker";
    };
  };
  programs = {
        neovim = {
            enable = true;
            defaultEditor = true;
        };

        nix-ld = {
          enable = true;
	  libraries = with pkgs; [
            stdenv.cc.cc
            zlib
            fuse3
            icu
            zlib
            nss
            openssl
            curl
            expat
            # ...
	  ];
	};
  };	
}

however, when I run this in the terminal I couldn't get the LSP (gopls) to work

➜ echo $NIX_LD
/nix/store/ihhhd1r1a2wb4ndm24rnm83rfnjw5n0z-gcc-wrapper-12.3.0/nix-support/dynamic-linker
➜ cd $HOME/.local/share/nvim/mason/bin
nvim/mason/bin 
➜ ls gopls
gopls
➜ ./gopls
zsh: no such file or directory: ./gopls

any advice? rebooting doesn't work for me.

@alexandru0-dev
Copy link

@adibfarrasy i moved away from nix-ld pretty fast, as it wasn't working really that great with mason unfortunately
my actual solution is just to install lsp servers manually globally in my system

@klautcomputing
Copy link
Author

https://github.com/dundalek/lazy-lsp.nvim might be worth a look.

@Vaisakhkm2625
Copy link

Vaisakhkm2625 commented Mar 31, 2024

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....

Cian-H added a commit to Cian-H/My_NixOS_Config that referenced this issue Apr 9, 2024
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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests