Skip to content

Conversation

@jrobsonchase
Copy link

@jrobsonchase jrobsonchase commented Dec 23, 2025

Builds on #413 and #381.

Run a nix flake update and fix problems that arise.

hallettj and others added 7 commits January 23, 2025 00:15
Crate2nix identifies packages using package ID strings reported by the
`cargo metadata` subcommand. Cargo describes these strings as internal
identifiers subject to change. And in fact the string format did change
sometime between cargo 1.76 and cargo 1.78.

In cargo 1.76 package ID strings look like this:

```
aho-corasick 1.1.3 (registry+https://github.com/rust-lang/crates.io-index)
```

In later cargo versions the format changed to look like this:

```
registry+https://github.com/rust-lang/crates.io-index#aho-corasick@1.1.3
```

The change is fine as long as package IDs are used as opaque
identifiers in memory. Unfortunately one use of package IDs is to look
up checksums in the legacy v1 `Cargo.lock` manifest format. That format
stores checksums in a map at the end of the file that looks like this:

```toml
[metadata]
"checksum ansi_term 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ee49baf6cb617b853aa8d93bf420db2383fab46d314482ca2803b40d5fde979b"
"checksum atty 0.2.13 (registry+https://github.com/rust-lang/crates.io-index)" = "1803c647a3ec87095e7ae7acfca019e98de5ec9a7d01343f611cf3152ed71a90"
"checksum autocfg 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "1d49d90015b3c36167a20fe2810c5cd875ad504b39cff3d4eae7977e6b7c1cb2"
```

Being a legacy format the keys in these checksum maps will always use
the old package ID format. The problem becomes quickly apparent because
nix-test-runner - which is used in the crate2nix test suite - happens to
use a v1 manifest. That leads to tests and the devShell breaking when
attempting to update crate2nix flake inputs.

Currently crate2nix assumes that package IDs read from `cargo metadata`
output can be used as lookup keys in the v1 checksum map. But when
a recent version of cargo is installed that assumption is broken.

This PR fixes the problem by constructing checksum lookup keys
explicitly. This should make checksum lookups work regardless of which
cargo version is installed.
Comment on lines +5 to +9
{ system
, pkgs ? import
"${builtins.fetchTree (builtins.getAttr flakeLock.nodes.crate2nix_stable.inputs.nixpkgs flakeLock.nodes)
.locked}"
{ inherit system; }
Copy link
Author

Choose a reason for hiding this comment

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

This is the first point where I noticed the new nixpkgs causing problems. It wasn't enough to use the stable crate2nix - it had to be the stable crate2nix with the same nixpkgs to get this working.

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.

2 participants