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

Stop fabricating PackageId and look it up instead #341

Merged
merged 1 commit into from
Apr 6, 2024

Conversation

pacak
Copy link
Contributor

@pacak pacak commented Apr 3, 2024

  • lock.rs: get rid of confusing Metadata type alias
  • IndexedMetadata::new_from_merged doesn't consume MergedMetadata
  • Lookup PackageId in resolved metadata

Fixes #340

@kolloch
Copy link
Collaborator

kolloch commented Apr 6, 2024

Hey @pacak,

thanks for trying to address this! I believe the general direction is the right one, even though I forgot much about the context in the code since it is quite a long time that I wrote (parts of) it. Let me comment on the easy to agree with parts:

  • lock.rs: get rid of confusing Metadata type alias

Note that this is code copied from elsewhere, so potentially it would be worth it to keep it closer to the source, but hey, I merged it.

  • IndexedMetadata::new_from_merged doesn't consume MergedMetadata

Makes sense, since it doesn't reuse anything anyways

@kolloch
Copy link
Collaborator

kolloch commented Apr 6, 2024

I noticed that you removed quite some tests, can you comment on that?

@@ -66,88 +82,6 @@ impl EncodableResolve {
}
}

#[test]
fn test_no_legacy_checksums() {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please don't delete them, rather add some for the new cases :)

crate2nix/src/lock.rs Outdated Show resolved Hide resolved
kolloch added a commit that referenced this pull request Apr 6, 2024
@pacak
Copy link
Contributor Author

pacak commented Apr 6, 2024

Note that this is code copied from elsewhere, so potentially it would be worth it to keep it closer to the source

I don't have strong opinions about it, but knowing that we are working with cargo-metadata- I assumed that it was Metadata from that crate and tried to use it accordingly, wasting some time. Just wanted to save this trouble for other people.

I noticed that you removed quite some tests, can you comment on that?

New code relies on info from cargo-metadata, tests don't have it included. Faking might work but it isn't the best idea. For as long as this crate uses itself to generate its own Cargo.nix this serves as a test for current lock file format. Legacy might or might not work, but using the most recent crate2nix with very old rust tool chain...

instead of trying to create ourselves using information available:
internal representation is not stable.

Sadly tests had to go
@kolloch
Copy link
Collaborator

kolloch commented Apr 6, 2024

I would like the code supporting for the old legacy formats tested.

Not sure how to decide that it is not needed anymore, then the code could be removed and the tests as well. But I'd not like to do that without a deprecation period.

@pacak
Copy link
Contributor Author

pacak commented Apr 6, 2024

Not sure how to decide that it is not needed anymore, then the code could be removed and the tests as well. But I'd not like to do that without a deprecation period.

Comment calling it legacy was added in January 2020, so at most 1.42 - 35 rust releases ago. crate2nix requires at least 1.56 to compile - it uses 2021 edition, actual MSRV might be higher due to dependencies. I'd say it is safe to drop the support right now but it goes outside of the scope for this pull request.

@kolloch
Copy link
Collaborator

kolloch commented Apr 6, 2024

Still, can we add tests for the new stuff?

Sure, it will probably fail elsewhere if there is a problem.

But it is usually easier to understand with more specific tests.

@pacak
Copy link
Contributor Author

pacak commented Apr 6, 2024

Still, can we add tests for the new stuff?

Will look into that when I have free time.

@kolloch kolloch merged commit 640584d into nix-community:master Apr 6, 2024
2 checks passed
@flokli
Copy link
Contributor

flokli commented Apr 10, 2024

@kolloch can you publish a release with this?

@kolloch
Copy link
Collaborator

kolloch commented Apr 11, 2024

Done, hopefully not too rushed.

@flokli
Copy link
Contributor

flokli commented Apr 11, 2024

Thanks! I opened NixOS/nixpkgs#303309 so nixpkgs has the fix too.

@Ten0
Copy link

Ten0 commented May 1, 2024

Not sure if that's relevant but IFD code seems to still generate such IDs with old format to store them in crate-hashes.json, while Rust code now generates those with the new format.
Looking at #340 (comment), it seems that it may be what's causing #348 (not sure though because even when giving to IFD extra hashes from manually generated crate-hashes.json I still observe #348).

@pacak
Copy link
Contributor Author

pacak commented May 1, 2024

I'm seeing stuff like this which suggests new format. Old format comes from old version of cargo.

  "git+https://github.com/nix-rust/nix?rev=fbdac70c78975fe7c75b882337bf9f40a639f51a#0.25.0": "1jvls4d90ns5qwqab1a2hcyff2dlls1q4i5xl6cs09a371g5h7b3",

@pacak
Copy link
Contributor Author

pacak commented May 2, 2024

And in case of #340 it was working, but wasn't able to use cache so I don't think it's related.

@Ten0
Copy link

Ten0 commented May 2, 2024

Even with rust 1.77.1 being used everywhere, I see IFD like this:

++ crate2nix generate -f ./.cargo/workspace/Cargo.toml -o Cargo-generated.nix -h /nix/store/f443x0imd2b8r7gb5jkyai9j32y6xhmv-proj-crate2nix/crate-hashes.json
Error: while retrieving metadata about ./.cargo/workspace/Cargo.toml:

with /nix/store/f443x0imd2b8r7gb5jkyai9j32y6xhmv-proj-crate2nix/crate-hashes.json containing stuff like this:

{
  "lightgbm-sys 0.3.0 (git+https://github.com/Ten0/lightgbm-rs.git?branch=for_proj_main#ebc5262299d75cc770e21416f9e3ef8204427fba)": "0nr42asw4sg7q7xrkg565ivl1s9b6g75kflzy9hvl3srqrnxf10z"
}

which seems to be old format.

Isn't it generated on the nix side in the case of IFD?

echo -n '${builtins.toJSON vendor.extendedHashes}' | jq > "$crate_hashes"

Indeed it does not seem related to #348.

@pacak
Copy link
Contributor Author

pacak commented May 2, 2024

Isn't it generated on the nix side in the case of IFD?

crate2nix/tools.nix

Lines 246 to 249 in cf03486

rec {
toPackageId = { name, version, source, ... }:
"${name} ${version} (${source})";

Looks like it indeed. That's not going to work...

@flokli
Copy link
Contributor

flokli commented May 2, 2024

I just ran crate2nix generate --all-features with the more recent rust version (not inside IFD), and crate2nix started to manually add all crate hashes into crate-hashes.json, not just for the ones for which there are no hashes in Cargo.lock - so definitely something still seems to be off.

Note it however still builds for me…

@pacak
Copy link
Contributor Author

pacak commented May 2, 2024

I just ran crate2nix generate --all-features with the more recent rust version (not inside IFD)

Is this using crate2nix after the change, 0.14.0? Anything public or any reproduction? Works for me...

@flokli
Copy link
Contributor

flokli commented May 2, 2024

Hmmh, no, indeed I'm still on 0.13.0 for some reason. I'll get this bumped and will report back.

@flokli
Copy link
Contributor

flokli commented May 2, 2024

Indeed, this fixed it. Sorry for the noise!

tvlbot pushed a commit to tvlfyi/tvix that referenced this pull request May 3, 2024
Since a recent nixpkgs bump bringing a version of cargo with
rust-lang/cargo#12914,
crate2nix creates a crate-hashes.json with all crate hashes from
Cargo.lock (and downloads a lot of stuff while producing it).

nix-community/crate2nix#341 prevents this from
happening, but our hardcoded crate2nix pin prevented us from getting the
fix included in 0.14.0, which did land in nixpkgs.

Replace the pin with a simply override, carrying our only leftover patch
on top of it, and link to that PR.

Change-Id: I9503898e15d61fa6a2b1589d141bec1b4ed3d616
Reviewed-on: https://cl.tvl.fyi/c/depot/+/11581
Autosubmit: flokli <flokli@flokli.de>
Tested-by: BuildkiteCI
Reviewed-by: sterni <sternenseemann@systemli.org>
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

Successfully merging this pull request may close these issues.

Crate hash loading from Cargo.lock is broken in Rust 1.77
4 participants