doc: recommend fetchCargoVendor

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.

+36 -42
+1
doc/hooks/tauri.section.md
··· 26 26 rustPlatform.buildRustPackage rec { 27 27 # . . . 28 28 29 + useFetchCargoVendor = true; 29 30 cargoHash = "..."; 30 31 31 32 # Assuming our app's frontend uses `npm` as a package manager
+35 -42
doc/languages-frameworks/rust.section.md
··· 26 26 27 27 rustPlatform.buildRustPackage rec { 28 28 pname = "ripgrep"; 29 - version = "12.1.1"; 29 + version = "14.1.1"; 30 30 31 31 src = fetchFromGitHub { 32 32 owner = "BurntSushi"; 33 33 repo = pname; 34 34 rev = version; 35 - hash = "sha256-+s5RBC3XSgb8omTbUNLywZnP6jSxZBKSS1BmXOjRF8M="; 35 + hash = "sha256-gyWnahj1A+iXUQlQ1O1H1u7K5euYQOld9qWm99Vjaeg="; 36 36 }; 37 37 38 - cargoHash = "sha256-jtBw4ahSl88L0iuCXxQgZVm1EcboWRJMNtjxLVTtzts="; 38 + useFetchCargoVendor = true; 39 + cargoHash = "sha256-9atn5qyBDy4P6iUoHFhg+TV6Ur71fiah4oTJbBMeEy4="; 39 40 40 41 meta = { 41 42 description = "Fast line-oriented regex search tool, similar to ag and ack"; ··· 63 64 } 64 65 ``` 65 66 66 - 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 67 + If this method does not work, you can resort to copying the `Cargo.lock` file into nixpkgs 78 68 and importing it as described in the [next section](#importing-a-cargo.lock-file). 79 69 80 70 Both types of hashes are permitted when contributing to nixpkgs. The ··· 119 109 hash = "sha256-aDQA4A5mScX9or3Lyiv/5GyAehidnpKKE0grhbP1Ctc="; 120 110 }; 121 111 122 - cargoHash = "sha256-tbrTbutUs5aPSV+yE0IBUZAAytgmZV7Eqxia7g+9zRs="; 112 + useFetchCargoVendor = true; 113 + cargoHash = "sha256-iDYh52rj1M5Uupvbx2WeDd/jvQZ+2A50V5rp5e2t7q4="; 123 114 cargoDepsName = pname; 124 115 125 116 # ... ··· 443 434 444 435 Since network access is not allowed in sandboxed builds, Rust crate 445 436 dependencies need to be retrieved using a fetcher. `rustPlatform` 446 - provides the `fetchCargoTarball` fetcher, which vendors all 437 + provides the `fetchCargoVendor` fetcher, which vendors all 447 438 dependencies of a crate. For example, given a source path `src` 448 - containing `Cargo.toml` and `Cargo.lock`, `fetchCargoTarball` 439 + containing `Cargo.toml` and `Cargo.lock`, `fetchCargoVendor` 449 440 can be used as follows: 450 441 451 442 ```nix 452 443 { 453 - cargoDeps = rustPlatform.fetchCargoTarball { 444 + cargoDeps = rustPlatform.fetchCargoVendor { 454 445 inherit src; 455 446 hash = "sha256-BoHIN/519Top1NUBjpB/oEMqi86Omt3zTQcXFWqrek0="; 456 447 }; ··· 482 473 ``` 483 474 484 475 If a `Cargo.lock` file is available, you can alternatively use the 485 - `importCargoLock` function. In contrast to `fetchCargoTarball`, this 476 + `importCargoLock` function. In contrast to `fetchCargoVendor`, this 486 477 function does not require a hash (unless git dependencies are used) 487 478 and fetches every dependency as a separate fixed-output derivation. 488 479 `importCargoLock` can be used as follows: ··· 521 512 `rustPlatform` provides the following hooks to automate Cargo builds: 522 513 523 514 * `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`. 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`. 530 522 * `cargoBuildHook`: use Cargo to build a crate. If the crate to be 531 523 built is a crate in e.g. a Cargo workspace, the relative path to the 532 524 crate to build can be set through the optional `buildAndTestSubdir` ··· 557 549 #### Python package using `setuptools-rust` {#python-package-using-setuptools-rust} 558 550 559 551 For Python packages using `setuptools-rust`, you can use 560 - `fetchCargoTarball` and `cargoSetupHook` to retrieve and set up Cargo 552 + `fetchCargoVendor` and `cargoSetupHook` to retrieve and set up Cargo 561 553 dependencies. The build itself is then performed by 562 554 `buildPythonPackage`. 563 555 ··· 586 578 hash = "sha256-rQ2hRV52naEf6PvRsWVCTN7B1oXAQGmnpJw4iIdhamw="; 587 579 }; 588 580 589 - cargoDeps = rustPlatform.fetchCargoTarball { 581 + cargoDeps = rustPlatform.fetchCargoVendor { 590 582 inherit pname version src sourceRoot; 591 - hash = "sha256-miW//pnOmww2i6SOGbkrAIdc/JMDT4FJLqdMFojZeoY="; 583 + hash = "sha256-RO1m8wEd5Ic2M9q+zFHeCJWhCr4Sv3CEWd08mkxsBec="; 592 584 }; 593 585 594 586 sourceRoot = "${src.name}/bindings/python"; ··· 609 601 specify the crate's directory relative to `sourceRoot`. In the 610 602 following example, the crate is in `src/rust`, as specified in the 611 603 `cargoRoot` attribute. Note that we also need to specify the correct 612 - path for `fetchCargoTarball`. 604 + path for `fetchCargoVendor`. 613 605 614 606 ```nix 615 607 ··· 629 621 hash = "sha256-xGDilsjLOnls3MfVbGKnj80KCUCczZxlis5PmHzpNcQ="; 630 622 }; 631 623 632 - cargoDeps = rustPlatform.fetchCargoTarball { 624 + cargoDeps = rustPlatform.fetchCargoVendor { 633 625 inherit pname version src; 634 626 sourceRoot = "${pname}-${version}/${cargoRoot}"; 635 - hash = "sha256-PS562W4L1NimqDV2H0jl5vYhL08H9est/pbIxSdYVfo="; 627 + hash = "sha256-ctUt8maCjnGddKPf+Ii++wKsAXA1h+JM6zKQNXXwJqQ="; 636 628 }; 637 629 638 630 cargoRoot = "src/rust"; ··· 644 636 #### Python package using `maturin` {#python-package-using-maturin} 645 637 646 638 Python packages that use [Maturin](https://github.com/PyO3/maturin) 647 - can be built with `fetchCargoTarball`, `cargoSetupHook`, and 639 + can be built with `fetchCargoVendor`, `cargoSetupHook`, and 648 640 `maturinBuildHook`. For example, the following (partial) derivation 649 - builds the `retworkx` Python package. `fetchCargoTarball` and 641 + builds the `retworkx` Python package. `fetchCargoVendor` and 650 642 `cargoSetupHook` are used to fetch and set up the crate dependencies. 651 643 `maturinBuildHook` is used to perform the build. 652 644 ··· 669 661 hash = "sha256-11n30ldg3y3y6qxg3hbj837pnbwjkqw3nxq6frds647mmmprrd20="; 670 662 }; 671 663 672 - cargoDeps = rustPlatform.fetchCargoTarball { 664 + cargoDeps = rustPlatform.fetchCargoVendor { 673 665 inherit pname version src; 674 - hash = "sha256-heOBK8qi2nuc/Ib+I/vLzZ1fUUD/G/KTw9d7M4Hz5O0="; 666 + hash = "sha256-QsPCQhNZKYCAogQriQX6pBYQUDAIUsEdRX/63dAqTzg="; 675 667 }; 676 668 677 669 nativeBuildInputs = with rustPlatform; [ cargoSetupHook maturinBuildHook ]; ··· 682 674 683 675 #### Rust package built with `meson` {#rust-package-built-with-meson} 684 676 685 - 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. 677 + 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. 686 678 687 679 ```nix 688 680 { lib ··· 713 705 hash = "sha256-PrNPprSS98yN8b8yw2G6hzTSaoE65VbsM3q7FVB4mds="; 714 706 }; 715 707 716 - cargoDeps = rustPlatform.fetchCargoTarball { 708 + cargoDeps = rustPlatform.fetchCargoVendor { 717 709 inherit pname version src; 718 - hash = "sha256-8fa3fa+sFi5H+49B5sr2vYPkp9C9s6CcE0zv4xB8gww="; 710 + hash = "sha256-eR1ZGtTZQNhofFUEjI7IX16sMKPJmAl7aIFfPJukecg="; 719 711 }; 720 712 721 713 nativeBuildInputs = [ ··· 998 990 999 991 rustPlatform.buildRustPackage rec { 1000 992 pname = "ripgrep"; 1001 - version = "12.1.1"; 993 + version = "14.1.1"; 1002 994 1003 995 src = fetchFromGitHub { 1004 996 owner = "BurntSushi"; 1005 997 repo = "ripgrep"; 1006 998 rev = version; 1007 - hash = "sha256-+s5RBC3XSgb8omTbUNLywZnP6jSxZBKSS1BmXOjRF8M="; 999 + hash = "sha256-gyWnahj1A+iXUQlQ1O1H1u7K5euYQOld9qWm99Vjaeg="; 1008 1000 }; 1009 1001 1010 - cargoHash = "sha256-l1vL2ZdtDRxSGvP0X/l3nMw8+6WF67KPutJEzUROjg8="; 1002 + useFetchCargoVendor = true; 1003 + cargoHash = "sha256-9atn5qyBDy4P6iUoHFhg+TV6Ur71fiah4oTJbBMeEy4="; 1011 1004 1012 1005 doCheck = false; 1013 1006