fetchpatch: add "decode" argument for gerrit

(and gitiles)

This allows fetching a patch from servers that return them
base64-encoded, like this:

fetchpatch {
name = "gcc.patch";
url = "https://chromium.googlesource.com/aosp/platform/external/libchrome/+/f37ae3b1a873d74182a2ac31d96742ead9c1f523^!?format=TEXT";
decode = "base64 -d";
sha256 = "11j1bqz2p8xrfzgfrylgdvmqs45489c4ckl7l0ra1dpfgbqy94a8";
}

+14 -1
+14 -1
pkgs/build-support/fetchpatch/default.nix
··· 8 8 9 9 { relative ? null 10 10 , stripLen ? 0 11 + , decode ? "cat" # custom command to decode patch e.g. base64 -d 11 12 , extraPrefix ? null 12 13 , excludes ? [] 13 14 , includes ? [] ··· 35 36 echo "error: Fetched patch file '$out' is empty!" 1>&2 36 37 exit 1 37 38 fi 39 + 40 + set +e 41 + ${decode} < "$out" > "$tmpfile" 42 + if [ $? -ne 0 ] || [ ! -s "$tmpfile" ]; then 43 + echo 'Failed to decode patch with command "'${lib.escapeShellArg decode}'"' >&2 44 + echo 'Fetched file was (limited to 128 bytes):' >&2 45 + od -A x -t x1z -v -N 128 "$out" >&2 46 + exit 1 47 + fi 48 + set -e 49 + mv "$tmpfile" "$out" 38 50 39 51 "${patchutils}/bin/lsdiff" \ 40 52 ${lib.optionalString (relative != null) "-p1 -i ${lib.escapeShellArg relative}/'*'"} \ ··· 76 88 mv "$tmpfile" "$out" 77 89 '' + postFetch; 78 90 } // builtins.removeAttrs args [ 79 - "relative" "stripLen" "extraPrefix" "excludes" "includes" "revert" "postFetch" 91 + "relative" "stripLen" "decode" "extraPrefix" "excludes" "includes" "revert" 92 + "postFetch" 80 93 ])