nix-helpers: 591f14f6addb19235955ebf7cbdbac4cb9ece376

     1: #!/usr/bin/env bash
     2: set -e
     3: 
     4: if [[ "x$1" = "x-h" ]] || [[ "x$1" = "x--help" ]] || [[ "x$1" = "x-?" ]]
     5: then
     6:     {
     7:         echo "nix_release: Find and build all Nix derivations defined in a file"
     8:         echo
     9:         echo "Runs nix_release_eval to find all Nix derivations, then attempts"
    10:         echo "to build each in turn. Reports how many succeed/fail at the end."
    11:         echo
    12:         echo "Any (optional) arguments will be passed to the build commands,"
    13:         echo "which are 'nix-store --realise ...' (followed by each .drv)."
    14:         echo
    15:         echo "Set the ADD_ROOT env var to a directory path if you would like"
    16:         echo "garbage collector roots to be created."
    17:         echo
    18:         echo "Set the F env var to the path you'd like to import. If F is not"
    19:         echo "set, we default to looking for a ./release.nix file, then"
    20:         echo "./nix/release.nix, then ./default.nix and finally"
    21:         echo "./nix/default.nix; the first one found will be used, or we abort"
    22:         echo "if none is found."
    23:     } 1>&2
    24:     exit 0
    25: fi
    26: 
    27: if [[ -n "$ADD_ROOT" ]]
    28: then
    29:     [[ -e "$ADD_ROOT" ]] || fail "ADD_ROOT dir '$ADD_ROOT' doesn't exist"
    30:     echo "GC roots will be made in '$ADD_ROOT'" 1>&2
    31: else
    32:     echo "Won't make GC roots. If you want them, give an \$ADD_ROOT dir" 1>&2
    33: fi
    34: 
    35: DRVPATHS=$("$nix_release_eval") ||  fail "Failed to get paths, aborting"
    36: 
    37: function build {
    38:     nix-store --show-trace --realise "$@"
    39: }
    40: 
    41: echo "Building derivations" 1>&2
    42: COUNT=0
    43: FAILS=0
    44: while read -r PAIR
    45: do
    46:     COUNT=$(( COUNT + 1 ))
    47:      ATTR=$(echo "$PAIR" | cut -f1)
    48:       DRV=$(echo "$PAIR" | cut -f2)
    49: 
    50:     echo "Building $ATTR" 1>&2
    51:     if [[ -n "$ADD_ROOT" ]]
    52:     then
    53:         build --indirect --add-root "$ADD_ROOT/$ATTR" "$@" "$DRV" ||
    54:             FAILS=$(( FAILS + 1 ))
    55:     else
    56:         build                                         "$@" "$DRV" ||
    57:             FAILS=$(( FAILS + 1 ))
    58:     fi
    59: done < <(echo "$DRVPATHS")
    60: 
    61: if [[ "$FAILS" -eq 0 ]]
    62: then
    63:     echo "All $COUNT built successfully" 1>&2
    64: else
    65:     printf '%s/%s builds failed\n' "$FAILS" "$COUNT" 1>&2
    66:     exit 1
    67: fi

Generated by git2html.