dev-templates icon indicating copy to clipboard operation
dev-templates copied to clipboard

rust-analyzer support in vscode

Open Michael-J-Ward opened this issue 1 year ago • 0 comments

rust-analyzer support in vscode

In order for rust analyzer fails because it needs rust-src. Using oxalica's cheat-sheet, I was able to achieve that. However, I am unsure if this is the optimal way to do so, so I'm merely reproducing it below.

{
  description = "A Nix-flake-based Rust development environment";

  inputs = {
    flake-utils.url = "github:numtide/flake-utils";
    nixpkgs.url = "github:NixOS/nixpkgs";
    rust-overlay.url = "github:oxalica/rust-overlay";
  };

  outputs =
    { self
    , flake-utils
    , nixpkgs
    , rust-overlay
    }:

    flake-utils.lib.eachDefaultSystem (system:
    let
      overlays = [
        (import rust-overlay)
        (self: super: {
          rustToolchain =
            let
              rust = super.rust-bin;
              toolchain =
                if builtins.pathExists ./rust-toolchain.toml then
                  rust.fromRustupToolchainFile ./rust-toolchain.toml
                else if builtins.pathExists ./rust-toolchain then
                  rust.fromRustupToolchainFile ./rust-toolchain
                else
                  rust.stable.latest.default;
            in
            toolchain.override {
              extensions = [ "rust-src" ];
            };
        })
      ];

      pkgs = import nixpkgs { inherit system overlays; };
    in
    {
      devShell = pkgs.mkShell {
        nativeBuildInputs = with pkgs; [
          rustToolchain
          # rust-src
          openssl
          pkg-config
          cargo-audit
          cargo-deny
          cargo-cross
          rust-analyzer
        ] ++ pkgs.lib.optionals (pkgs.stdenv.isLinux) (with pkgs; [ cargo-watch ]); # Currently broken on macOS

        shellHook = ''
          ${pkgs.rustToolchain}/bin/cargo --version
        '';
      };
    });
}

Michael-J-Ward avatar Sep 27 '22 15:09 Michael-J-Ward