Stripping options and fetchpatch

I need to apply an upstream patch in the gdb derivation. For this I use the fetchpatch function as follows:

  patches = [ ./debug-info-from-env.patch ];
    ++ stdenv.lib.optional stdenv.isDarwin ./darwin-target-match.patch
    ++ stdenv.lib.optional stdenv.isDarwin (fetchpatch {
        name = "darwin-mojave.patch";
        url = "https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;a=patch;h=fc7b364aba41819a5d74ae0ac69f050af282d057";
        sha256 = "02ipryra2c3xhhkm22bvsni5xsslx0wid8jz90g8g8igc064x29q"; });

The third patch fails to apply because it does not contain the top directory source name (“gdb-8.0”), while the two others do. In principle I could use the patchFlags to set -p1 for the first two and -p0 for the last one, but as far as I understand, it is not possible to set a different flag for each patch.

Is there a way to apply this patch using fetchpatch, or should I create an another patch?

Unfortunately, patchFlags are only global. fetchpatch supports stripLen and extraPrefix arguments for patch normalization, though.

I think it’s also okay to check in this patch. It will just be removed in the next bump of GDB.

I would avoid checked-in patches by any means necessary. They bloat nixpkgs significantly and are often left behind after the patch is removed from patches. Using fetchpatch is much cleaner.

Thanks for the suggestion @jtojnar. The stripLen and extraPrefix options are what I was looking for, so I’m going to mark this question as solved.

It does not solve the specific issue I’m having with the gdb though, because the patch does not apply to the gdb-8.1.1 source tarball. But that’s another story.