diff options
author | Ivar Scholten <ivar.scholten@protonmail.com> | 2022-09-12 13:50:18 +0200 |
---|---|---|
committer | Bjørn Forsman <bjorn.forsman@gmail.com> | 2022-09-25 16:17:36 +0200 |
commit | 987d32bbaca9b58c4aa652bdf7a26c86b70c182b (patch) | |
tree | f56aa2071e1f9c2ebff6dab3721b2f627b343314 /pkgs/build-support | |
parent | bf9ff0c6873e8c828617e72b66eeeec3026b9201 (diff) | |
download | nixlib-987d32bbaca9b58c4aa652bdf7a26c86b70c182b.tar nixlib-987d32bbaca9b58c4aa652bdf7a26c86b70c182b.tar.gz nixlib-987d32bbaca9b58c4aa652bdf7a26c86b70c182b.tar.bz2 nixlib-987d32bbaca9b58c4aa652bdf7a26c86b70c182b.tar.lz nixlib-987d32bbaca9b58c4aa652bdf7a26c86b70c182b.tar.xz nixlib-987d32bbaca9b58c4aa652bdf7a26c86b70c182b.tar.zst nixlib-987d32bbaca9b58c4aa652bdf7a26c86b70c182b.zip |
buildRustPackage: dont rely on NIX_BUILD_TOP in cargoSetupPostPatchHook
This breaks the builder when a nix-shell or keepBuildTree is used. The issue occurs because paths to cargo lockfiles are read with NIX_BUILD_TOP, which is not reliable. This breaks a nix-shell because NIX_BUILD_TOP simply is not set, causing an invalid path to be used. This can be worked around using NIX_BUILD_TOP=$PWD, but that obviously is not great. This breaks keepBuildTree because it changes the working directory to a different path than NIX_BUILD_TOP. Since the lockfiles are copied based on the working directory, but read based on NIX_BUILD_TOP, this causes the hook to not be able to find them. This was solved by both reading these files based on the working directory, using absolute paths to avoid having to traverse back in the directory tree. Fixes: #138554
Diffstat (limited to 'pkgs/build-support')
-rw-r--r-- | pkgs/build-support/rust/hooks/cargo-setup-hook.sh | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/pkgs/build-support/rust/hooks/cargo-setup-hook.sh b/pkgs/build-support/rust/hooks/cargo-setup-hook.sh index 842e66b5170e..b85796e2a41b 100644 --- a/pkgs/build-support/rust/hooks/cargo-setup-hook.sh +++ b/pkgs/build-support/rust/hooks/cargo-setup-hook.sh @@ -7,23 +7,23 @@ cargoSetupPostUnpackHook() { # this for us automatically. if [ -z $cargoVendorDir ]; then unpackFile "$cargoDeps" - export cargoDepsCopy=$(stripHash $cargoDeps) + export cargoDepsCopy="$(realpath "$(stripHash $cargoDeps)")" else - cargoDepsCopy="$sourceRoot/${cargoRoot:+$cargoRoot/}${cargoVendorDir}" + cargoDepsCopy="$(realpath "$(pwd)/$sourceRoot/${cargoRoot:+$cargoRoot/}${cargoVendorDir}")" fi if [ ! -d .cargo ]; then mkdir .cargo fi - config="$(pwd)/$cargoDepsCopy/.cargo/config"; + config="$cargoDepsCopy/.cargo/config"; if [[ ! -e $config ]]; then config=@defaultConfig@ fi; tmp_config=$(mktemp) substitute $config $tmp_config \ - --subst-var-by vendor "$(pwd)/$cargoDepsCopy" + --subst-var-by vendor "$cargoDepsCopy" cat ${tmp_config} >> .cargo/config cat >> .cargo/config <<'EOF' @@ -39,8 +39,8 @@ EOF cargoSetupPostPatchHook() { echo "Executing cargoSetupPostPatchHook" - cargoDepsLockfile="$NIX_BUILD_TOP/$cargoDepsCopy/Cargo.lock" - srcLockfile="$NIX_BUILD_TOP/$sourceRoot/${cargoRoot:+$cargoRoot/}/Cargo.lock" + cargoDepsLockfile="$cargoDepsCopy/Cargo.lock" + srcLockfile="$(pwd)/${cargoRoot:+$cargoRoot/}Cargo.lock" echo "Validating consistency between $srcLockfile and $cargoDepsLockfile" if ! @diff@ $srcLockfile $cargoDepsLockfile; then |