From f0396574ab32b2d0b02469e7c2b1446623344f09 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Thalheim?= Date: Fri, 5 Jun 2020 08:10:53 +0100 Subject: [PATCH] buildRustPackage: add documentation on how to create cargo.lock patches --- doc/languages-frameworks/rust.section.md | 18 ++++++++++++++++++ pkgs/build-support/rust/default.nix | 1 + 2 files changed, 19 insertions(+) diff --git a/doc/languages-frameworks/rust.section.md b/doc/languages-frameworks/rust.section.md index cec3373cbee..f56bc5285b9 100644 --- a/doc/languages-frameworks/rust.section.md +++ b/doc/languages-frameworks/rust.section.md @@ -75,6 +75,24 @@ pkgs.rustPlatform.buildRustPackage { } ``` +### Building a crate with an absent or out-of-date Cargo.lock file + +`buildRustPackage` needs a `Cargo.lock` file to get all dependencies in the +source code in a reproducible way. If it is missing or out-of-date one can use +the `cargoPatches` attribute to update or add it. + +``` +{ lib, rustPlatform, fetchFromGitHub }: + +rustPlatform.buildRustPackage rec { + (...) + cargoPatches = [ + # a patch file to add/update Cargo.lock in the source code + ./add-Cargo.lock.patch + ]; +} +``` + ## Compiling Rust crates using Nix instead of Cargo ### Simple operation diff --git a/pkgs/build-support/rust/default.nix b/pkgs/build-support/rust/default.nix index a6b47930c27..795ce841ffb 100644 --- a/pkgs/build-support/rust/default.nix +++ b/pkgs/build-support/rust/default.nix @@ -130,6 +130,7 @@ stdenv.mkDerivation (args // { # give a friendlier error msg. if ! [ -e $srcLockfile ]; then echo "ERROR: Missing Cargo.lock from src. Expected to find it at: $srcLockfile" + echo "Hint: You can use the cargoPatches attribute to add a Cargo.lock manually to the build." exit 1 fi