about summary refs log tree commit diff
path: root/nixpkgs/pkgs/build-support/rust/fetchcargo.nix
diff options
context:
space:
mode:
Diffstat (limited to 'nixpkgs/pkgs/build-support/rust/fetchcargo.nix')
-rw-r--r--nixpkgs/pkgs/build-support/rust/fetchcargo.nix26
1 files changed, 22 insertions, 4 deletions
diff --git a/nixpkgs/pkgs/build-support/rust/fetchcargo.nix b/nixpkgs/pkgs/build-support/rust/fetchcargo.nix
index bc80db0947b0..7a0ba38dce71 100644
--- a/nixpkgs/pkgs/build-support/rust/fetchcargo.nix
+++ b/nixpkgs/pkgs/build-support/rust/fetchcargo.nix
@@ -17,11 +17,20 @@ let cargo-vendor-normalise = stdenv.mkDerivation {
   preferLocalBuild = true;
 };
 in
-{ name ? "cargo-deps", src, srcs, patches, sourceRoot, sha256, cargoUpdateHook ? "" }:
-stdenv.mkDerivation {
+{ name ? "cargo-deps"
+, src ? null
+, srcs ? []
+, patches ? []
+, sourceRoot
+, sha256
+, cargoUpdateHook ? ""
+, # whenever to also include the Cargo.lock in the output
+  copyLockfile ? false
+, ...
+} @ args:
+stdenv.mkDerivation ({
   name = "${name}-vendor";
   nativeBuildInputs = [ cacert git cargo-vendor-normalise cargo ];
-  inherit src srcs patches sourceRoot;
 
   phases = "unpackPhase patchPhase installPhase";
 
@@ -37,6 +46,9 @@ stdenv.mkDerivation {
         exit 1
     fi
 
+    # Keep the original around for copyLockfile
+    cp Cargo.lock Cargo.lock.orig
+
     export CARGO_HOME=$(mktemp -d cargo-home.XXX)
     CARGO_CONFIG=$(mktemp cargo-config.XXXX)
 
@@ -52,6 +64,10 @@ stdenv.mkDerivation {
     if ! cmp $CARGO_CONFIG ${./fetchcargo-default-config.toml} > /dev/null; then
       install -D $CARGO_CONFIG $out/.cargo/config;
     fi;
+
+  '' + stdenv.lib.optionalString copyLockfile ''
+    # add the Cargo.lock to allow hash invalidation
+    cp Cargo.lock.orig $out/Cargo.lock
   '';
 
   outputHashAlgo = "sha256";
@@ -60,4 +76,6 @@ stdenv.mkDerivation {
 
   impureEnvVars = stdenv.lib.fetchers.proxyImpureEnvVars;
   preferLocalBuild = true;
-}
+} // (builtins.removeAttrs args [
+  "name" "sha256" "cargoUpdateHook" "copyLockfile"
+]))