From 1c287c65c05b8a497dd7a5483a7018919be9917b Mon Sep 17 00:00:00 2001 From: Morgan Jones Date: Thu, 9 Oct 2025 00:50:10 -0700 Subject: [PATCH] fetchpatch: support `hunks` option We can pick individual hunks or ranges of hunks with filterdiff, so expose that in fetchpatch. This was originally useful for openssh, since the first hunks always look like this (that is, only differing in the date): ``` @@ -1,4 +1,4 @@ -/* $OpenBSD: ssh.c,v 1.616 2025/08/29 03:50:38 djm Exp $ */ +/* $OpenBSD: ssh.c,v 1.617 2025/09/04 00:29:09 djm Exp $ */ /* * Author: Tatu Ylonen * Copyright (c) 1995 Tatu Ylonen , Espoo, Finland ``` The usage looks something like this to skip the first hunk in the patch. Numbers work too, if you'd like to only pick out specific hunks. ``` fetchpatch { name = "my-patch"; url = "..."; hunks = [ "2-" ]; hash = "..."; } ``` (cherry picked from commit 77e773dbc6c45c0678d1c5c588a071a30add51bf) --- pkgs/build-support/fetchpatch/default.nix | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/pkgs/build-support/fetchpatch/default.nix b/pkgs/build-support/fetchpatch/default.nix index 0e7be1717107..9f384e732846 100644 --- a/pkgs/build-support/fetchpatch/default.nix +++ b/pkgs/build-support/fetchpatch/default.nix @@ -17,6 +17,7 @@ extraPrefix ? null, excludes ? [ ], includes ? [ ], + hunks ? [ ], revert ? false, postFetch ? "", nativeBuildInputs ? [ ], @@ -88,8 +89,12 @@ lib.throwIfNot (excludes == [ ] || includes == [ ]) filterdiff \ -p1 \ - ${builtins.toString (builtins.map (x: "-x ${lib.escapeShellArg x}") excludes)} \ - ${builtins.toString (builtins.map (x: "-i ${lib.escapeShellArg x}") includes)} \ + ${toString (map (x: "-x ${lib.escapeShellArg x}") excludes)} \ + ${toString (map (x: "-i ${lib.escapeShellArg x}") includes)} \ + ${ + lib.optionalString (hunks != [ ]) + "-# ${lib.escapeShellArg (lib.concatMapStringsSep "," toString hunks)}" + } \ "$tmpfile" > "$out" if [ ! -s "$out" ]; then @@ -113,6 +118,7 @@ lib.throwIfNot (excludes == [ ] || includes == [ ]) "extraPrefix" "excludes" "includes" + "hunks" "revert" "postFetch" "nativeBuildInputs"