nixpkgs mirror (for testing) github.com/NixOS/nixpkgs
nix

fectchcargo: don't break old sha256

+25 -57
+1 -10
doc/languages-frameworks/rust.section.md
··· 42 42 sha256 = "0y5d1n6hkw85jb3rblcxqas2fp82h3nghssa4xqrhqnz25l799pj"; 43 43 }; 44 44 45 - cargoSha256 = "194lzn9xjkc041lmqnm676ydgbhn45xx9jhrhz6lzlg99yr6b880"; 46 - useRealVendorConfig = true; 45 + cargoSha256 = "0q68qyl2h6i0qsz82z840myxlnjay8p1w5z7hfyr8fqp7wgwa9cx"; 47 46 48 47 meta = with stdenv.lib; { 49 48 description = "A fast line-oriented regex search tool, similar to ag and ack"; ··· 63 64 `Cargo.toml`, it is possible to use `cargoPatches` to update it. All patches 64 65 added in `cargoPatches` will also be prepended to the patches in `patches` at 65 66 build-time. 66 - 67 - The `useRealVendorConfig` parameter tells cargo-vendor to include a Cargo 68 - configuration file in the fetched dependencies. This will fix problems with 69 - projects, where Crates are downloaded from non-crates.io sources. Please note, 70 - that currently this parameter defaults to `false` only due to compatibility 71 - reasons, as setting this to `true` requires a change in `cargoSha256`. 72 - Eventually this distinction will be deprecated, so please always set 73 - `useRealVendorConfig` to `true` and make sure to recompute the `cargoSha256`. 74 67 75 68 To install crates with nix there is also an experimental project called 76 69 [nixcrates](https://github.com/fractalide/nixcrates).
-21
nixos/doc/manual/release-notes/rl-1809.xml
··· 551 551 <literal>stdenv.buildPlatform</literal>, <literal>stdenv.hostPlatform</literal>, and <literal>stdenv.targetPlatform</literal>. 552 552 </para> 553 553 </listitem> 554 - <listitem> 555 - <para> 556 - The <literal>buildRustPackage</literal> function got the new 557 - argument <literal>useRealVendorConfig</literal>, currently 558 - defaulting to <literal>false</literal>. Setting it to 559 - <literal>true</literal> necessates the recomputation of the 560 - <literal>cargoSha256</literal> and fixes a problem with 561 - dependencies, that were fetched from a non-crates.io source. 562 - Eventually only the <literal>true</literal> behaviour will be kept, 563 - so please set it explicitly to <literal>true</literal> and 564 - recompute your <literal>cargoSha256</literal>, so that we can 565 - migrate to the new behaviour and deprecate the option. 566 - </para> 567 - <para> 568 - While recomputing <literal>cargoSha256</literal>, it is important 569 - to first invalidate the hash (e.g. by changing a digit), so that 570 - Nix actually rebuilds the fixed-output derivation. Otherwise this 571 - could lead to hard to detect errors, where a package seemingly 572 - builds on your computer, but breaks on others! 573 - </para> 574 - </listitem> 575 554 </itemizedlist> 576 555 </section> 577 556 </section>
+6 -20
pkgs/build-support/rust/default.nix
··· 17 17 , cargoBuildFlags ? [] 18 18 19 19 , cargoVendorDir ? null 20 - # This tells cargo-vendor to include a Cargo config file in the fixed-output 21 - # derivation. This is desirable in every case, so please set it to true. 22 - # Eventually this will default to true and even later this option and the old 23 - # behaviour will be removed. 24 - , useRealVendorConfig ? false 25 20 , ... } @ args: 26 21 27 22 assert cargoVendorDir == null -> cargoSha256 != "unset"; 28 - assert cargoVendorDir != null -> !useRealVendorConfig; 29 23 30 24 let 31 25 cargoDeps = if cargoVendorDir == null ··· 27 33 inherit name src srcs sourceRoot cargoUpdateHook; 28 34 patches = cargoPatches; 29 35 sha256 = cargoSha256; 30 - writeVendorConfig = useRealVendorConfig; 31 36 } 32 37 else null; 33 38 ··· 61 68 ${setupVendorDir} 62 69 63 70 mkdir .cargo 64 - '' + (if useRealVendorConfig then '' 65 - substitute "$(pwd)/$cargoDepsCopy/.cargo/config" .cargo/config \ 66 - --subst-var-by vendor "$(pwd)/$cargoDepsCopy" 67 - '' else '' 68 - cat >.cargo/config <<-EOF 69 - [source.crates-io] 70 - registry = 'https://github.com/rust-lang/crates.io-index' 71 - replace-with = 'vendored-sources' 72 - 73 - [source.vendored-sources] 74 - directory = '$(pwd)/$cargoDepsCopy' 75 - EOF 76 - '') + '' 71 + config="$(pwd)/$cargoDepsCopy/.cargo/config"; 72 + if [[ ! -e $config ]]; then 73 + config=${./fetchcargo-default-config.toml}; 74 + fi; 75 + substitute $config .cargo/config \ 76 + --subst-var-by vendor "$(pwd)/$cargoDepsCopy" 77 77 78 78 unset cargoDepsCopy 79 79
+7
pkgs/build-support/rust/fetchcargo-default-config.toml
··· 1 + [source."crates-io"] 2 + "replace-with" = "vendored-sources" 3 + 4 + [source."vendored-sources"] 5 + "directory" = "@vendor@" 6 + 7 +
+11 -6
pkgs/build-support/rust/fetchcargo.nix
··· 1 1 { stdenv, cacert, git, rust, cargo-vendor, python3 }: 2 - { name ? "cargo-deps", src, srcs, patches, sourceRoot, sha256, cargoUpdateHook ? "", writeVendorConfig ? false }: 3 2 let cargo-vendor-normalise = stdenv.mkDerivation { 4 3 name = "cargo-vendor-normalise"; 5 4 src = ./cargo-vendor-normalise.py; ··· 8 9 preferLocalBuild = true; 9 10 }; 10 11 in 12 + { name ? "cargo-deps", src, srcs, patches, sourceRoot, sha256, cargoUpdateHook ? "" }: 11 13 stdenv.mkDerivation { 12 14 name = "${name}-vendor"; 13 - nativeBuildInputs = [ cacert cargo-vendor git rust.cargo ]; 15 + nativeBuildInputs = [ cacert cargo-vendor git cargo-vendor-normalise rust.cargo ]; 14 16 inherit src srcs patches sourceRoot; 15 17 16 18 phases = "unpackPhase patchPhase installPhase"; ··· 33 33 ${cargoUpdateHook} 34 34 35 35 mkdir -p $out 36 - cargo vendor $out > config 37 - '' + stdenv.lib.optionalString writeVendorConfig '' 38 - mkdir $out/.cargo 39 - < config ${cargo-vendor-normalise}/bin/cargo-vendor-normalise > $out/.cargo/config 36 + cargo vendor $out | cargo-vendor-normalise > config 37 + # fetchcargo used to never keep the config output by cargo vendor 38 + # and instead hardcode the config in ./fetchcargo-default-config.toml. 39 + # This broke on packages needing git dependencies, so now we keep the config. 40 + # But not to break old cargoSha256, if the previous behavior was enough, 41 + # we don't store the config. 42 + if ! cmp config ${./fetchcargo-default-config.toml} > /dev/null; then 43 + install -Dt $out/.cargo config; 44 + fi; 40 45 ''; 41 46 42 47 outputHashAlgo = "sha256";