Cargo 1.84.0 broke fetchCargoTarball hashes, so fetchCargoTarball is not long for this world. Tell people to use fetchCargoVendor, which Nixpkgs is currently in the process of switching to across the tree.
···26262727rustPlatform.buildRustPackage rec {
2828 pname = "ripgrep";
2929- version = "12.1.1";
2929+ version = "14.1.1";
30303131 src = fetchFromGitHub {
3232 owner = "BurntSushi";
3333 repo = pname;
3434 rev = version;
3535- hash = "sha256-+s5RBC3XSgb8omTbUNLywZnP6jSxZBKSS1BmXOjRF8M=";
3535+ hash = "sha256-gyWnahj1A+iXUQlQ1O1H1u7K5euYQOld9qWm99Vjaeg=";
3636 };
37373838- cargoHash = "sha256-jtBw4ahSl88L0iuCXxQgZVm1EcboWRJMNtjxLVTtzts=";
3838+ useFetchCargoVendor = true;
3939+ cargoHash = "sha256-9atn5qyBDy4P6iUoHFhg+TV6Ur71fiah4oTJbBMeEy4=";
39404041 meta = {
4142 description = "Fast line-oriented regex search tool, similar to ag and ack";
···6364}
6465```
65666666-Exception: If the application has cargo `git` dependencies, the `cargoHash`
6767-approach will not work by default. In this case, you can set `useFetchCargoVendor = true`
6868-to use an improved fetcher that supports handling `git` dependencies.
6969-7070-```nix
7171-{
7272- useFetchCargoVendor = true;
7373- cargoHash = "sha256-RqPVFovDaD2rW31HyETJfQ0qVwFxoGEvqkIgag3H6KU=";
7474-}
7575-```
7676-7777-If this method still does not work, you can resort to copying the `Cargo.lock` file into nixpkgs
6767+If this method does not work, you can resort to copying the `Cargo.lock` file into nixpkgs
7868and importing it as described in the [next section](#importing-a-cargo.lock-file).
79698070Both types of hashes are permitted when contributing to nixpkgs. The
···119109 hash = "sha256-aDQA4A5mScX9or3Lyiv/5GyAehidnpKKE0grhbP1Ctc=";
120110 };
121111122122- cargoHash = "sha256-tbrTbutUs5aPSV+yE0IBUZAAytgmZV7Eqxia7g+9zRs=";
112112+ useFetchCargoVendor = true;
113113+ cargoHash = "sha256-iDYh52rj1M5Uupvbx2WeDd/jvQZ+2A50V5rp5e2t7q4=";
123114 cargoDepsName = pname;
124115125116 # ...
···443434444435Since network access is not allowed in sandboxed builds, Rust crate
445436dependencies need to be retrieved using a fetcher. `rustPlatform`
446446-provides the `fetchCargoTarball` fetcher, which vendors all
437437+provides the `fetchCargoVendor` fetcher, which vendors all
447438dependencies of a crate. For example, given a source path `src`
448448-containing `Cargo.toml` and `Cargo.lock`, `fetchCargoTarball`
439439+containing `Cargo.toml` and `Cargo.lock`, `fetchCargoVendor`
449440can be used as follows:
450441451442```nix
452443{
453453- cargoDeps = rustPlatform.fetchCargoTarball {
444444+ cargoDeps = rustPlatform.fetchCargoVendor {
454445 inherit src;
455446 hash = "sha256-BoHIN/519Top1NUBjpB/oEMqi86Omt3zTQcXFWqrek0=";
456447 };
···482473```
483474484475If a `Cargo.lock` file is available, you can alternatively use the
485485-`importCargoLock` function. In contrast to `fetchCargoTarball`, this
476476+`importCargoLock` function. In contrast to `fetchCargoVendor`, this
486477function does not require a hash (unless git dependencies are used)
487478and fetches every dependency as a separate fixed-output derivation.
488479`importCargoLock` can be used as follows:
···521512`rustPlatform` provides the following hooks to automate Cargo builds:
522513523514* `cargoSetupHook`: configure Cargo to use dependencies vendored
524524- through `fetchCargoTarball`. This hook uses the `cargoDeps`
525525- environment variable to find the vendored dependencies. If a project
526526- already vendors its dependencies, the variable `cargoVendorDir` can
527527- be used instead. When the `Cargo.toml`/`Cargo.lock` files are not in
528528- `sourceRoot`, then the optional `cargoRoot` is used to specify the
529529- Cargo root directory relative to `sourceRoot`.
515515+ through `fetchCargoVendor` or `importCargoLock`. This hook uses the
516516+ `cargoDeps` environment variable to find the vendored
517517+ dependencies. If a project already vendors its dependencies, the
518518+ variable `cargoVendorDir` can be used instead. When the
519519+ `Cargo.toml`/`Cargo.lock` files are not in `sourceRoot`, then the
520520+ optional `cargoRoot` is used to specify the Cargo root directory
521521+ relative to `sourceRoot`.
530522* `cargoBuildHook`: use Cargo to build a crate. If the crate to be
531523 built is a crate in e.g. a Cargo workspace, the relative path to the
532524 crate to build can be set through the optional `buildAndTestSubdir`
···557549#### Python package using `setuptools-rust` {#python-package-using-setuptools-rust}
558550559551For Python packages using `setuptools-rust`, you can use
560560-`fetchCargoTarball` and `cargoSetupHook` to retrieve and set up Cargo
552552+`fetchCargoVendor` and `cargoSetupHook` to retrieve and set up Cargo
561553dependencies. The build itself is then performed by
562554`buildPythonPackage`.
563555···586578 hash = "sha256-rQ2hRV52naEf6PvRsWVCTN7B1oXAQGmnpJw4iIdhamw=";
587579 };
588580589589- cargoDeps = rustPlatform.fetchCargoTarball {
581581+ cargoDeps = rustPlatform.fetchCargoVendor {
590582 inherit pname version src sourceRoot;
591591- hash = "sha256-miW//pnOmww2i6SOGbkrAIdc/JMDT4FJLqdMFojZeoY=";
583583+ hash = "sha256-RO1m8wEd5Ic2M9q+zFHeCJWhCr4Sv3CEWd08mkxsBec=";
592584 };
593585594586 sourceRoot = "${src.name}/bindings/python";
···609601specify the crate's directory relative to `sourceRoot`. In the
610602following example, the crate is in `src/rust`, as specified in the
611603`cargoRoot` attribute. Note that we also need to specify the correct
612612-path for `fetchCargoTarball`.
604604+path for `fetchCargoVendor`.
613605614606```nix
615607···629621 hash = "sha256-xGDilsjLOnls3MfVbGKnj80KCUCczZxlis5PmHzpNcQ=";
630622 };
631623632632- cargoDeps = rustPlatform.fetchCargoTarball {
624624+ cargoDeps = rustPlatform.fetchCargoVendor {
633625 inherit pname version src;
634626 sourceRoot = "${pname}-${version}/${cargoRoot}";
635635- hash = "sha256-PS562W4L1NimqDV2H0jl5vYhL08H9est/pbIxSdYVfo=";
627627+ hash = "sha256-ctUt8maCjnGddKPf+Ii++wKsAXA1h+JM6zKQNXXwJqQ=";
636628 };
637629638630 cargoRoot = "src/rust";
···644636#### Python package using `maturin` {#python-package-using-maturin}
645637646638Python packages that use [Maturin](https://github.com/PyO3/maturin)
647647-can be built with `fetchCargoTarball`, `cargoSetupHook`, and
639639+can be built with `fetchCargoVendor`, `cargoSetupHook`, and
648640`maturinBuildHook`. For example, the following (partial) derivation
649649-builds the `retworkx` Python package. `fetchCargoTarball` and
641641+builds the `retworkx` Python package. `fetchCargoVendor` and
650642`cargoSetupHook` are used to fetch and set up the crate dependencies.
651643`maturinBuildHook` is used to perform the build.
652644···669661 hash = "sha256-11n30ldg3y3y6qxg3hbj837pnbwjkqw3nxq6frds647mmmprrd20=";
670662 };
671663672672- cargoDeps = rustPlatform.fetchCargoTarball {
664664+ cargoDeps = rustPlatform.fetchCargoVendor {
673665 inherit pname version src;
674674- hash = "sha256-heOBK8qi2nuc/Ib+I/vLzZ1fUUD/G/KTw9d7M4Hz5O0=";
666666+ hash = "sha256-QsPCQhNZKYCAogQriQX6pBYQUDAIUsEdRX/63dAqTzg=";
675667 };
676668677669 nativeBuildInputs = with rustPlatform; [ cargoSetupHook maturinBuildHook ];
···682674683675#### Rust package built with `meson` {#rust-package-built-with-meson}
684676685685-Some projects, especially GNOME applications, are built with the Meson Build System instead of calling Cargo directly. Using `rustPlatform.buildRustPackage` may successfully build the main program, but related files will be missing. Instead, you need to set up Cargo dependencies with `fetchCargoTarball` and `cargoSetupHook` and leave the rest to Meson. `rust` and `cargo` are still needed in `nativeBuildInputs` for Meson to use.
677677+Some projects, especially GNOME applications, are built with the Meson Build System instead of calling Cargo directly. Using `rustPlatform.buildRustPackage` may successfully build the main program, but related files will be missing. Instead, you need to set up Cargo dependencies with `fetchCargoVendor` and `cargoSetupHook` and leave the rest to Meson. `rust` and `cargo` are still needed in `nativeBuildInputs` for Meson to use.
686678687679```nix
688680{ lib
···713705 hash = "sha256-PrNPprSS98yN8b8yw2G6hzTSaoE65VbsM3q7FVB4mds=";
714706 };
715707716716- cargoDeps = rustPlatform.fetchCargoTarball {
708708+ cargoDeps = rustPlatform.fetchCargoVendor {
717709 inherit pname version src;
718718- hash = "sha256-8fa3fa+sFi5H+49B5sr2vYPkp9C9s6CcE0zv4xB8gww=";
710710+ hash = "sha256-eR1ZGtTZQNhofFUEjI7IX16sMKPJmAl7aIFfPJukecg=";
719711 };
720712721713 nativeBuildInputs = [
···998990999991rustPlatform.buildRustPackage rec {
1000992 pname = "ripgrep";
10011001- version = "12.1.1";
993993+ version = "14.1.1";
10029941003995 src = fetchFromGitHub {
1004996 owner = "BurntSushi";
1005997 repo = "ripgrep";
1006998 rev = version;
10071007- hash = "sha256-+s5RBC3XSgb8omTbUNLywZnP6jSxZBKSS1BmXOjRF8M=";
999999+ hash = "sha256-gyWnahj1A+iXUQlQ1O1H1u7K5euYQOld9qWm99Vjaeg=";
10081000 };
1009100110101010- cargoHash = "sha256-l1vL2ZdtDRxSGvP0X/l3nMw8+6WF67KPutJEzUROjg8=";
10021002+ useFetchCargoVendor = true;
10031003+ cargoHash = "sha256-9atn5qyBDy4P6iUoHFhg+TV6Ur71fiah4oTJbBMeEy4=";
1011100410121005 doCheck = false;
10131006