From f20b229aa19e92914aba7fe990201be730c07a10 Mon Sep 17 00:00:00 2001 From: Symphorien Gibol Date: Sun, 9 Sep 2018 15:54:00 +0200 Subject: [PATCH] fectchcargo: don't break old sha256 --- doc/languages-frameworks/rust.section.md | 11 +------- nixos/doc/manual/release-notes/rl-1809.xml | 21 --------------- pkgs/build-support/rust/default.nix | 26 +++++-------------- .../rust/fetchcargo-default-config.toml | 7 +++++ pkgs/build-support/rust/fetchcargo.nix | 17 +++++++----- 5 files changed, 25 insertions(+), 57 deletions(-) create mode 100755 pkgs/build-support/rust/fetchcargo-default-config.toml diff --git a/doc/languages-frameworks/rust.section.md b/doc/languages-frameworks/rust.section.md index 737759fd8bd8..6588281878a0 100644 --- a/doc/languages-frameworks/rust.section.md +++ b/doc/languages-frameworks/rust.section.md @@ -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). diff --git a/nixos/doc/manual/release-notes/rl-1809.xml b/nixos/doc/manual/release-notes/rl-1809.xml index dd04996925bb..01421fc5dda7 100644 --- a/nixos/doc/manual/release-notes/rl-1809.xml +++ b/nixos/doc/manual/release-notes/rl-1809.xml @@ -551,27 +551,6 @@ 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 864e42c47619..1d5de052f893 100644 --- a/pkgs/build-support/rust/default.nix +++ b/pkgs/build-support/rust/default.nix @@ -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 \ - --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 - '') + '' + 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" unset cargoDepsCopy diff --git a/pkgs/build-support/rust/fetchcargo-default-config.toml b/pkgs/build-support/rust/fetchcargo-default-config.toml new file mode 100755 index 000000000000..dd8ebbc32d31 --- /dev/null +++ b/pkgs/build-support/rust/fetchcargo-default-config.toml @@ -0,0 +1,7 @@ +[source."crates-io"] +"replace-with" = "vendored-sources" + +[source."vendored-sources"] +"directory" = "@vendor@" + + diff --git a/pkgs/build-support/rust/fetchcargo.nix b/pkgs/build-support/rust/fetchcargo.nix index f04988a7dc13..1a40a362d9b5 100644 --- a/pkgs/build-support/rust/fetchcargo.nix +++ b/pkgs/build-support/rust/fetchcargo.nix @@ -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";