-
Notifications
You must be signed in to change notification settings - Fork 89
/
regenerate_cargo_nix.sh
executable file
·75 lines (62 loc) · 2.1 KB
/
regenerate_cargo_nix.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#!/usr/bin/env bash
set -Eeuo pipefail
top="$(readlink -f "$(dirname "$0")")"
if [ -z "${IN_CRATE2NIX_SHELL:-}" ]; then
exec nix-shell --extra-experimental-features flakes --pure "$top/shell.nix" --run "$(printf "%q " $0 "$@")"
fi
options=$(getopt -o '' --long offline,no-cargo-build -- "$@")
[ $? -eq 0 ] || {
echo "Incorrect options provided. Available:"
echo " --offline Enable offline friendly operations with out substituters"
echo " --no-cargo-build Skip local cargo build." >&2
exit 1
}
eval set -- "$options"
NIX_OPTIONS="--option log-lines 100 --show-trace"
NO_CARGO_BUILD=""
while true; do
case "$1" in
--no-cargo-build)
NO_CARGO_BUILD=1
;;
--offline)
NIX_OPTIONS="--option substitute false"
;;
--)
shift
break
;;
esac
shift
done
echo "================ Regenerating ./Cargo.nix =================="
cd "${top}"
function noisily {
set -x
"$@"
{ set +x; } 2>/dev/null
return $?
}
if [ -z "${NO_CARGO_BUILD}" ]; then
(cd crate2nix; noisily ../cargo.sh run -- generate -n ../nix/nixpkgs.nix \
-f ./Cargo.toml -o ./Cargo.nix) ||\
{ echo "Bootstrap regeneration of ./Cargo.nix failed." >&2 ; exit 1; }
else
echo "Skipping because of --no-cargo-build"
fi
noisily nix-build --extra-experimental-features flakes --arg release false $NIX_OPTIONS
crate2nix=$(nix-build --extra-experimental-features flakes --arg release false $NIX_OPTIONS)/bin/crate2nix
noisily "$crate2nix" generate -n ../nix/nixpkgs.nix \
-f ./crate2nix/Cargo.toml -o ./crate2nix/Cargo.nix || \
{ echo "Regeneration of ./Cargo.nix failed." >&2 ; exit 1; }
nix-instantiate --extra-experimental-features flakes tests.nix --eval --strict --json -A buildTestConfigs | \
jq -r .[].pregeneratedBuild | \
while read cargo_nix; do
if [ "$cargo_nix" = "null" ]; then
continue
fi
dir=$(dirname "$cargo_nix")
echo "=============== Regenerating ${cargo_nix} ================"
noisily "$crate2nix" generate -f "$dir/Cargo.toml" -o "$cargo_nix" ||\
{ echo "Regeneration of ${cargo_nix} failed." >&2 ; exit 1; }
done