Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)
1cargoSetupPostUnpackHook() {
2 echo "Executing cargoSetupPostUnpackHook"
3
4 # Some cargo builds include build hooks that modify their own vendor
5 # dependencies. This copies the vendor directory into the build tree and makes
6 # it writable. If we're using a tarball, the unpackFile hook already handles
7 # this for us automatically.
8 if [ -z $cargoVendorDir ]; then
9 if [ -d "$cargoDeps" ]; then
10 local dest=$(stripHash "$cargoDeps")
11 cp -Lr --reflink=auto -- "$cargoDeps" "$dest"
12 chmod -R +644 -- "$dest"
13 else
14 unpackFile "$cargoDeps"
15 fi
16 export cargoDepsCopy="$(realpath "$(stripHash $cargoDeps)")"
17 else
18 cargoDepsCopy="$(realpath "$(pwd)/$sourceRoot/${cargoRoot:+$cargoRoot/}${cargoVendorDir}")"
19 fi
20
21 if [ ! -d .cargo ]; then
22 mkdir .cargo
23 fi
24
25 config="$cargoDepsCopy/.cargo/config.toml"
26 if [[ ! -e $config ]]; then
27 config=@defaultConfig@
28 fi;
29
30 tmp_config=$(mktemp)
31 substitute $config $tmp_config \
32 --subst-var-by vendor "$cargoDepsCopy"
33 cat ${tmp_config} >> .cargo/config.toml
34
35 cat >> .cargo/config.toml <<'EOF'
36 @cargoConfig@
37EOF
38
39 echo "Finished cargoSetupPostUnpackHook"
40}
41
42# After unpacking and applying patches, check that the Cargo.lock matches our
43# src package. Note that we do this after the patchPhase, because the
44# patchPhase may create the Cargo.lock if upstream has not shipped one.
45cargoSetupPostPatchHook() {
46 echo "Executing cargoSetupPostPatchHook"
47
48 cargoDepsLockfile="$cargoDepsCopy/Cargo.lock"
49 srcLockfile="$(pwd)/${cargoRoot:+$cargoRoot/}Cargo.lock"
50
51 echo "Validating consistency between $srcLockfile and $cargoDepsLockfile"
52 if ! @diff@ $srcLockfile $cargoDepsLockfile; then
53
54 # If the diff failed, first double-check that the file exists, so we can
55 # give a friendlier error msg.
56 if ! [ -e $srcLockfile ]; then
57 echo "ERROR: Missing Cargo.lock from src. Expected to find it at: $srcLockfile"
58 echo "Hint: You can use the cargoPatches attribute to add a Cargo.lock manually to the build."
59 exit 1
60 fi
61
62 if ! [ -e $cargoDepsLockfile ]; then
63 echo "ERROR: Missing lockfile from cargo vendor. Expected to find it at: $cargoDepsLockfile"
64 exit 1
65 fi
66
67 echo
68 echo "ERROR: cargoHash or cargoSha256 is out of date"
69 echo
70 echo "Cargo.lock is not the same in $cargoDepsCopy"
71 echo
72 echo "To fix the issue:"
73 echo '1. Set cargoHash/cargoSha256 to an empty string: `cargoHash = "";`'
74 echo '2. Build the derivation and wait for it to fail with a hash mismatch'
75 echo '3. Copy the "got: sha256-..." value back into the cargoHash field'
76 echo ' You should have: cargoHash = "sha256-XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX=";'
77 echo
78
79 exit 1
80 fi
81
82 unset cargoDepsCopy
83
84 echo "Finished cargoSetupPostPatchHook"
85}
86
87if [ -z "${dontCargoSetupPostUnpack-}" ]; then
88 postUnpackHooks+=(cargoSetupPostUnpackHook)
89fi
90
91if [ -z ${cargoVendorDir-} ]; then
92 postPatchHooks+=(cargoSetupPostPatchHook)
93fi