How to apply User patches in portage

After years of tinkering with gentoo and feeding my custom overlay I discovered today the "user patches" feature of portage.

This is really awesome !

The Use Case :
You want to just try out a patch for something already in portage.

Instead of creating another ebuild in an overlay you can put your patch in :

For example :
mkdir -p /etc/portage/patches/sys-libs/glibc-2.13-r3/
wget -O /etc/portage/patches/sys-libs/glibc-2.13-r3/fix1.patch "https://bugs.gentoo.org/attachment.cgi?id=279269"
emerge -1 glibc

To check if your patch applied you should see the following just after the standard batch of patches:
 * Applying user patches from /etc/portage/patches/sys-libs/glibc-2.13-r3 ...
 *   fix1.patch ...                                                                                 [ ok ]
 * Done with patching


  1. I don't think this works always, because I tried this method for a package yesterday and emerge didn't apply it.

    This thread- http://forums.gentoo.org/viewtopic-t-867029-start-0.html says patches in /etc/portage/patches are applied only if the ebuild calls epatch_user or the eclass calls it. :|

    Now I guess I'll have to create a new overlay for myself to have custom packages.

  2. Ha indeed, all the ebuild are not capable of this :( Thanks for reporting that !

  3. With bit of effort all the patches magic like PATCHES array and epatch_user could be part of EAPI=6.

    So if you want you can start spec-ing it up.

    On that note the epatch_user is called by most eclasses (base/kde/gnome/...)

    1. I would love too, I dig this feature ! I gonna ask the PMS guys where I could help there.