From 66855adbbfa848dcfa99cd707949d442cfa19524 Mon Sep 17 00:00:00 2001 From: TomaSajt <62384384+TomaSajt@users.noreply.github.com> Date: Tue, 12 Nov 2024 18:22:59 +0100 Subject: [PATCH] docs: mention fetchCargoVendor --- doc/languages-frameworks/rust.section.md | 25 ++++++++++++++++--- .../rust/fetch-cargo-tarball/default.nix | 5 ++-- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/doc/languages-frameworks/rust.section.md b/doc/languages-frameworks/rust.section.md index db1fd01bf0f1f..f1f951b9650fd 100644 --- a/doc/languages-frameworks/rust.section.md +++ b/doc/languages-frameworks/rust.section.md @@ -64,10 +64,18 @@ hash using `nix-hash --to-sri --type sha256 ""`. ``` Exception: If the application has cargo `git` dependencies, the `cargoHash` -approach will not work, and you will need to copy the `Cargo.lock` file of the application -to nixpkgs and continue with the next section for specifying the options of the `cargoLock` -section. +approach will not work by default. In this case, you can set `useFetchCargoVendor = true` +to use an improved fetcher that supports handling `git` dependencies. +```nix +{ + useFetchCargoVendor = true; + cargoHash = "sha256-RqPVFovDaD2rW31HyETJfQ0qVwFxoGEvqkIgag3H6KU="; +} +``` + +If this method still does not work, you can resort to copying the `Cargo.lock` file into nixpkgs +and importing it as described in the [next section](#importing-a-cargo.lock-file). Both types of hashes are permitted when contributing to nixpkgs. The Cargo hash is obtained by inserting a fake checksum into the @@ -462,6 +470,17 @@ also be used: the `Cargo.lock`/`Cargo.toml` files need to be patched before vendoring. +In case the lockfile contains cargo `git` dependencies, you can use +`fetchCargoVendor` instead. +```nix +{ + cargoDeps = rustPlatform.fetchCargoVendor { + inherit src; + hash = "sha256-RqPVFovDaD2rW31HyETJfQ0qVwFxoGEvqkIgag3H6KU="; + }; +} +``` + If a `Cargo.lock` file is available, you can alternatively use the `importCargoLock` function. In contrast to `fetchCargoTarball`, this function does not require a hash (unless git dependencies are used) diff --git a/pkgs/build-support/rust/fetch-cargo-tarball/default.nix b/pkgs/build-support/rust/fetch-cargo-tarball/default.nix index 96db232ce2f53..aec39315ccc2a 100644 --- a/pkgs/build-support/rust/fetch-cargo-tarball/default.nix +++ b/pkgs/build-support/rust/fetch-cargo-tarball/default.nix @@ -120,8 +120,9 @@ stdenv.mkDerivation ( echo echo "ERROR: The Cargo.lock contains git dependencies" echo - echo "This is currently not supported in the fixed-output derivation fetcher." - echo "Use cargoLock.lockFile / importCargoLock instead." + echo "This is not supported in the default fixed-output derivation fetcher." + echo "Set \`useFetchCargoVendor = true\` / use fetchCargoVendor" + echo "or use cargoLock.lockFile / importCargoLock instead." echo exit 1