artempyanykh / marksman

Write Markdown with code assist and intelligence in the comfort of your favourite editor.
MIT License
1.98k stars 35 forks source link

Prebuilt linux binary doesn't work on NixOS #245

Open j-steinbach opened 1 year ago

j-steinbach commented 1 year ago

I am definitely doing something wrong, but I don't know where/how.

I installed marksman via LazyVim mason/mason-lspconfig. I tried 'installing' it with just the default config, Folkes dotfiles config, the config mentioned here and the values mentioned in the install readme.

In Nvim I get the error

Spawning language server with cmd: /home/jst/.local/share/nvim/mason/bin/marksman failed. The language server is either not installed, missing from PATH, or not executable.

When I navigate to the folder, I see the binary (and/or the symlinked version). I can change it chmod +x and then try to run it, but I get

'./marksman server' terminated by signal SIGSEGV (Address boundary error)

This happens for 5 random releases I grabbed from the marksman 'releases' page.

But when installing marksman via my package manager (NixOS), I can run it just fine.

↳ marksman --version
1.0.0-2023-03-04
↳ marksman
[22:34:44 INF] <LSP Entry> Starting Marksman LSP server: {}

The same version from the release page fails again.

I am not sure if this is a marksman or a mason.nvim problem or if I am just doing something wrong. But I assumed that when I can't run the pre-compiled binary that I got from the repo, then this is the place to ask.

artempyanykh commented 1 year ago

Thanks for reporting @j-steinbach! I'd imagine the problem might be due to incompatible dynamic dependencies -- the marksman binary is linked statically but it still has some dynamic dependencies (e.g. libc); prebuilt binaries are built on Debian which may use different versions of dynamic libs compared to NixOS.

I'd love to have prebuilt binaries that work on NixOS too, but the PR would have to come from someone who actually knows their way around NixOS.

j-steinbach commented 1 year ago

I think this not only about marksman, as some other LSPs fail the same way(deno, selene, stylua). But others work (shfmt, prettierd). All installed via Mason. This could be a starting point when looking into this.

I am unfortunately a Nix noob, but maybe it is possible to Marksman as build input to the Neovim nixpkg. Might be a workaround. I'll see if I find time to try it this weekend (unlikely).

j-steinbach commented 1 year ago

Small workaround: I changed the cmd in my mason/lspconfig to cmd = { "/etc/profiles/per-user/jst/bin/marksman", "server" },, which is the path to my system Marksman install (which marksman). Not pretty but at least it gets it to work. Old version though.

Thesola10 commented 10 months ago

Highly recommend using the Nix package for Marksman on NixOS. Changing the cmd to something like { "nix", "run", "nixpkgs#marksman", "--", "server" } will work.

A more polished config with Nix-provided LSP can be found on my Gitea

kik4444 commented 5 months ago

While this issue is being dealt with, here's my two cents. I use LazyVim and enabled the markdown extra by adding this line to my nvim/lua/config/lazy.lua

{ import = "lazyvim.plugins.extras.lang.markdown" },

The source code is available here. This automatically configures nvim-lspconfig to use the marksman downloaded by mason which is not what we want. Instead I added this to my plugins to maintain compatibility with anything non-NixOS

return {
  {
    "neovim/nvim-lspconfig",
    opts = {
      servers = {
        -- Because the official marksman has dynamic lib issues on NixOS
        -- Remember to install marksman manually
        marksman = {
          cmd = {
            "sh",
            "-c",
            "test -x /run/current-system/sw/bin/marksman && { /run/current-system/sw/bin/marksman server; } || { marksman server; }",
          },
        },
      },
    },
  },
}