summaryrefslogtreecommitdiffstats
path: root/krebs/5pkgs/whatsupnix/whatsupnix.bash
blob: a1941005589b17aa80be3b694ddef6f9b61a678d (plain)
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
#!/usr/bin/env bash

# Prints build logs for failed derivations in quiet build mode (-Q).
# See https://github.com/NixOS/nix/issues/443
#
# Usage:
#
#    set -o pipefail
#    nix-build ... -Q ... | whatsupnix
#


GAWK=${GAWK:-gawk}
NIX_STORE=${NIX_STORE:-nix-store}

broken=$(mktemp)
trap 'rm -f -- "$broken"' EXIT

exec >&2

$GAWK -v broken="$broken" -f <(cat - <<- 'AWK'
  match($0, /builder for .*(\/nix\/store\/.+\.drv).* failed/, m) {
    print m[1] >> broken
  }
  { print $0 }
AWK
)

export NIX_PAGER='' # for nix-store
while read -r drv; do
  title="** FAILED $drv LOG  **"
  frame=${title//?/*}

  echo "$frame"
  echo "$title"
  echo "$frame"
  echo

  $NIX_STORE -l "$drv"

  echo
done < "$broken"

exit 0