Gentoo Custom Patches

May 12, 2026

Sometimes you need a slight tweak to a program's code but cannot justify a pull request or custom ebuild. Enter custom patches. We'll use zfs-auto-snapshot as an example. You can reference the gentoo wiki article as well. Find step find the ebuild file.

ls -1 $(portageq get_repo_path / gentoo)/sys-fs/zfs-auto-snapshot/*.ebuild
/var/db/repos/gentoo/sys-fs/zfs-auto-snapshot/zfs-auto-snapshot-1.2.4-r1.ebuild
/var/db/repos/gentoo/sys-fs/zfs-auto-snapshot/zfs-auto-snapshot-9999.ebuild

As you can see, I have two builds for this application. Pick one path and unpack it.

ebuild /var/db/repos/gentoo/sys-fs/zfs-auto-snapshot/zfs-auto-snapshot-1.2.4-r1.ebuild clean unpack

Next we will enter that directory. I like pushd over cd.

pushd /var/tmp/portage/sys-fs/zfs-auto-snapshot-1.2.4-r1/work/zfs-auto-snapshot-upstream-1.2.4/

ls -1
COPYING
Makefile
README
etc
src

Now we create a new git repository in the working directory folder.

git init
git add .
git commit

Now you can make your changes to the source code. In my case, I want the date to come before label.

nano -w src/zfs-auto-snapshot.sh

Now create the patch.

git diff | tee /tmp/$(date +%F-%H%M).patch

Create the patch directory and move your new patch

mkdir -p /etc/portage/patches/sys-fs/zfs-auto-snapshot/
mv /tmp/*.patch /etc/portage/patches/sys-fs/zfs-auto-snapshot/
popd

Now we are ready to try again.

emerge zfs-auto-snapshot -a -j1
 * User patches applied.

Now you can go test your patch. Congrats!

zfs-auto-snapshot --default-exclude --syslog --label=test --keep=1 tank
@2025-12-28-1619-zfs-auto-snap_test, 1 created, 0 destroyed, 0 warnings.

zfs list -t snap tank
NAME                                        USED  AVAIL  REFER  MOUNTPOINT
tank@2025-12-28-1619-zfs-auto-snap_test       0B      -    96K  -