diff options
Diffstat (limited to 'pkgs/build-support/rust/default.nix')
-rw-r--r-- | pkgs/build-support/rust/default.nix | 89 |
1 files changed, 22 insertions, 67 deletions
diff --git a/pkgs/build-support/rust/default.nix b/pkgs/build-support/rust/default.nix index 36130289fbaa..2b32da11d1ce 100644 --- a/pkgs/build-support/rust/default.nix +++ b/pkgs/build-support/rust/default.nix @@ -1,10 +1,14 @@ -{ stdenv, callPackage, path, cacert, git, rust, rustRegistry }: - +{ fetchurl, stdenv, path, cacert, git, rust }: let - rustRegistry' = rustRegistry; + cargoVendor = import ./cargo-vendor.nix { + inherit fetchurl stdenv; + }; + + fetchcargo = import ./fetchcargo.nix { + inherit stdenv cacert git rust cargoVendor; + }; in -{ name, depsSha256 -, rustRegistry ? rustRegistry' +{ name, cargoSha256 , src ? null , srcs ? null , sourceRoot ? null @@ -18,17 +22,13 @@ in let lib = stdenv.lib; - fetchDeps = import ./fetchcargo.nix { - inherit stdenv cacert git rust rustRegistry; - }; - - cargoDeps = fetchDeps { + cargoDeps = fetchcargo { inherit name src srcs sourceRoot cargoUpdateHook; - sha256 = depsSha256; + sha256 = cargoSha256; }; in stdenv.mkDerivation (args // { - inherit cargoDeps rustRegistry; + inherit cargoDeps; patchRegistryDeps = ./patch-registry-deps; @@ -43,71 +43,24 @@ in stdenv.mkDerivation (args // { postUnpack = '' eval "$cargoDepsHook" - echo "Using cargo deps from $cargoDeps" + mkdir .cargo + cat >.cargo/config <<-EOF + [source.crates-io] + registry = 'https://github.com/rust-lang/crates.io-index' + replace-with = 'vendored-sources' - cp -a "$cargoDeps" deps - chmod +w deps -R - - # It's OK to use /dev/null as the URL because by the time we do this, cargo - # won't attempt to update the registry anymore, so the URL is more or less - # irrelevant - - cat <<EOF > deps/config - [registry] - index = "file:///dev/null" + [source.vendored-sources] + directory = '$cargoDeps' EOF - export CARGO_HOME="$(realpath deps)" export RUST_LOG=${logLevel} export SSL_CERT_FILE=${cacert}/etc/ssl/certs/ca-bundle.crt - - # Let's find out which $indexHash cargo uses for file:///dev/null - (cd $sourceRoot && cargo fetch &>/dev/null) || true - cd deps - indexHash="$(basename $(echo registry/index/*))" - - echo "Using indexHash '$indexHash'" - - rm -rf -- "registry/cache/$indexHash" \ - "registry/index/$indexHash" - - mv registry/cache/HASH "registry/cache/$indexHash" - - echo "Using rust registry from $rustRegistry" - ln -s "$rustRegistry" "registry/index/$indexHash" - - # Retrieved the Cargo.lock file which we saved during the fetch - cd .. - mv deps/Cargo.lock $sourceRoot/ - - ( - cd $sourceRoot - - cargo fetch - cargo clean - ) '' + (args.postUnpack or ""); - prePatch = '' - # Patch registry dependencies, using the scripts in $patchRegistryDeps - ( - set -euo pipefail - - cd $NIX_BUILD_TOP/deps/registry/src/* - - for script in $patchRegistryDeps/*; do - # Run in a subshell so that directory changes and shell options don't - # affect any following commands - - ( . $script) - done - ) - '' + (args.prePatch or ""); - buildPhase = with builtins; args.buildPhase or '' runHook preBuild echo "Running cargo build --release ${concatStringsSep " " cargoBuildFlags}" - cargo build --release ${concatStringsSep " " cargoBuildFlags} + cargo build --release --frozen ${concatStringsSep " " cargoBuildFlags} runHook postBuild ''; @@ -126,4 +79,6 @@ in stdenv.mkDerivation (args // { find target/release -maxdepth 1 -executable -exec cp "{}" $out/bin \; runHook postInstall ''; + + passthru = { inherit cargoDeps; }; }) |