/etc/portage/patches

User patches provides users with an integrated method of applying site-specific patches. This is often preferable to forking the ebuild in a local overlay, since the latter will require ongoing maintenance to keep up with the Gentoo tree.

To apply user patches to an ebuild that supports them, save the patch in (for example . Note that the patch file's name must end with in  . A few other folders will also be checked for user patches, see the snippet from  below for full details.

User patches is not a feature provided by the package manager directly, but is implemented by calling the  function (from ) in many individual ebuilds, often through eclass-defined   functions. This has the advantage of letting the maintainer of a package determine the most appropriate place for applying user patches, for example prior to calling. Current Gentoo policy does not require ebuilds to use, its usage is at the package maintainer's discretion.

Different ebuilds and eclasses have their own conventions, for example, calls   after applying other patches in the eclass'. can be called multiple times without causing issues, it creates a file and exits early if this file already exists.

Calling with a hook in Portage's bashrc
If an ebuild does not call, and you still wish to apply user patches; this can be accomplished using bashrc hooks provided by Portage, provided the ebuild inherits.

Typically, one might use the  or   hooks. However, the latter is run after the ebuild's  phase, which causes issues if for example   should be run after patches are applied.

There's an ugly trick to also make it work with ebuilds that don't inherit eutils.

It would be much nicer if this feature was included into portage.