nix-community / crate2nix

rebuild only changed crates in CI with crate2nix and nix
https://nix-community.github.io/crate2nix/
Apache License 2.0
354 stars 83 forks source link

Can't fetch git dependency that is a workspace #207

Open JonathanLorimer opened 3 years ago

JonathanLorimer commented 3 years ago

I am getting this error, and I think it is because the git dependency that is being fetched is a workspace. Here is the dependency that is being fetched https://github.com/informalsystems/modelator. This is the Cargo.toml is failing when I call generatedCargoNix on this workspace

Error: while retrieving metadata about ./Cargo.toml: Error during execution of `cargo metadata`: error:
 failed to get `anomaly` as a dependency of package `ibc v0.6.0 (/build/source/modules)`

Caused by:
  failed to load source for dependency `anomaly`

Caused by:
  Unable to update registry `https://github.com/rust-lang/crates.io-index`

Caused by:
  failed to update replaced source registry `https://github.com/rust-lang/crates.io-index`

Caused by:
  found a virtual manifest at `/nix/store/pd6m24q5jz3i3csxlm0gppwjkgqicg06-deps/a08p33ghcl1dix9c96i1dpgd9g8wqdda-modelator-0.1.0/Cargo.toml` instead of a package manifest

crate2nix failed.
== cargo/config (BEGIN)
    [source.crates-io]
    replace-with = "vendored-sources"

    [source."https://github.com/informalsystems/modelator"]
    git = "https://github.com/informalsystems/modelator"
    rev = "99f656fa8b3cf46a2aa0b6513e4e140d1778c4bd"

    replace-with = "vendored-sources"

    [source.vendored-sources]
    directory = "/nix/store/pd6m24q5jz3i3csxlm0gppwjkgqicg06-deps"

== cargo/config (END)

== crate-hashes.json (BEGIN)
    {"modelator 0.1.0 (git+https://github.com/informalsystems/modelator?rev=99f656fa8b3cf46a2aa0b6513e4e140d1778c4bd#99f656fa8b3cf46a2aa0b6513e4e140d1778c4bd)":"8532d146bd6d80f31e12285ebb7938e340226f7066a52deb4db126b16fc57ec8"}
== crate-hashes.json (END)
JonathanLorimer commented 3 years ago

Okay, after doing some more digging this got even weirder. If I just use crate2nix generate from within the directory, everything works as expected. Are there any notable differences between invokign crate2nix generate directly and using generatedCargoNix ?

JonathanLorimer commented 3 years ago

If it helps at all, the crate-hashes.json created by the generatedCargoNix is different from the crate-hashes.json generated when I call crate2nix generate

generatedCargoNix

{
"modelator 0.1.0 (git+https://github.com/informalsystems/modelator?rev=99f656fa8b3cf46a2aa0b6513e4e140d1778c4bd#99f656fa8b3cf46a2aa0b6513e4e140d1778c4bd)":"8532d146bd6d80f31e12285ebb7938e340226f7066a52deb4db126b16fc57ec8"}

crate2nix generate

{
  "modelator 0.1.0 (git+https://github.com/informalsystems/modelator?rev=99f656fa8b3cf46a2aa0b6513e4e140d1778c4bd#99f656fa8b3cf46a2aa0b6513e4e140d1778c4bd)": "1j3yqmpv29mi9pmjv9b6f1pj4h7371wvnpi828gg703dpm3d2cl5"
}
auscyber commented 3 years ago

it doesn't even follow the revision, the revision is incorrect

JonathanLorimer commented 3 years ago

@AusCyberman I'm a bit confused, are you saying that the revision I am using for informalsystems/modelator is incorrect? Unfortunately I am not in control of the upstream Cargo.toml that references the modelator revision. I do believe that the revision is present though https://github.com/informalsystems/modelator/commit/99f656fa8b3cf46a2aa0b6513e4e140d1778c4bd.

If the URL that crate2nix generates is incorrect, then perhaps that is the bug?

auscyber commented 3 years ago

@AusCyberman I'm a bit confused, are you saying that the revision I am using for informalsystems/modelator is incorrect? Unfortunately I am not in control of the upstream Cargo.toml that references the modelator revision. I do believe that the revision is present though informalsystems/modelator@99f656f.

If the URL that crate2nix generates is incorrect, then perhaps that is the bug?

Oh, i mean im having a similar problem, and thats its even worse than your describing

marius851000 commented 2 years ago

I am working on a PR that would fix this issue (+other issue preventing compiling Veloren with this. I think it isn’t the first issue mentionning Veloren btw).

The issue that prevented me to using it is 1. an issue with making sure each git repo is only overriden a single time (when there are no reason for it to be overrided twice, resulting in duplicated key and thus error) and the vendered library given as input to the crate2nix binary being the whole workspace instead of just the subdirectory containing the crate as expected by Cargo.

I still have to find a good way to find the package folder (currenctly using hardcoded to check if it worked), but it shouldn’t be too hard to implement that somehow (maybe in a subcommand of crate2nix?). I just need to check the name of all crates referenced in the workspace to see if they match the one being vendored.

marius851000 commented 2 years ago

I’m dumb enougth that I forgot I already implemented this. https://github.com/kolloch/crate2nix/pull/166/files