cachix / devenv

Fast, Declarative, Reproducible, and Composable Developer Environments
https://devenv.sh
Apache License 2.0
3.47k stars 252 forks source link

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

Open brizzbuzz opened 2 weeks ago

brizzbuzz commented 2 weeks ago

Describe the bug Hey :wave: 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

domenkozar commented 2 weeks ago

Can you reproduce without neovim, just running it manually?

FantomeBeignet commented 1 week ago

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 commented 6 days ago

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 commented 6 days ago

languages.rust.channel = "stable";

This line breaks it.

sandydoo commented 6 days ago

Upstream fix: https://github.com/nix-community/fenix/pull/147