forked from grahamc/r13y.com
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheck.sh
More file actions
executable file
·100 lines (77 loc) · 2.48 KB
/
check.sh
File metadata and controls
executable file
·100 lines (77 loc) · 2.48 KB
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#!/usr/bin/env nix-shell
#!nix-shell -i bash -p jq diffoscope nix git findutils coreutils --pure
set -eux
export LANG=en_US.UTF-8
export LOCALE_ARCHIVE=/run/current-system/sw/lib/locale/locale-archive
CORES=$(nproc)
REPORT_STORE=$(pwd)/public
function update_nixpkgs() (
if [ ! -d ./nixpkgs ]; then
git clone https://github.com/nixos/nixpkgs-channels.git ./nixpkgs
fi
cd nixpkgs
git fetch origin
git checkout origin/nixos-unstable-small
)
function nixpkgs_rev() (
cd nixpkgs
git rev-parse HEAD
)
function nix_store_path_requisite_drvs() {
nix-store --query --requisites "$1" | grep '\.drv$'
}
function find_iso_minimal_drv_x86_64_linux() (
nix-instantiate \
./nixpkgs/nixos/release-combined.nix \
-A nixos.iso_minimal.x86_64-linux \
--add-root ./result.drv --indirect
)
function drv_outputs() {
nix show-derivation "$1" \
| jq -r '. | map(.outputs) | .[0] | map(.path) | .[]'
}
function drv_name() (
echo "$1" | tail -c+45
)
function log() {
status="$1"
drv="$2"
printf "%s\t%s\n" "$status" "$drv" | tee -a "$LOGFILE"
}
function have_checked_before() {
grep -q "$1" "$LOGFILE"
}
function main() {
update_nixpkgs
export REV=$(nixpkgs_rev)
export LOGFILE="./reproducibility-log-$REV"
top_level_drv=$(find_iso_minimal_drv_x86_64_linux)
printf "ISO Drv: %s\n" "$top_level_drv"
mkdir -p "$REPORT_STORE/diff"
attempted=0
total=$(nix_store_path_requisite_drvs "$top_level_drv" | wc -l)
for drv in $(nix_store_path_requisite_drvs "$top_level_drv"); do
attempted=$((attempted + 1))
drvname=$(drv_name "$drv")
(
nix copy "$drv" --to "$REPORT_STORE"
if have_checked_before "$drv"; then
echo "Built before."
elif ! nix-build "$drv" --option cores "$CORES"; then
log "failed-on-first-build" "$drv"
elif nix-build "$drv" --check --keep-failed --option cores "$CORES"; then
log "reproducible" "$drv"
else
for path in $(drv_outputs "$drv"); do
set +e
if [ -e "$path.check" ]; then
diffoscope --html - "$path" "$path.check" >> "$REPORT_STORE/diff/$(basename "$drv").html"
fi
set -e
done
log "unreproducible" "$drv"
fi
) 2>&1 | sed -e "s#^#($attempted / $total | $drvname) #"
done
}
main