Rust-analyzer in a nix shell + vscode, "failed to build proc-macro"

Hi,

I’ve recently moved to NixOS on my main computer after trying it on my server and come across a problem with my Rust + Bevy project. I use a flake to manage system dependencies and the rust toolchain as well as rust-analyzer. Using flake-compat I have a shell.nix that I can use with the nixEnvSelector code extension which seems to work fine.

rust-analyzer is erroring everywhere I use proc macros with error: “failed to build proc-macro”. There are a bunch of errors in the logs that look like this:

error: could not compile `syn` (lib) due to 2 previous errors
error: couldn't create a temp dir: No such file or directory (os error 2) at path "/tmp/nix-shell-34163-0/rustcGqyFCf"


error: aborting due to 1 previous error

Edit: This error also shows up: “proc-macro crate build data is missing dylib path”

Here’s my setup:

flake.nix
{
  description = "Environment for developing bevy project";

  # Flake inputs
  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
    flake-compat.url = "https://flakehub.com/f/edolstra/flake-compat/1.tar.gz";
  };

  # Flake outputs
  outputs = { self, nixpkgs, ... }:
    let
      # Systems supported
      allSystems = [
        "x86_64-linux" # 64-bit Intel/AMD Linux
        "aarch64-linux" # 64-bit ARM Linux
        "x86_64-darwin" # 64-bit Intel macOS
        "aarch64-darwin" # 64-bit ARM macOS
      ];

      # Helper to provide system-specific attributes
      forAllSystems = f: nixpkgs.lib.genAttrs allSystems (system: f {
        pkgs = import nixpkgs {
          inherit system;
        };
      });
    in
    {
      # Development environment output
      devShells = forAllSystems ({ pkgs }: {
        default = pkgs.mkShell rec {
            # The Nix packages provided in the environment
            packages = with pkgs; [
              rustc cargo rust-analyzer clippy rustfmt
              pkg-config
              udev alsa-lib vulkan-loader
              libxkbcommon wayland # Wayland dependencies
              xorg.libX11 xorg.libXcursor xorg.libXi xorg.libXrandr # X11 dependencies
            ];
            LD_LIBRARY_PATH = "${nixpkgs.lib.makeLibraryPath packages}";
            RUST_SRC_PATH = "${pkgs.rust.packages.stable.rustPlatform.rustLibSrc}";
          };
      });
    };
}
.vscode/settings.json

{
“nixEnvSelector.nixFile”: “${workspaceFolder}/shell.nix”,
“editor.formatOnSave”: true,
“rust-analyzer.server.path”: “rust-analyzer”,
}

shell.nix (copied from flake-compat)
(import
  (
    let
      lock = builtins.fromJSON (builtins.readFile ./flake.lock);
      nodeName = lock.nodes.root.inputs.flake-compat;
    in
    fetchTarball {
      url = lock.nodes.${nodeName}.locked.url or "https://github.com/edolstra/flake-compat/archive/${lock.nodes.${nodeName}.locked.rev}.tar.gz";
      sha256 = lock.nodes.${nodeName}.locked.narHash;
    }
  )
  { src = ./.; }
).shellNix

Thanks!