fectchcargo: don't break old sha256

This commit is contained in:
Symphorien Gibol 2018-09-09 15:54:00 +02:00
parent ccf72b8537
commit f20b229aa1
5 changed files with 25 additions and 57 deletions

View File

@ -42,8 +42,7 @@ rustPlatform.buildRustPackage rec {
sha256 = "0y5d1n6hkw85jb3rblcxqas2fp82h3nghssa4xqrhqnz25l799pj";
};
cargoSha256 = "194lzn9xjkc041lmqnm676ydgbhn45xx9jhrhz6lzlg99yr6b880";
useRealVendorConfig = true;
cargoSha256 = "0q68qyl2h6i0qsz82z840myxlnjay8p1w5z7hfyr8fqp7wgwa9cx";
meta = with stdenv.lib; {
description = "A fast line-oriented regex search tool, similar to ag and ack";
@ -65,14 +64,6 @@ 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,27 +551,6 @@ 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,15 +17,9 @@ 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
@ -33,7 +27,6 @@ let
inherit name src srcs sourceRoot cargoUpdateHook;
patches = cargoPatches;
sha256 = cargoSha256;
writeVendorConfig = useRealVendorConfig;
}
else null;
@ -68,19 +61,12 @@ in stdenv.mkDerivation (args // {
${setupVendorDir}
mkdir .cargo
'' + (if useRealVendorConfig then ''
substitute "$(pwd)/$cargoDepsCopy/.cargo/config" .cargo/config \
config="$(pwd)/$cargoDepsCopy/.cargo/config";
if [[ ! -e $config ]]; then
config=${./fetchcargo-default-config.toml};
fi;
substitute $config .cargo/config \
--subst-var-by vendor "$(pwd)/$cargoDepsCopy"
'' 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

View File

@ -0,0 +1,7 @@
[source."crates-io"]
"replace-with" = "vendored-sources"
[source."vendored-sources"]
"directory" = "@vendor@"

View File

@ -1,5 +1,4 @@
{ stdenv, cacert, git, rust, cargo-vendor, python3 }:
{ name ? "cargo-deps", src, srcs, patches, sourceRoot, sha256, cargoUpdateHook ? "", writeVendorConfig ? false }:
let cargo-vendor-normalise = stdenv.mkDerivation {
name = "cargo-vendor-normalise";
src = ./cargo-vendor-normalise.py;
@ -9,9 +8,10 @@ let cargo-vendor-normalise = stdenv.mkDerivation {
preferLocalBuild = true;
};
in
{ name ? "cargo-deps", src, srcs, patches, sourceRoot, sha256, cargoUpdateHook ? "" }:
stdenv.mkDerivation {
name = "${name}-vendor";
nativeBuildInputs = [ cacert cargo-vendor git rust.cargo ];
nativeBuildInputs = [ cacert cargo-vendor git cargo-vendor-normalise rust.cargo ];
inherit src srcs patches sourceRoot;
phases = "unpackPhase patchPhase installPhase";
@ -33,10 +33,15 @@ stdenv.mkDerivation {
${cargoUpdateHook}
mkdir -p $out
cargo vendor $out > config
'' + stdenv.lib.optionalString writeVendorConfig ''
mkdir $out/.cargo
< config ${cargo-vendor-normalise}/bin/cargo-vendor-normalise > $out/.cargo/config
cargo vendor $out | cargo-vendor-normalise > config
# fetchcargo used to never keep the config output by cargo vendor
# and instead hardcode the config in ./fetchcargo-default-config.toml.
# This broke on packages needing git dependencies, so now we keep the config.
# But not to break old cargoSha256, if the previous behavior was enough,
# we don't store the config.
if ! cmp config ${./fetchcargo-default-config.toml} > /dev/null; then
install -Dt $out/.cargo config;
fi;
'';
outputHashAlgo = "sha256";