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.
···2627rustPlatform.buildRustPackage rec {
28 pname = "ripgrep";
29- version = "12.1.1";
3031 src = fetchFromGitHub {
32 owner = "BurntSushi";
33 repo = pname;
34 rev = version;
35- hash = "sha256-+s5RBC3XSgb8omTbUNLywZnP6jSxZBKSS1BmXOjRF8M=";
36 };
3738- cargoHash = "sha256-jtBw4ahSl88L0iuCXxQgZVm1EcboWRJMNtjxLVTtzts=";
03940 meta = {
41 description = "Fast line-oriented regex search tool, similar to ag and ack";
···63}
64```
6566-Exception: If the application has cargo `git` dependencies, the `cargoHash`
67-approach will not work by default. In this case, you can set `useFetchCargoVendor = true`
68-to use an improved fetcher that supports handling `git` dependencies.
69-70-```nix
71-{
72- useFetchCargoVendor = true;
73- cargoHash = "sha256-RqPVFovDaD2rW31HyETJfQ0qVwFxoGEvqkIgag3H6KU=";
74-}
75-```
76-77-If this method still does not work, you can resort to copying the `Cargo.lock` file into nixpkgs
78and importing it as described in the [next section](#importing-a-cargo.lock-file).
7980Both types of hashes are permitted when contributing to nixpkgs. The
···119 hash = "sha256-aDQA4A5mScX9or3Lyiv/5GyAehidnpKKE0grhbP1Ctc=";
120 };
121122- cargoHash = "sha256-tbrTbutUs5aPSV+yE0IBUZAAytgmZV7Eqxia7g+9zRs=";
0123 cargoDepsName = pname;
124125 # ...
···443444Since network access is not allowed in sandboxed builds, Rust crate
445dependencies need to be retrieved using a fetcher. `rustPlatform`
446-provides the `fetchCargoTarball` fetcher, which vendors all
447dependencies of a crate. For example, given a source path `src`
448-containing `Cargo.toml` and `Cargo.lock`, `fetchCargoTarball`
449can be used as follows:
450451```nix
452{
453- cargoDeps = rustPlatform.fetchCargoTarball {
454 inherit src;
455 hash = "sha256-BoHIN/519Top1NUBjpB/oEMqi86Omt3zTQcXFWqrek0=";
456 };
···482```
483484If a `Cargo.lock` file is available, you can alternatively use the
485-`importCargoLock` function. In contrast to `fetchCargoTarball`, this
486function does not require a hash (unless git dependencies are used)
487and fetches every dependency as a separate fixed-output derivation.
488`importCargoLock` can be used as follows:
···521`rustPlatform` provides the following hooks to automate Cargo builds:
522523* `cargoSetupHook`: configure Cargo to use dependencies vendored
524- through `fetchCargoTarball`. This hook uses the `cargoDeps`
525- environment variable to find the vendored dependencies. If a project
526- already vendors its dependencies, the variable `cargoVendorDir` can
527- be used instead. When the `Cargo.toml`/`Cargo.lock` files are not in
528- `sourceRoot`, then the optional `cargoRoot` is used to specify the
529- Cargo root directory relative to `sourceRoot`.
0530* `cargoBuildHook`: use Cargo to build a crate. If the crate to be
531 built is a crate in e.g. a Cargo workspace, the relative path to the
532 crate to build can be set through the optional `buildAndTestSubdir`
···557#### Python package using `setuptools-rust` {#python-package-using-setuptools-rust}
558559For Python packages using `setuptools-rust`, you can use
560-`fetchCargoTarball` and `cargoSetupHook` to retrieve and set up Cargo
561dependencies. The build itself is then performed by
562`buildPythonPackage`.
563···586 hash = "sha256-rQ2hRV52naEf6PvRsWVCTN7B1oXAQGmnpJw4iIdhamw=";
587 };
588589- cargoDeps = rustPlatform.fetchCargoTarball {
590 inherit pname version src sourceRoot;
591- hash = "sha256-miW//pnOmww2i6SOGbkrAIdc/JMDT4FJLqdMFojZeoY=";
592 };
593594 sourceRoot = "${src.name}/bindings/python";
···609specify the crate's directory relative to `sourceRoot`. In the
610following example, the crate is in `src/rust`, as specified in the
611`cargoRoot` attribute. Note that we also need to specify the correct
612-path for `fetchCargoTarball`.
613614```nix
615···629 hash = "sha256-xGDilsjLOnls3MfVbGKnj80KCUCczZxlis5PmHzpNcQ=";
630 };
631632- cargoDeps = rustPlatform.fetchCargoTarball {
633 inherit pname version src;
634 sourceRoot = "${pname}-${version}/${cargoRoot}";
635- hash = "sha256-PS562W4L1NimqDV2H0jl5vYhL08H9est/pbIxSdYVfo=";
636 };
637638 cargoRoot = "src/rust";
···644#### Python package using `maturin` {#python-package-using-maturin}
645646Python packages that use [Maturin](https://github.com/PyO3/maturin)
647-can be built with `fetchCargoTarball`, `cargoSetupHook`, and
648`maturinBuildHook`. For example, the following (partial) derivation
649-builds the `retworkx` Python package. `fetchCargoTarball` and
650`cargoSetupHook` are used to fetch and set up the crate dependencies.
651`maturinBuildHook` is used to perform the build.
652···669 hash = "sha256-11n30ldg3y3y6qxg3hbj837pnbwjkqw3nxq6frds647mmmprrd20=";
670 };
671672- cargoDeps = rustPlatform.fetchCargoTarball {
673 inherit pname version src;
674- hash = "sha256-heOBK8qi2nuc/Ib+I/vLzZ1fUUD/G/KTw9d7M4Hz5O0=";
675 };
676677 nativeBuildInputs = with rustPlatform; [ cargoSetupHook maturinBuildHook ];
···682683#### Rust package built with `meson` {#rust-package-built-with-meson}
684685-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.
686687```nix
688{ lib
···713 hash = "sha256-PrNPprSS98yN8b8yw2G6hzTSaoE65VbsM3q7FVB4mds=";
714 };
715716- cargoDeps = rustPlatform.fetchCargoTarball {
717 inherit pname version src;
718- hash = "sha256-8fa3fa+sFi5H+49B5sr2vYPkp9C9s6CcE0zv4xB8gww=";
719 };
720721 nativeBuildInputs = [
···998999rustPlatform.buildRustPackage rec {
1000 pname = "ripgrep";
1001- version = "12.1.1";
10021003 src = fetchFromGitHub {
1004 owner = "BurntSushi";
1005 repo = "ripgrep";
1006 rev = version;
1007- hash = "sha256-+s5RBC3XSgb8omTbUNLywZnP6jSxZBKSS1BmXOjRF8M=";
1008 };
10091010- cargoHash = "sha256-l1vL2ZdtDRxSGvP0X/l3nMw8+6WF67KPutJEzUROjg8=";
010111012 doCheck = false;
1013
···2627rustPlatform.buildRustPackage rec {
28 pname = "ripgrep";
29+ version = "14.1.1";
3031 src = fetchFromGitHub {
32 owner = "BurntSushi";
33 repo = pname;
34 rev = version;
35+ hash = "sha256-gyWnahj1A+iXUQlQ1O1H1u7K5euYQOld9qWm99Vjaeg=";
36 };
3738+ useFetchCargoVendor = true;
39+ cargoHash = "sha256-9atn5qyBDy4P6iUoHFhg+TV6Ur71fiah4oTJbBMeEy4=";
4041 meta = {
42 description = "Fast line-oriented regex search tool, similar to ag and ack";
···64}
65```
6667+If this method does not work, you can resort to copying the `Cargo.lock` file into nixpkgs
0000000000068and importing it as described in the [next section](#importing-a-cargo.lock-file).
6970Both types of hashes are permitted when contributing to nixpkgs. The
···109 hash = "sha256-aDQA4A5mScX9or3Lyiv/5GyAehidnpKKE0grhbP1Ctc=";
110 };
111112+ useFetchCargoVendor = true;
113+ cargoHash = "sha256-iDYh52rj1M5Uupvbx2WeDd/jvQZ+2A50V5rp5e2t7q4=";
114 cargoDepsName = pname;
115116 # ...
···434435Since network access is not allowed in sandboxed builds, Rust crate
436dependencies need to be retrieved using a fetcher. `rustPlatform`
437+provides the `fetchCargoVendor` fetcher, which vendors all
438dependencies of a crate. For example, given a source path `src`
439+containing `Cargo.toml` and `Cargo.lock`, `fetchCargoVendor`
440can be used as follows:
441442```nix
443{
444+ cargoDeps = rustPlatform.fetchCargoVendor {
445 inherit src;
446 hash = "sha256-BoHIN/519Top1NUBjpB/oEMqi86Omt3zTQcXFWqrek0=";
447 };
···473```
474475If a `Cargo.lock` file is available, you can alternatively use the
476+`importCargoLock` function. In contrast to `fetchCargoVendor`, this
477function does not require a hash (unless git dependencies are used)
478and fetches every dependency as a separate fixed-output derivation.
479`importCargoLock` can be used as follows:
···512`rustPlatform` provides the following hooks to automate Cargo builds:
513514* `cargoSetupHook`: configure Cargo to use dependencies vendored
515+ through `fetchCargoVendor` or `importCargoLock`. This hook uses the
516+ `cargoDeps` environment variable to find the vendored
517+ dependencies. If a project already vendors its dependencies, the
518+ variable `cargoVendorDir` can be used instead. When the
519+ `Cargo.toml`/`Cargo.lock` files are not in `sourceRoot`, then the
520+ optional `cargoRoot` is used to specify the Cargo root directory
521+ relative to `sourceRoot`.
522* `cargoBuildHook`: use Cargo to build a crate. If the crate to be
523 built is a crate in e.g. a Cargo workspace, the relative path to the
524 crate to build can be set through the optional `buildAndTestSubdir`
···549#### Python package using `setuptools-rust` {#python-package-using-setuptools-rust}
550551For Python packages using `setuptools-rust`, you can use
552+`fetchCargoVendor` and `cargoSetupHook` to retrieve and set up Cargo
553dependencies. The build itself is then performed by
554`buildPythonPackage`.
555···578 hash = "sha256-rQ2hRV52naEf6PvRsWVCTN7B1oXAQGmnpJw4iIdhamw=";
579 };
580581+ cargoDeps = rustPlatform.fetchCargoVendor {
582 inherit pname version src sourceRoot;
583+ hash = "sha256-RO1m8wEd5Ic2M9q+zFHeCJWhCr4Sv3CEWd08mkxsBec=";
584 };
585586 sourceRoot = "${src.name}/bindings/python";
···601specify the crate's directory relative to `sourceRoot`. In the
602following example, the crate is in `src/rust`, as specified in the
603`cargoRoot` attribute. Note that we also need to specify the correct
604+path for `fetchCargoVendor`.
605606```nix
607···621 hash = "sha256-xGDilsjLOnls3MfVbGKnj80KCUCczZxlis5PmHzpNcQ=";
622 };
623624+ cargoDeps = rustPlatform.fetchCargoVendor {
625 inherit pname version src;
626 sourceRoot = "${pname}-${version}/${cargoRoot}";
627+ hash = "sha256-ctUt8maCjnGddKPf+Ii++wKsAXA1h+JM6zKQNXXwJqQ=";
628 };
629630 cargoRoot = "src/rust";
···636#### Python package using `maturin` {#python-package-using-maturin}
637638Python packages that use [Maturin](https://github.com/PyO3/maturin)
639+can be built with `fetchCargoVendor`, `cargoSetupHook`, and
640`maturinBuildHook`. For example, the following (partial) derivation
641+builds the `retworkx` Python package. `fetchCargoVendor` and
642`cargoSetupHook` are used to fetch and set up the crate dependencies.
643`maturinBuildHook` is used to perform the build.
644···661 hash = "sha256-11n30ldg3y3y6qxg3hbj837pnbwjkqw3nxq6frds647mmmprrd20=";
662 };
663664+ cargoDeps = rustPlatform.fetchCargoVendor {
665 inherit pname version src;
666+ hash = "sha256-QsPCQhNZKYCAogQriQX6pBYQUDAIUsEdRX/63dAqTzg=";
667 };
668669 nativeBuildInputs = with rustPlatform; [ cargoSetupHook maturinBuildHook ];
···674675#### Rust package built with `meson` {#rust-package-built-with-meson}
676677+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.
678679```nix
680{ lib
···705 hash = "sha256-PrNPprSS98yN8b8yw2G6hzTSaoE65VbsM3q7FVB4mds=";
706 };
707708+ cargoDeps = rustPlatform.fetchCargoVendor {
709 inherit pname version src;
710+ hash = "sha256-eR1ZGtTZQNhofFUEjI7IX16sMKPJmAl7aIFfPJukecg=";
711 };
712713 nativeBuildInputs = [
···990991rustPlatform.buildRustPackage rec {
992 pname = "ripgrep";
993+ version = "14.1.1";
994995 src = fetchFromGitHub {
996 owner = "BurntSushi";
997 repo = "ripgrep";
998 rev = version;
999+ hash = "sha256-gyWnahj1A+iXUQlQ1O1H1u7K5euYQOld9qWm99Vjaeg=";
1000 };
10011002+ useFetchCargoVendor = true;
1003+ cargoHash = "sha256-9atn5qyBDy4P6iUoHFhg+TV6Ur71fiah4oTJbBMeEy4=";
10041005 doCheck = false;
1006