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

Cannot run rust + rust-analyzer when configured via devenv #1143

Closed
brizzbuzz opened this issue Apr 17, 2024 · 7 comments
Closed

Cannot run rust + rust-analyzer when configured via devenv #1143

brizzbuzz opened this issue Apr 17, 2024 · 7 comments
Labels
bug Something isn't working

Comments

@brizzbuzz
Copy link

Describe the bug
Hey 👋 currently, rust-analyzer will crash with the following when neovim attempts to attach to it

[ERROR][2024-04-17 15:25:35] .../vim/lsp/rpc.lua:734	"rpc"	"rust-analyzer"	"stderr"	"rust-analyzer: error while loading shared libraries: librustc_driver-cf038663a889d84a.so: cannot open shared object file: No such file or directory\n"

To reproduce

Current flake

{
  inputs = {
    nixpkgs.url = "github:cachix/devenv-nixpkgs/rolling";
    nixpkgs-unstable.url = "github:NixOS/nixpkgs/nixos-unstable";
    systems.url = "github:nix-systems/default";
    devenv.url = "github:cachix/devenv";
    devenv.inputs.nixpkgs.follows = "nixpkgs";
    fenix.url = "github:nix-community/fenix";
    fenix.inputs.nixpkgs.follows = "nixpkgs-unstable";
  };

  nixConfig = {
    extra-trusted-public-keys = "devenv.cachix.org-1:w1cLUi8dv3hnoSPGAuibQv+f9TZLr6cv/Hm9XgU50cw=";
    extra-substituters = "https://devenv.cachix.org";
  };

  outputs = {
    self,
    nixpkgs,
    nixpkgs-unstable,
    devenv,
    systems,
    ...
  } @ inputs: let
    forEachSystem = nixpkgs.lib.genAttrs (import systems);
  in {
    packages = forEachSystem (system: {
      devenv-up = self.devShells.${system}.default.config.procfileScript;
    });

    devShells =
      forEachSystem
      (system: let
        pkgs = nixpkgs.legacyPackages.${system};
        pkgs-unstable = nixpkgs-unstable.legacyPackages.${system};
      in {
        default = devenv.lib.mkShell {
          inherit inputs pkgs;
          modules = [
            {
              languages.rust.enable = true;
              languages.rust.channel = "stable";

              packages =
                (with pkgs; [
                  atlas
                  watchexec
                  xh
                ])
                ++ (with pkgs-unstable; [
                  git-cliff
                  tailwindcss
                ]);

              services.postgres = {
                enable = true;
                package = pkgs.postgresql_15;
                initialDatabases = [{name = "rentirement";}];
                extensions = extensions: [];
              };

              processes = {
                server.exec = "watchexec --restart --exts go,templ -- go run main.go";
                tailwind.exec = "watchexec --restart --exts go,css,temple -- tailwindcss -i input.css -o assets/style.css";
                templ.exec = "watchexec --restart --exts templ -- templ generate";
              };

              enterShell = ''
              '';
            }
          ];
        };
      });
  };
}

Then, load the shell and attempt to run neovim with the rust-analyzer lsp attached via lsp config.

Make sure to include full logs and what you expected to happen.

Version

Paste the output of $ devenv version here.

devenv: 1.0.4

@brizzbuzz brizzbuzz added the bug Something isn't working label Apr 17, 2024
@domenkozar
Copy link
Member

Can you reproduce without neovim, just running it manually?

@FantomeBeignet
Copy link

I'm running into the same issue, trying to invoke rust-analyzer from the cli will fail in the same way:

rust-analyzer: error while loading shared libraries: librustc_driver-b8025a1ae2c7defc.so: cannot open shared object file: No such file or directory

@sandydoo
Copy link
Member

It's missing rpath for some reason 🤔

➜ readelf -d $(which rust-analyzer)

Dynamic section at offset 0x199c3d8 contains 34 entries:
  Tag        Type                         Name/Value
 0x0000000000000001 (NEEDED)             Shared library: [librustc_driver-4766cc27bbc2a07e.so]
 0x0000000000000001 (NEEDED)             Shared library: [libstd-f0ae9f5a3e408c19.so]
 0x0000000000000001 (NEEDED)             Shared library: [libdl.so.2]
 0x0000000000000001 (NEEDED)             Shared library: [libgcc_s.so.1]
 0x0000000000000001 (NEEDED)             Shared library: [libpthread.so.0]
 0x0000000000000001 (NEEDED)             Shared library: [libm.so.6]
 0x0000000000000001 (NEEDED)             Shared library: [libc.so.6]
 0x000000000000001d (RUNPATH)            Library runpath: []
 0x000000000000000c (INIT)               0x1f0f88
 0x000000000000000d (FINI)               0x132f344
 0x0000000000000019 (INIT_ARRAY)         0x18a7120
 0x000000000000001b (INIT_ARRAYSZ)       24 (bytes)
 0x000000000000001a (FINI_ARRAY)         0x18a7138
 0x000000000000001c (FINI_ARRAYSZ)       8 (bytes)
 0x0000000000000004 (HASH)               0x27d0000
 0x0000000000000005 (STRTAB)             0x27e0000
 0x0000000000000006 (SYMTAB)             0x16a0
 0x000000000000000a (STRSZ)              29865 (bytes)
 0x000000000000000b (SYMENT)             24 (bytes)
 0x0000000000000015 (DEBUG)              0x0
 0x0000000000000003 (PLTGOT)             0x19ac638
 0x0000000000000002 (PLTRELSZ)           10056 (bytes)
 0x0000000000000014 (PLTREL)             RELA
 0x0000000000000017 (JMPREL)             0x1ee840
 0x0000000000000007 (RELA)               0xb858
 0x0000000000000008 (RELASZ)             1978344 (bytes)
 0x0000000000000009 (RELAENT)            24 (bytes)
 0x0000000000000018 (BIND_NOW)
 0x000000006ffffffb (FLAGS_1)            Flags: NOW ORIGIN PIE
 0x000000006ffffffe (VERNEED)            0xb7b8
 0x000000006fffffff (VERNEEDNUM)         5
 0x000000006ffffff0 (VERSYM)             0xb43e
 0x000000006ffffff9 (RELACOUNT)          82152
 0x0000000000000000 (NULL)               0x0

@sandydoo
Copy link
Member

languages.rust.channel = "stable";

This line breaks it.

@sandydoo
Copy link
Member

Upstream fix: nix-community/fenix#147

@diefans
Copy link

diefans commented May 13, 2024

just tried https://github.com/cachix/devenv/blob/main/examples/rust/devenv.nix and got same result...

inputs:
  nixpkgs:
    url: github:cachix/devenv-nixpkgs/rolling
  fenix:
    # broken rust-analyzer
    # url: github:nix-community/fenix
    url: github:sandydoo/fenix/patch-rust-analyzer-preview
    inputs:
      nixpkgs:
        follows: nixpkgs

for me the upstream fix works...

@sandydoo
Copy link
Member

The upstream fenix fix has been merged. Don't forget to update your inputs: nix flake update fenix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

5 participants