3
0
Fork 0
forked from mirrors/nixpkgs

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
This commit is contained in:
Justin Humm 2018-08-20 20:30:02 +02:00 committed by Symphorien Gibol
parent cb8fb7e71b
commit b66ef28841
4 changed files with 56 additions and 12 deletions

View file

@ -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).

View file

@ -551,6 +551,27 @@ inherit (pkgs.nixos {
<literal>stdenv.buildPlatform</literal>, <literal>stdenv.hostPlatform</literal>, and <literal>stdenv.targetPlatform</literal>.
</para>
</listitem>
<listitem>
<para>
The <literal>buildRustPackage</literal> function got the new
argument <literal>useRealVendorConfig</literal>, currently
defaulting to <literal>false</literal>. Setting it to
<literal>true</literal> necessates the recomputation of the
<literal>cargoSha256</literal> and fixes a problem with
dependencies, that were fetched from a non-crates.io source.
Eventually only the <literal>true</literal> behaviour will be kept,
so please set it explicitly to <literal>true</literal> and
recompute your <literal>cargoSha256</literal>, so that we can
migrate to the new behaviour and deprecate the option.
</para>
<para>
While recomputing <literal>cargoSha256</literal>, 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!
</para>
</listitem>
</itemizedlist>
</section>
</section>

View file

@ -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

View file

@ -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";