|
1 | 1 | #!/usr/bin/env nix-shell
|
2 |
| -#!nix-shell -i bash -p moreutils -I nixpkgs=channel:nixpkgs-unstable |
| 2 | +#!nix-shell -i bash -p coreutils moreutils -I nixpkgs=channel:nixpkgs-unstable |
3 | 3 |
|
4 | 4 | set -euxo pipefail
|
5 | 5 |
|
6 |
| -system="x86_64-linux" |
7 |
| -SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" |
| 6 | +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" &>/dev/null && pwd)" |
8 | 7 | NIXPKGS_PATH="$(readlink -f "$SCRIPT_DIR"/..)"
|
9 | 8 |
|
| 9 | +system="x86_64-linux" |
| 10 | +quick_test=0 |
| 11 | +CORES=$(nproc) |
| 12 | + |
10 | 13 | parseArgs() {
|
11 |
| - while [[ $# -gt 0 ]]; do |
12 |
| - case $1 in |
13 |
| - --system) |
14 |
| - system=$2 |
15 |
| - shift 2 |
16 |
| - ;; |
17 |
| - *) |
18 |
| - echo "Unknown argument: $1" |
19 |
| - exit 1 |
20 |
| - ;; |
21 |
| - esac |
22 |
| - done |
| 14 | + while [[ $# -gt 0 ]]; do |
| 15 | + arg=$1 |
| 16 | + shift |
| 17 | + case "$arg" in |
| 18 | + --system) |
| 19 | + system=$1 |
| 20 | + shift 1 |
| 21 | + ;; |
| 22 | + --cores) |
| 23 | + CORES=$1 |
| 24 | + shift 1 |
| 25 | + ;; |
| 26 | + --quick-test) |
| 27 | + quick_test=1 |
| 28 | + ;; |
| 29 | + *) |
| 30 | + echo "Unknown argument: $arg" |
| 31 | + exit 1 |
| 32 | + ;; |
| 33 | + esac |
| 34 | + done |
23 | 35 | }
|
24 | 36 |
|
25 | 37 | main() {
|
26 | 38 | parseArgs "$@"
|
27 | 39 | tmpdir=$(mktemp -d)
|
28 | 40 | trap 'rm -rf "$tmpdir"' EXIT
|
29 | 41 |
|
30 |
| - nix-instantiate --eval --strict --json --arg enableWarnings false "$NIXPKGS_PATH"/pkgs/top-level/release-attrpaths-superset.nix -A paths > "$tmpdir/paths.json" |
| 42 | + nix-instantiate --eval --strict --json --arg enableWarnings false "$NIXPKGS_PATH"/pkgs/top-level/release-attrpaths-superset.nix -A paths >"$tmpdir/paths.json" |
31 | 43 |
|
32 |
| - CORES=$(nproc) |
33 | 44 | # Originally @amjoseph: note that the number of processes spawned is four times
|
34 | 45 | # the number of cores -- this helps in two ways:
|
35 | 46 | # 1. Keeping cores busy while I/O operations are in flight
|
36 | 47 | # 2. Since the amount of time needed for the jobs is *not* balanced
|
37 | 48 | # this minimizes the "tail latency" for the very last job to finish
|
38 | 49 | # (on one core) by making the job size smaller.
|
39 |
| - NUM_CHUNKS=$(( 4 * CORES )) |
40 |
| - |
| 50 | + local num_chunks=$((4 * CORES)) |
| 51 | + local seq_end=$((num_chunks - 1)) |
| 52 | + if [[ $quick_test -eq 1 ]]; then |
| 53 | + seq_end=0 |
| 54 | + fi |
41 | 55 |
|
42 | 56 | (
|
43 |
| - set +e |
44 |
| - parallel -j "$CORES" \ |
45 |
| - nix-env -qaP --no-name --out-path --arg checkMeta true --arg includeBroken true \ |
46 |
| - --arg systems "[\"$system\"]" \ |
47 |
| - -f "$NIXPKGS_PATH"/ci/parallel.nix --arg attrPathFile "$tmpdir"/paths.json \ |
48 |
| - --arg numChunks "$NUM_CHUNKS" --show-trace --arg myChunk \ |
49 |
| - -- $(seq 0 $(( NUM_CHUNKS - 1 ))) > "$tmpdir/paths" |
50 |
| - echo $? > "$tmpdir/exit-code" |
| 57 | + set +e |
| 58 | + seq 0 $seq_end | xargs -P "$CORES" -I {} nix-env -qaP --no-name --out-path --arg checkMeta true --arg includeBroken true \ |
| 59 | + --arg systems "[\"$system\"]" \ |
| 60 | + -f "$NIXPKGS_PATH"/ci/parallel.nix --arg attrPathFile "$tmpdir"/paths.json \ |
| 61 | + --arg numChunks "$num_chunks" --show-trace --arg myChunk {} >"$tmpdir/paths" |
| 62 | + echo $? >"$tmpdir/exit-code" |
51 | 63 | ) &
|
52 | 64 | pid=$!
|
53 | 65 | while kill -0 "$pid"; do
|
54 | 66 | free -g >&2
|
55 | 67 | sleep 20
|
56 | 68 | done
|
57 |
| - jq --raw-input --slurp 'split("\n") | map(select(. != "") | split(" ") | map(select(. != "")) | { key: .[0], value: .[1] }) | from_entries' "$tmpdir/paths" |
| 69 | + |
| 70 | + # Extract derivation outputs for each attribute into a JSON object |
| 71 | + # i.e. { "attr1": { "out": "/nix/store/...", "dev": "/nix/store/..." }, ... } |
| 72 | + jq --raw-input --slurp ' |
| 73 | + split("\n") | |
| 74 | + map(select(. != "") | split(" ") | map(select(. != ""))) | |
| 75 | + map( |
| 76 | + { |
| 77 | + key: .[0], |
| 78 | + value: .[1] | split(";") | map(split("=") | |
| 79 | + if length == 1 then |
| 80 | + { key: "out", value: .[0] } |
| 81 | + else |
| 82 | + { key: .[0], value: .[1] } |
| 83 | + end) | from_entries} |
| 84 | + ) | from_entries |
| 85 | + ' "$tmpdir/paths" |
58 | 86 | exit "$(cat "$tmpdir/exit-code")"
|
59 | 87 | }
|
60 | 88 |
|
|
0 commit comments