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

Some crates.io hashes cannot be found in Cargo.lock #370

Open
YPares opened this issue Nov 5, 2024 · 2 comments
Open

Some crates.io hashes cannot be found in Cargo.lock #370

YPares opened this issue Nov 5, 2024 · 2 comments

Comments

@YPares
Copy link

YPares commented Nov 5, 2024

I'm running into this:

Running phase: unpackPhase
@nix { "action": "setPhase", "phase": "unpackPhase" }
unpacking source archive /nix/store/qc74kg08frlgdjb5fjmwgvb0snpf45lx-unarchiver
source root is unarchiver
Running phase: buildPhase
@nix { "action": "setPhase", "phase": "buildPhase" }
++ crate2nix generate -f ./Cargo.toml -o Cargo-generated.nix -h /nix/store/2mwh4sn153gar2r2ay6x43l7752pr3v3-rustnix-crate2nix/crate-hashes.json
Did not find all crates.io hashes in Cargo.lock. Hashes for e.g. addr2line 0.24.2, adler 1.0.2, adler2 2.0.0, aho-corasick 1.1.3, android-tzdata 0.1.1, android_system_properties 0.1.5, async-channel 2.3.1, async-stream 0.3.6, async-stream-impl 0.3.6, async-trait 0.1.83 are missing.
This is probably a bug.
Prefetching    1/379: https://static.crates.io/crates/encoding_rs/encoding_rs-0.8.35.crate
Error: while prefetching crates for calculating sha256: While spawning 'nix-prefetch-url https://static.crates.io/crates/encoding_rs/encoding_rs-0.8.35.crate --name encoding_rs-0.8.35': No such file or directory (os error 2)
crate2nix failed.

It's difficult to make a minimal reproduction but just in case is it a known error? I tried running cargo update but that doesn't change anything.

@danieldk
Copy link
Contributor

danieldk commented Nov 22, 2024

You are bumping into this issue because, most likely, you have git dependency in Cargo.toml. crate2nix will try to determine the crate's hash by downloading the crate using nix-prefetch-git. However, nix-prefetch-git is not added as a dependency to the generatedCargoNix derivation. However, adding it is not going to help you much, since crate2nix runs in a sandbox, so it cannot fetch the crate over the network anyway.

The solution is to run crate2nix in your Rust source folder once. This will create a crate-hashes.json file that contains the fixed-output derivation hashes for the Rust crates that are fetched using git. Add this file to your Nix repo/flake and crate2nix will use it (and not attempt to call nix-prefetch-git).

@YPares
Copy link
Author

YPares commented Nov 22, 2024

@danieldk Thanks! I'll try that. I suppose then that I should re-run crate2nix manually everytime a git-provided crate has to change?
I'm not sure it's part of crate2nix documentation, could it be added? I think notable here: https://nix-community.github.io/crate2nix/00_guides/31_auto_generating/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants