From dd6e94f2c1ae61633c69c6416c9da9d9853015ca Mon Sep 17 00:00:00 2001 From: Alyssa Ross Date: Fri, 2 Jul 2021 14:58:42 +0000 Subject: 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"; } --- pkgs/build-support/fetchpatch/default.nix | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/pkgs/build-support/fetchpatch/default.nix b/pkgs/build-support/fetchpatch/default.nix index d059715cedc..a3ca6685147 100644 --- a/pkgs/build-support/fetchpatch/default.nix +++ b/pkgs/build-support/fetchpatch/default.nix @@ -8,6 +8,7 @@ { relative ? null , stripLen ? 0 +, decode ? "cat" # custom command to decode patch e.g. base64 -d , extraPrefix ? null , excludes ? [] , includes ? [] @@ -36,6 +37,17 @@ fetchurl ({ exit 1 fi + set +e + ${decode} < "$out" > "$tmpfile" + if [ $? -ne 0 ] || [ ! -s "$tmpfile" ]; then + echo 'Failed to decode patch with command "'${lib.escapeShellArg decode}'"' >&2 + echo 'Fetched file was (limited to 128 bytes):' >&2 + od -A x -t x1z -v -N 128 "$out" >&2 + exit 1 + fi + set -e + mv "$tmpfile" "$out" + "${patchutils}/bin/lsdiff" \ ${lib.optionalString (relative != null) "-p1 -i ${lib.escapeShellArg relative}/'*'"} \ "$out" \ @@ -76,5 +88,6 @@ fetchurl ({ mv "$tmpfile" "$out" '' + postFetch; } // builtins.removeAttrs args [ - "relative" "stripLen" "extraPrefix" "excludes" "includes" "revert" "postFetch" + "relative" "stripLen" "decode" "extraPrefix" "excludes" "includes" "revert" + "postFetch" ]) -- cgit 1.4.1