You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
cargo metadata fails when the target Cargo.toml is inside a read-only filesystem.
I'm on Nixos and I'd like to write a compiler plugin so I need rustc sources.
In particular, I need rust-analyzer to load rustc sources.
To do so, RA uses cargo metadata to locate the rustc sources.
However, when running cargo metadata it attempts to create a Cargo.lock file which fails because Rust is installed in the nix store which is read-only.
Here is the command output :
$ "/nix/store/v0769idpz76l6b3xff8ps98bcsy5ymjb-rust-default-1.80.0-nightly-2024-05-20/bin/cargo" "metadata" "--format-version" "1" "--manifest-path" "/nix/store/v0769idpz76l6b3xff8ps98bcsy5ymjb-rust-default-1.80.0-nightly-2024-05-20/lib/rustlib/rustc-src/rust/compiler/rustc/Cargo.toml" "--filter-platform" "x86_64-unknown-linux-gnu"
Updating crates.io index
error: failed to write /nix/store/v0769idpz76l6b3xff8ps98bcsy5ymjb-rust-default-1.80.0-nightly-2024-05-20/lib/rustlib/rustc-src/rust/compiler/rustc/Cargo.lock
Caused by:
failed to open: /nix/store/v0769idpz76l6b3xff8ps98bcsy5ymjb-rust-default-1.80.0-nightly-2024-05-20/lib/rustlib/rustc-src/rust/compiler/rustc/Cargo.lock
Caused by:
Read-only file system (os error 30)
Here is the rust-analyzer log from which I got the command :
2024-08-10T20:19:02.972263Z ERROR project_model::workspace: Failed to read Cargo metadata from rustc source at /nix/store/v0769idpz76l6b3xff8ps98bcsy5ymjb-rust-default-1.80.0-nightly-2024-05-20/lib/rustlib/rustc-src/rust/compiler/rustc/Cargo.toml e=Failed to run `cd "<project dir>" && RUSTUP_TOOLCHAIN="/nix/store/v0769idpz76l6b3xff8ps98bcsy5ymjb-rust-default-1.80.0-nightly-2024-05-20" "/nix/store/v0769idpz76l6b3xff8ps98bcsy5ymjb-rust-default-1.80.0-nightly-2024-05-20/bin/cargo" "metadata" "--format-version" "1" "--manifest-path" "/nix/store/v0769idpz76l6b3xff8ps98bcsy5ymjb-rust-default-1.80.0-nightly-2024-05-20/lib/rustlib/rustc-src/rust/compiler/rustc/Cargo.toml" "--filter-platform" "x86_64-unknown-linux-gnu"
Steps
Have or install Nix:
curl -L https://nixos.org/nix/install | sh
Create a directory for testing and the corresponding nix shell:
Thanks for the detailed use case. Really appreciate that!
This is a duplicate of #10096 as far as I can tell. We are working on providing a new flag --lockfile-path for an alternative location to write lockfile. That is expected to improve the situation. The implementation is almost done in #14326
I am going to close this in favour of #10096. Let's discuss the problem in one place then!
Problem
cargo metadata
fails when the target Cargo.toml is inside a read-only filesystem.I'm on Nixos and I'd like to write a compiler plugin so I need rustc sources.
In particular, I need
rust-analyzer
to load rustc sources.To do so, RA uses
cargo metadata
to locate the rustc sources.However, when running
cargo metadata
it attempts to create aCargo.lock
file which fails because Rust is installed in the nix store which is read-only.Here is the command output :
Here is the rust-analyzer log from which I got the command :
Steps
Create a
shell.nix
with the following content:nix-shell cargo metadata --manifest-path $RUST_PKG/lib/rustlib/rustc-src/rust/compiler/rustc/Cargo.toml
Possible Solution(s)
No response
Notes
No response
Version
The text was updated successfully, but these errors were encountered: