fetchpatch: add patchutils to nativeBuildInputs

This change allows using programs from patchutils in postFetch.
This commit is contained in:
Ivan Trubach 2024-07-01 17:01:44 +03:00
parent 32b51c3352
commit 6ed79156ce
2 changed files with 9 additions and 7 deletions

View File

@ -14,6 +14,7 @@
, includes ? []
, revert ? false
, postFetch ? ""
, nativeBuildInputs ? []
, ...
}@args:
let
@ -29,6 +30,7 @@ in
lib.throwIfNot (excludes == [] || includes == [])
"fetchpatch: cannot use excludes and includes simultaneously"
fetchurl ({
nativeBuildInputs = [ patchutils ] ++ nativeBuildInputs;
postFetch = ''
tmpfile="$TMPDIR/patch"
@ -48,12 +50,12 @@ fetchurl ({
set -e
mv "$tmpfile" "$out"
"${patchutils}/bin/lsdiff" \
lsdiff \
${lib.optionalString (relative != null) "-p1 -i ${lib.escapeShellArg relative}/'*'"} \
"$out" \
| sort -u | sed -e 's/[*?]/\\&/g' \
| xargs -I{} \
"${patchutils}/bin/filterdiff" \
filterdiff \
--include={} \
--strip=${toString stripLen} \
${lib.optionalString (extraPrefix != null) ''
@ -70,7 +72,7 @@ fetchurl ({
exit 1
fi
${patchutils}/bin/filterdiff \
filterdiff \
-p1 \
${builtins.toString (builtins.map (x: "-x ${lib.escapeShellArg x}") excludes)} \
${builtins.toString (builtins.map (x: "-i ${lib.escapeShellArg x}") includes)} \
@ -84,10 +86,10 @@ fetchurl ({
exit 1
fi
'' + lib.optionalString revert ''
${patchutils}/bin/interdiff "$out" /dev/null > "$tmpfile"
interdiff "$out" /dev/null > "$tmpfile"
mv "$tmpfile" "$out"
'' + postFetch;
} // builtins.removeAttrs args [
"relative" "stripLen" "decode" "extraPrefix" "excludes" "includes" "revert"
"postFetch"
"postFetch" "nativeBuildInputs"
])

View File

@ -1073,14 +1073,14 @@ with pkgs;
fetchpatch = callPackage ../build-support/fetchpatch {
# 0.3.4 would change hashes: https://github.com/NixOS/nixpkgs/issues/25154
patchutils = buildPackages.patchutils_0_3_3;
patchutils = __splicedPackages.patchutils_0_3_3;
} // {
tests = pkgs.tests.fetchpatch;
version = 1;
};
fetchpatch2 = callPackage ../build-support/fetchpatch {
patchutils = buildPackages.patchutils_0_4_2;
patchutils = __splicedPackages.patchutils_0_4_2;
} // {
tests = pkgs.tests.fetchpatch2;
version = 2;