diff --git a/doc/languages-frameworks/rust.section.md b/doc/languages-frameworks/rust.section.md
index 6588281878a..737759fd8bd 100644
--- a/doc/languages-frameworks/rust.section.md
+++ b/doc/languages-frameworks/rust.section.md
@@ -42,7 +42,8 @@ rustPlatform.buildRustPackage rec {
sha256 = "0y5d1n6hkw85jb3rblcxqas2fp82h3nghssa4xqrhqnz25l799pj";
};
- cargoSha256 = "0q68qyl2h6i0qsz82z840myxlnjay8p1w5z7hfyr8fqp7wgwa9cx";
+ cargoSha256 = "194lzn9xjkc041lmqnm676ydgbhn45xx9jhrhz6lzlg99yr6b880";
+ useRealVendorConfig = true;
meta = with stdenv.lib; {
description = "A fast line-oriented regex search tool, similar to ag and ack";
@@ -64,6 +65,14 @@ When the `Cargo.lock`, provided by upstream, is not in sync with the
added in `cargoPatches` will also be prepended to the patches in `patches` at
build-time.
+The `useRealVendorConfig` parameter tells cargo-vendor to include a Cargo
+configuration file in the fetched dependencies. This will fix problems with
+projects, where Crates are downloaded from non-crates.io sources. Please note,
+that currently this parameter defaults to `false` only due to compatibility
+reasons, as setting this to `true` requires a change in `cargoSha256`.
+Eventually this distinction will be deprecated, so please always set
+`useRealVendorConfig` to `true` and make sure to recompute the `cargoSha256`.
+
To install crates with nix there is also an experimental project called
[nixcrates](https://github.com/fractalide/nixcrates).
diff --git a/nixos/doc/manual/release-notes/rl-1809.xml b/nixos/doc/manual/release-notes/rl-1809.xml
index 01421fc5dda..dd04996925b 100644
--- a/nixos/doc/manual/release-notes/rl-1809.xml
+++ b/nixos/doc/manual/release-notes/rl-1809.xml
@@ -551,6 +551,27 @@ inherit (pkgs.nixos {
stdenv.buildPlatform, stdenv.hostPlatform, and stdenv.targetPlatform.
+
+
+ The buildRustPackage function got the new
+ argument useRealVendorConfig, currently
+ defaulting to false. Setting it to
+ true necessates the recomputation of the
+ cargoSha256 and fixes a problem with
+ dependencies, that were fetched from a non-crates.io source.
+ Eventually only the true behaviour will be kept,
+ so please set it explicitly to true and
+ recompute your cargoSha256, so that we can
+ migrate to the new behaviour and deprecate the option.
+
+
+ While recomputing cargoSha256, it is important
+ to first invalidate the hash (e.g. by changing a digit), so that
+ Nix actually rebuilds the fixed-output derivation. Otherwise this
+ could lead to hard to detect errors, where a package seemingly
+ builds on your computer, but breaks on others!
+
+
diff --git a/pkgs/build-support/rust/default.nix b/pkgs/build-support/rust/default.nix
index 820989a7620..a2dc5df4d92 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'
+ '' + (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
+ [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 2670ed52864..2d8a36a30ac 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";