summary refs log tree commit diff
path: root/pkgs/build-support/rust
diff options
context:
space:
mode:
authorJustin Humm <justin.humm@posteo.de>2018-08-20 20:30:02 +0200
committerSymphorien Gibol <symphorien+git@xlumurb.eu>2018-09-11 23:44:14 +0200
commitb66ef28841319bf1a281bde4e97c82458839a483 (patch)
tree629b15bb6db4f470acbfe88b98894dbaaadd7259 /pkgs/build-support/rust
parentcb8fb7e71ba7b99321156027934cc96fdf0f0ad7 (diff)
downloadnixlib-b66ef28841319bf1a281bde4e97c82458839a483.tar
nixlib-b66ef28841319bf1a281bde4e97c82458839a483.tar.gz
nixlib-b66ef28841319bf1a281bde4e97c82458839a483.tar.bz2
nixlib-b66ef28841319bf1a281bde4e97c82458839a483.tar.lz
nixlib-b66ef28841319bf1a281bde4e97c82458839a483.tar.xz
nixlib-b66ef28841319bf1a281bde4e97c82458839a483.tar.zst
nixlib-b66ef28841319bf1a281bde4e97c82458839a483.zip
buildRustPackage, fetchcargo: optionally use vendor config from cargo-vendor
By setting useRealVendorConfig explicitly to true, the actual (slightly
modified) config generated by cargo-vendor is used.

This solves a problem, where the static vendor config in
pkgs/build-support/rust/default.nix would not sufficiently replace all
crates Cargo is looking for.

As useRealVendorConfig (and writeVendorConfig in fetchcargo) default to
false, there should be no breakage in existing cargoSha256 hashes.

Nethertheless, imho using this new feature should become standard. A
possible deprecation path could be:

- introduce this patch
- set useRealVendorConfig explicitly to false whereever cargoSha256 is
  set but migration is not wanted yet.
- after some time, let writeVendorConfig default to true
- when useRealVendorConfig is true everywhere cargoSha256 is set and
  enough time is passed, `assert cargoVendorDir == null ->
  useRealVendorConfig;`, remove old behaviour
- after some time, remove all appearences of useRealVendorConfig and the
  parameter itself
Diffstat (limited to 'pkgs/build-support/rust')
-rw-r--r--pkgs/build-support/rust/default.nix28
-rw-r--r--pkgs/build-support/rust/fetchcargo.nix10
2 files changed, 26 insertions, 12 deletions
diff --git a/pkgs/build-support/rust/default.nix b/pkgs/build-support/rust/default.nix
index 820989a76206..a2dc5df4d926 100644
--- a/pkgs/build-support/rust/default.nix
+++ b/pkgs/build-support/rust/default.nix
@@ -17,9 +17,15 @@ in
 , cargoBuildFlags ? []
 
 , cargoVendorDir ? null
+# This tells cargo-vendor to include a Cargo config file in the fixed-output
+# derivation. This is desirable in every case, so please set it to true.
+# Eventually this will default to true and even later this option and the old
+# behaviour will be removed.
+, useRealVendorConfig ? false
 , ... } @ args:
 
 assert cargoVendorDir == null -> cargoSha256 != "unset";
+assert cargoVendorDir != null -> !useRealVendorConfig;
 
 let
   cargoDeps = if cargoVendorDir == null
@@ -27,6 +33,7 @@ let
         inherit name src srcs sourceRoot cargoUpdateHook;
         patches = cargoPatches;
         sha256 = cargoSha256;
+        writeVendorConfig = useRealVendorConfig;
       }
     else null;
 
@@ -61,14 +68,19 @@ in stdenv.mkDerivation (args // {
     ${setupVendorDir}
 
     mkdir .cargo
-    cat >.cargo/config <<-EOF
-      [source.crates-io]
-      registry = 'https://github.com/rust-lang/crates.io-index'
-      replace-with = 'vendored-sources'
-
-      [source.vendored-sources]
-      directory = '$(pwd)/$cargoDepsCopy'
-    EOF
+  '' + (if useRealVendorConfig then ''
+      sed "s|directory = \".*\"|directory = \"$(pwd)/$cargoDepsCopy\"|g" \
+        "$(pwd)/$cargoDepsCopy/.cargo/config" > .cargo/config
+    '' else ''
+      cat >.cargo/config <<-EOF
+        [source.crates-io]
+        registry = 'https://github.com/rust-lang/crates.io-index'
+        replace-with = 'vendored-sources'
+
+        [source.vendored-sources]
+        directory = '$(pwd)/$cargoDepsCopy'
+      EOF
+    '') + ''
 
     unset cargoDepsCopy
 
diff --git a/pkgs/build-support/rust/fetchcargo.nix b/pkgs/build-support/rust/fetchcargo.nix
index 2670ed528640..2d8a36a30ace 100644
--- a/pkgs/build-support/rust/fetchcargo.nix
+++ b/pkgs/build-support/rust/fetchcargo.nix
@@ -1,5 +1,5 @@
 { stdenv, cacert, git, rust, cargo-vendor }:
-{ name ? "cargo-deps", src, srcs, patches, sourceRoot, sha256, cargoUpdateHook ? "" }:
+{ name ? "cargo-deps", src, srcs, patches, sourceRoot, sha256, cargoUpdateHook ? "", writeVendorConfig ? false }:
 stdenv.mkDerivation {
   name = "${name}-vendor";
   nativeBuildInputs = [ cacert cargo-vendor git rust.cargo ];
@@ -23,9 +23,11 @@ stdenv.mkDerivation {
 
     ${cargoUpdateHook}
 
-    cargo vendor
-
-    cp -ar vendor $out
+    mkdir -p $out
+    cargo vendor $out > config
+  '' + stdenv.lib.optionalString writeVendorConfig ''
+    mkdir $out/.cargo
+    sed "s|directory = \".*\"|directory = \"./vendor\"|g" config > $out/.cargo/config
   '';
 
   outputHashAlgo = "sha256";