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