diff options
author | Ricardo M. Correia <rcorreia@wizy.org> | 2015-04-23 20:15:47 +0200 |
---|---|---|
committer | Ricardo M. Correia <rcorreia@wizy.org> | 2015-04-23 20:22:19 +0200 |
commit | d6093505cc59c7cf5540afd044dea9ab8d5c1e9b (patch) | |
tree | 09b753f7a1a26c42e0f19b4ffb0d777c9065e0dd /pkgs/build-support/rust/default.nix | |
parent | b993c2113c8191ca9b454abfc79d02196b6a2bd0 (diff) | |
download | nixpkgs-d6093505cc59c7cf5540afd044dea9ab8d5c1e9b.tar nixpkgs-d6093505cc59c7cf5540afd044dea9ab8d5c1e9b.tar.gz nixpkgs-d6093505cc59c7cf5540afd044dea9ab8d5c1e9b.tar.bz2 nixpkgs-d6093505cc59c7cf5540afd044dea9ab8d5c1e9b.tar.lz nixpkgs-d6093505cc59c7cf5540afd044dea9ab8d5c1e9b.tar.xz nixpkgs-d6093505cc59c7cf5540afd044dea9ab8d5c1e9b.tar.zst nixpkgs-d6093505cc59c7cf5540afd044dea9ab8d5c1e9b.zip |
buildRustPackage: Get rid of /proc/self/cwd hack
This makes buildRustPackage portable to non-Linux platforms. Additionally, now we also save the `Cargo.lock` file into the fetch output, so that we don't have to run $cargoUpdateHook again just before building.
Diffstat (limited to 'pkgs/build-support/rust/default.nix')
-rw-r--r-- | pkgs/build-support/rust/default.nix | 37 |
1 files changed, 25 insertions, 12 deletions
diff --git a/pkgs/build-support/rust/default.nix b/pkgs/build-support/rust/default.nix index 2a890a0d232..ddf2fce3cae 100644 --- a/pkgs/build-support/rust/default.nix +++ b/pkgs/build-support/rust/default.nix @@ -11,8 +11,16 @@ let sha256 = depsSha256; }; + # The following is the directory name cargo creates when the registry index + # URL is file:///dev/null + # + # 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 + registryIndexDirName = "-ba82b75dd6681d6f"; + in stdenv.mkDerivation (args // { - inherit cargoDeps rustRegistry cargoUpdateHook; + inherit cargoDeps rustRegistry; patchRegistryDeps = ./patch-registry-deps; @@ -22,21 +30,26 @@ in stdenv.mkDerivation (args // { postUnpack = '' echo "Using cargo deps from $cargoDeps" - cp -r $cargoDeps deps + + cp -r "$cargoDeps" deps chmod +w deps -R - export CARGO_HOME=$(realpath deps) + cat <<EOF > deps/config + [registry] + index = "file:///dev/null" + EOF echo "Using rust registry from $rustRegistry" - ( - cd $sourceRoot - ln -s $rustRegistry ./cargo-rust-registry - substituteInPlace Cargo.lock \ - --replace "registry+https://github.com/rust-lang/crates.io-index" \ - "registry+file:///proc/self/cwd/cargo-rust-registry" + ln -s "$rustRegistry" "deps/registry/index/${registryIndexDirName}" + + export CARGO_HOME="$(realpath deps)" + + # Retrieved the Cargo.lock file which we saved during the fetch + mv deps/Cargo.lock $sourceRoot/ - eval "$cargoUpdateHook" + ( + cd $sourceRoot cargo fetch cargo clean @@ -46,10 +59,10 @@ in stdenv.mkDerivation (args // { prePatch = '' # Patch registry dependencies, using the scripts in $patchRegistryDeps ( - cd ../deps/registry/src/* - set -euo pipefail + cd ../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 |