2017-05-16 21:30:09 +00:00
|
|
|
|
#!/usr/bin/env bash
|
2017-06-18 10:30:08 +00:00
|
|
|
|
#
|
2017-05-16 21:30:09 +00:00
|
|
|
|
# Prints build logs for failed derivations in quiet build mode (-Q).
|
|
|
|
|
# See https://github.com/NixOS/nix/issues/443
|
|
|
|
|
#
|
|
|
|
|
# Usage:
|
|
|
|
|
#
|
2017-06-18 10:34:34 +00:00
|
|
|
|
# nix-build ... -Q ... 2>&1 | whatsupnix [user@target[:port]]
|
2017-05-16 21:30:09 +00:00
|
|
|
|
#
|
2017-06-18 10:30:08 +00:00
|
|
|
|
# Exit Codes:
|
|
|
|
|
#
|
|
|
|
|
# 0 No failed derivations could be found. This either means there where
|
|
|
|
|
# no build errors, or stdin wasn't nix-build output.
|
|
|
|
|
#
|
|
|
|
|
# 1 Usage error; arguments couldn't be parsed.
|
|
|
|
|
#
|
2017-07-12 14:56:14 +00:00
|
|
|
|
# 2 Nix error; input looks like Nix failed.
|
|
|
|
|
#
|
|
|
|
|
# 3 Build error; at least one failed derivation could be found.
|
2017-06-18 10:30:08 +00:00
|
|
|
|
#
|
2017-05-16 21:30:09 +00:00
|
|
|
|
|
2017-07-12 14:56:14 +00:00
|
|
|
|
tmpdir=$(mktemp -d --tmpdir whatsupnix.XXXXXXXX)
|
|
|
|
|
failed_drvs=$tmpdir/failed_drvs; touch "$failed_drvs"
|
|
|
|
|
nix_errors=$tmpdir/nix_errors; touch "$nix_errors"
|
|
|
|
|
cleanup() {
|
|
|
|
|
rm "$failed_drvs"
|
|
|
|
|
rm "$nix_errors"
|
|
|
|
|
rmdir "$tmpdir"
|
|
|
|
|
}
|
|
|
|
|
trap cleanup EXIT
|
2017-05-16 21:30:09 +00:00
|
|
|
|
|
|
|
|
|
exec >&2
|
|
|
|
|
|
2017-07-12 14:56:14 +00:00
|
|
|
|
gawk \
|
|
|
|
|
-v failed_drvs="$failed_drvs" \
|
|
|
|
|
-v nix_errors="$nix_errors" \
|
|
|
|
|
'
|
|
|
|
|
/^(\033\[31;1m)?error:/ {
|
|
|
|
|
print $0 >> nix_errors
|
|
|
|
|
}
|
2017-06-15 17:55:28 +00:00
|
|
|
|
match($0, /^builder for ‘(\/nix\/store\/[^’]+\.drv)’ failed/, m) {
|
2017-06-18 10:33:46 +00:00
|
|
|
|
print m[1] >> failed_drvs
|
2017-05-16 21:30:09 +00:00
|
|
|
|
}
|
2017-06-30 02:53:34 +00:00
|
|
|
|
{ print $0; fflush("/dev/stdout") }
|
2017-06-15 17:55:28 +00:00
|
|
|
|
'
|
|
|
|
|
|
|
|
|
|
case $# in
|
|
|
|
|
0)
|
|
|
|
|
print_log() {
|
2017-06-28 01:31:14 +00:00
|
|
|
|
NIX_PAGER= nix-store -l "$1"
|
2017-06-15 17:55:28 +00:00
|
|
|
|
}
|
|
|
|
|
;;
|
|
|
|
|
1)
|
|
|
|
|
remote_user=${1%%@*}
|
|
|
|
|
if test "$remote_user" = "$1"; then
|
|
|
|
|
remote_user=root
|
|
|
|
|
else
|
|
|
|
|
set -- "${1#$remote_user@}"
|
|
|
|
|
fi
|
|
|
|
|
remote_port=${1##*:}
|
|
|
|
|
if test "$remote_port" = "$1"; then
|
|
|
|
|
remote_port=22
|
|
|
|
|
else
|
|
|
|
|
set -- "${1%:$remote_port}"
|
|
|
|
|
fi
|
|
|
|
|
remote_host=$1
|
|
|
|
|
print_log() {
|
|
|
|
|
ssh "$remote_user@$remote_host" -p "$remote_port" \
|
2017-06-18 10:22:48 +00:00
|
|
|
|
env NIX_PAGER= nix-store -l "$1"
|
2017-06-15 17:55:28 +00:00
|
|
|
|
}
|
|
|
|
|
;;
|
|
|
|
|
*)
|
|
|
|
|
echo "usage: whatsupnix [[USER@]HOST[:PORT]]" >&2
|
|
|
|
|
exit 1
|
|
|
|
|
esac
|
2017-05-16 21:30:09 +00:00
|
|
|
|
|
|
|
|
|
while read -r drv; do
|
2017-06-15 17:55:28 +00:00
|
|
|
|
title="** FAILED $drv LOG **"
|
2017-05-16 21:30:09 +00:00
|
|
|
|
frame=${title//?/*}
|
|
|
|
|
|
|
|
|
|
echo "$frame"
|
|
|
|
|
echo "$title"
|
|
|
|
|
echo "$frame"
|
|
|
|
|
echo
|
|
|
|
|
|
2017-06-15 17:55:28 +00:00
|
|
|
|
print_log "$drv"
|
2017-05-16 21:30:09 +00:00
|
|
|
|
|
|
|
|
|
echo
|
2017-06-18 10:33:46 +00:00
|
|
|
|
done < "$failed_drvs"
|
2017-05-16 21:30:09 +00:00
|
|
|
|
|
2017-07-12 14:56:14 +00:00
|
|
|
|
if test -s "$nix_errors"; then
|
2017-06-18 10:30:08 +00:00
|
|
|
|
exit 2
|
2017-07-12 14:56:14 +00:00
|
|
|
|
elif test -s "$failed_drvs"; then
|
|
|
|
|
exit 3
|
2017-06-18 10:30:08 +00:00
|
|
|
|
else
|
|
|
|
|
exit 0
|
|
|
|
|
fi
|