fetchpatch: add addPrefixes argument

Sometimes patches start without a leading prefix. We default to strip
one prefix or path component from patches (-p1) in the patchPhase in
stdenv.

As all patches should therefore be in this format, fetchpatch should
have an option to normalize patch paths. This commit introduces a new
argument to fetchpatch called addPrefixes that adds one patch prefix to
the old and new paths in a patch before putting it into the store.

+7 -3
+7 -3
pkgs/build-support/fetchpatch/default.nix
··· 4 4 # often change with updating of git or cgit. 5 5 # stripLen acts as the -p parameter when applying a patch. 6 6 7 - { fetchurl, patchutils }: 8 - { stripLen ? 0, ... }@args: 7 + { lib, fetchurl, patchutils }: 8 + { stripLen ? 0, addPrefixes ? false, ... }@args: 9 9 10 10 fetchurl ({ 11 11 postFetch = '' ··· 16 16 "${patchutils}/bin/filterdiff" \ 17 17 --include={} \ 18 18 --strip=${toString stripLen} \ 19 + ${lib.optionalString addPrefixes '' 20 + --addoldprefix=a/ \ 21 + --addnewprefix=b/ \ 22 + ''} \ 19 23 --clean "$out" > "$tmpfile" 20 24 mv "$tmpfile" "$out" 21 25 ${args.postFetch or ""} 22 26 ''; 23 - } // builtins.removeAttrs args ["stripLen"]) 27 + } // builtins.removeAttrs args ["stripLen" "addPrefixes"])