git.iko.soy/typeable/nixpkgs
on master help sign in
rustPlatform.importCargoLock: add an assert for old Cargo.locks

near the end of 2019, the default Cargo.lock format was changed to [[package]] checksum = ... This is what importCargoLock assumes. If the crate had not been `cargo update`'d with a more recent toolchain than the one with the new format as default, importCargoLock would fail when trying to access pkg.checksum. I ran into such a case (shamefully, in my own crate) and it took me a while to figure out what was going on, so here is an assert with a more user friendly message and a hint.

commit23dd37dd5ed22cc0ad296698330a9ecd1e26c16c authorRomanos Skiadas <rom.skiad@gmail.com> dateSat 17 Jul 2021, 18:02 (5 years ago) parentab9a0ee
1 file changed+13−5
pkgs/build-support/rust/import-cargo-lock.nix+13−5
pkgs/build-support/rust/import-cargo-lock.nix+13−5
@@ -63,11 +63,19 @@ let
6363
6464 # We can't use the existing fetchCrate function, since it uses a
6565 # recursive hash of the unpacked crate.
66− fetchCrate = pkg: fetchurl {
67− name = "crate-${pkg.name}-${pkg.version}.tar.gz";
68− url = "https://crates.io/api/v1/crates/${pkg.name}/${pkg.version}/download";
69− sha256 = pkg.checksum;
70− };
66+ fetchCrate = pkg:
67+ assert lib.assertMsg (pkg ? checksum) ''
68+ Package ${pkg.name} does not have a checksum.
69+ Please note that the Cargo.lock format where checksums used to be listed
70+ under [metadata] is not supported.
71+ If that is the case, running `cargo update` with a recent toolchain will
72+ automatically update the format along with the crate's depenendencies.
73+ '';
74+ fetchurl {
75+ name = "crate-${pkg.name}-${pkg.version}.tar.gz";
76+ url = "https://crates.io/api/v1/crates/${pkg.name}/${pkg.version}/download";
77+ sha256 = pkg.checksum;
78+ };
7179
7280 # Fetch and unpack a crate.
7381 mkCrate = pkg: