Gentoo has long been known for compiling from source, but that does not mean every package must be built that way. Since late 2023, Gentoo has officially provided a Binary Package Host (binhost), so you can use prebuilt binary packages to speed up installs and updates.

I recently synced a Gentoo mirror for my homelab, and it included Gentoo’s binpkgs. This post covers how to use binpkgs to speed up installs, how to build your own, and how to set up a private binhost server.

Why Use Binary Packages?

After more than ten years on Gentoo, I know the benefits of source builds: fine-grained USE flag control, hardware-specific optimisation, and a completely transparent build. But binary packages help a lot in these situations:

  • Maintaining many similar systems: compile on one machine and let the rest use the binary packages. This is especially useful in a homelab with several identically configured machines.
  • Skipping long builds of large packages: packages like dev-libs/icu, www-client/firefox and dev-qt/qtwebengine can take hours to compile but install in minutes as binaries.
  • Security updates in production: build and test in staging first, then deploy the verified binaries to production quickly and keep downtime minimal.
  • Updating old systems: binary packages need no build-time dependencies, which is a lifesaver on machines with limited resources.
  • Recovery: when the compiler toolchain is broken, prebuilt binaries get the system back quickly.

Binary Package Formats

Gentoo currently supports two binary package formats:

Format File extension Portage version Features
XPAK (old format) .tbz2 Any version Legacy format: tar.bz2 plus xpak metadata
GPKG (new format) .gpkg.tar ≥ 3.0.31 OpenPGP signatures, plain tar extraction, follows GLEP 78

GPKG has been the default since Portage 3.0.31, so make.conf needs no BINPKG_FORMAT. Set BINPKG_FORMAT="xpak" explicitly only to fall back to the old XPAK format.

The GPKG layout is simple: a gpkg-1 marker file, a metadata.tar{.compression} archive, an image.tar{.compression} archive with the installed files, a Manifest checksum file, and optional metadata.tar.sig / image.tar.sig members (inside the container, not separate sidecar files). Because it is a standard tar, you can inspect it with plain tar and no special tools.

Using the Official Binhost

Prerequisites

Binary packages come with hard requirements; the build host and the client must be compatible in these ways:

  • Architecture and CHOST must match: the build host and the client need the same CPU architecture and CHOST.
  • CFLAGS/CXXFLAGS must be compatible: the client CPU must support every instruction set used to build the package.
  • CPU_FLAGS_X86 must be a subset: the client cannot enable CPU-feature USE flags the binary package was not built with.

The official Gentoo binhost uses conservative generic options (-march=x86-64), so most amd64 systems can use it as is.

If you want CPU-specific optimisation, use app-misc/resolve-march-native to find a -march subset that both the build host and the client support. Likewise, app-portage/cpuid2cpuflags helps you find a compatible CPU_FLAGS_X86 set.

Configuring a Binhost

Newer stage3 tarballs ship a binhost config. Older installs and custom setups need it configured by hand.

Edit /etc/portage/binrepos.conf/gentoobinhost.conf (create the directory if it does not exist):

mkdir -p /etc/portage/binrepos.conf

Using the official host:

# /etc/portage/binrepos.conf/gentoobinhost.conf
[gentoo]
priority = 9999
sync-uri = https://distfiles.gentoo.org/releases/amd64/binpackages/23.0/x86-64/
verify-signature = true

Or a mirror in China (recommended, faster):

# /etc/portage/binrepos.conf/gentoobinhost.conf — Tsinghua mirror
[gentoo]
priority = 9999
sync-uri = https://mirrors.tuna.tsinghua.edu.cn/gentoo/releases/amd64/binpackages/23.0/x86-64/
verify-signature = true
# /etc/portage/binrepos.conf/gentoobinhost.conf — Aliyun mirror
[gentoo]
priority = 9999
sync-uri = https://mirrors.aliyun.com/gentoo/releases/amd64/binpackages/23.0/x86-64/
verify-signature = true

Parameter notes:

  • priority: higher numbers win. When a package exists on several binhosts, Portage pulls it from the highest-priority one.
  • sync-uri: the directory holding the binhost’s Packages index. The URL ends with the architecture and install type.
  • verify-signature: per-repository signature verification, added in Portage 3.0.74; it defaults to true since 3.0.77, so only older versions need it spelled out.

The 23.0/x86-64 part of sync-uri matches your profile. On the 23.0/x86-64-v3 profile (AVX2 and newer instruction sets), the path becomes 23.0/x86-64-v3 as well.

The official binhost only ships x86-64 (baseline) and x86-64-v3, no v2/v4. Directories for hardened, musl, llvm, x32 and similar profiles only contain the packages that come with stage3.

Enabling Binary Packages

Enable the getbinpkg feature in /etc/portage/make.conf so Portage fetches binaries from the binhost automatically:

FEATURES="getbinpkg"

When no matching binary exists, Portage falls back to a source build, so normal use is unaffected.

FEATURES="getbinpkg" makes it the global default; for occasional use, just add -g on the command line instead of writing it into make.conf. Pick one, not both.

GPG Signature Verification

Official binhost packages are signed with Gentoo Release Engineering keys. The first time emerge downloads a binary it calls getuto automatically and creates a keyring in /etc/portage/gnupg, so usually there is nothing to do by hand.

If the keyring is missing or broken, follow the steps in the FAQ at the end; the normal flow does not require running getuto manually.

Since the official news post in May 2026, downloaded binhost packages are verified by default (verify-signature, on by default since Portage 3.0.77), and official binhost users do not need binpkg-request-signature. You only need it when you want signature verification for locally built buildpkg packages too: it makes Portage reject any package without a valid signature, including ones just built here, so the build host must also enable binpkg-signing:

# /etc/portage/make.conf
FEATURES="getbinpkg binpkg-request-signature"

Gotcha: if /etc/portage/gnupg already exists (for example from older portage tree verification), getuto will not overwrite it, which can leave a bad configuration. Back up the old directory and reinitialise:

mv /etc/portage/gnupg /etc/portage/gnupg.bak
getuto

Trying It Out

Once configured, you can start using binary packages.

Install a single package from a binary:

emerge -avg app-editors/nano

Update the whole system from binaries:

emerge -avuDUg @world

Common binpkg-related emerge options:

Option Short Description
--getbinpkg -g Download binaries from the binhost; use them when they match, otherwise build from source
--getbinpkgonly -G Only use binhost binaries; fail if missing (no source fallback)
--usepkg -k Prefer local binaries in /var/cache/binpkgs; do not fetch from the binhost
--usepkgonly -K Only use local binaries; never build from source

Note: without --getbinpkg, Portage will not look on the binhost even if you pass --usepkgonly.

Put common options in EMERGE_DEFAULT_OPTS so you do not pass them every time:

# /etc/portage/make.conf
EMERGE_DEFAULT_OPTS="${EMERGE_DEFAULT_OPTS} --getbinpkg"

Excluding Specific Packages

Some packages are a poor fit for binaries (kernel sources, virtual packages and so on); exclude them with --usepkg-exclude:

emerge -avuDUg @world --usepkg-exclude "sys-kernel/gentoo-sources virtual/* sys-kernel/gentoo-kernel"

The same can go into EMERGE_DEFAULT_OPTS:

# /etc/portage/make.conf
EMERGE_DEFAULT_OPTS="${EMERGE_DEFAULT_OPTS} --usepkg-exclude 'sys-kernel/gentoo-sources virtual/*'"

When USE Flags Do Not Match

Portage checks whether a binary’s USE flags match the local configuration. On a mismatch it ignores the binary and builds from source by default.

To see which USE flags a package’s binary was built with:

emerge --pretend --getbinpkg --usepkgonly --binpkg-respect-use=n <package>

If you do not care about USE differences (testing, say), --binpkg-respect-use=n forces the binary despite them. The official docs warn that this can break the system, so use it for troubleshooting only and never leave it in EMERGE_DEFAULT_OPTS.

Building Your Own Binary Packages

Building your own binaries is the foundation of a private binhost. Portage offers three ways to do it.

Option 1: The –buildpkg Flag

Generate a binary while emerging a package:

# Install the package and create a binary at the same time
emerge --ask --buildpkg sys-devel/gcc

# Create the binary without installing it (build-time dependencies must already be present)
emerge --ask --buildpkgonly sys-devel/gcc

Option 2: Automatic Builds via FEATURES

The most common approach is enabling the buildpkg feature in /etc/portage/make.conf, after which every emerge creates a binary automatically:

# /etc/portage/make.conf
FEATURES="buildpkg"

buildsyspkg is the more conservative option and only builds binaries for packages in the @system set.

If some packages should not produce binaries (kernel sources, or packages that are already binary upstream such as firefox-bin), exclude them:

emerge -uDN @world --buildpkg --buildpkg-exclude "acct-*/* sys-kernel/*-sources virtual/* */*-bin"

Option 3: quickpkg

quickpkg packs an already installed package into a binary without recompiling:

# Create binaries for every installed GCC version
quickpkg sys-devel/gcc

# Create binaries for every package in the @system set
quickpkg @system

# Create binaries for every installed package
quickpkg "*/*"

quickpkg leaves out config files protected by CONFIG_PROTECT by default. Use --include-config or --include-unmodified-config to include them.

Every method writes binaries to the directory in PKGDIR, which defaults to /var/cache/binpkgs.

Compression

BINPKG_COMPRESS selects the compression format and defaults to zstd, so you need not set it. Supported formats are bzip2, gzip, lz4, lzip, lzop, xz and zstd; set it only to change, e.g. BINPKG_COMPRESS="lz4".

Each format needs its matching tool installed; lz4, for example, needs app-arch/lz4. zstd balances ratio and speed well, so the default is recommended.

OpenPGP Signing

For binaries distributed between machines, GPG signing is strongly recommended.

Configure signing on the build host:

# /etc/portage/make.conf
FEATURES="buildpkg binpkg-signing"
BINPKG_GPG_SIGNING_GPG_HOME="/root/.gnupg"
BINPKG_GPG_SIGNING_KEY="0xYOURKEYFINGERPRINT"

Parameter notes:

  • binpkg-signing enables binary package signing
  • BINPKG_GPG_SIGNING_GPG_HOME is the GPG home used for signing, default /root/.gnupg
  • BINPKG_GPG_SIGNING_KEY is the fingerprint of the signing key

Portage only unlocks the GPG private key at startup. If the key may expire, enable gpg-keepalive to avoid signing failures:

FEATURES="buildpkg binpkg-signing gpg-keepalive"

The script below quickly builds a Portage GPG keyring on a client to set up trust:

#!/bin/bash
 
KEY_NAME="sa-slchris.asc"
LOCAL_KEYSERVER="http://keyserver.internal:9001"
KEY="5BB4DC20DCA50A499219935036F2D646E2E89820" # your signing key fingerprint

GPG_DIR="/etc/portage/gnupg"

PASS="$(openssl rand -base64 32)"

KEY_CONFIG_FILE="$(mktemp)"
chmod 600 "${KEY_CONFIG_FILE}"

export GNUPGHOME="${GPG_DIR}"
cat > "${KEY_CONFIG_FILE}" <<EOF
     %echo Generating Portage local OpenPGP trust key
     Key-Type: default
     Subkey-Type: default
     Name-Real: Portage Local Trust Key
     Name-Comment: local signing only
     Name-Email: portage@localhost
     Expire-Date: 0
     Passphrase: ${PASS}
     %commit
     %echo done
EOF

mkdir -p "${GNUPGHOME}"
gpg --batch --generate-key "${KEY_CONFIG_FILE}"
rm -f "${KEY_CONFIG_FILE}"

touch "${GNUPGHOME}/pass"
chmod 600 "${GNUPGHOME}/pass"
echo "${PASS}" > "${GNUPGHOME}/pass"

# Import your signing public key
curl  $LOCAL_KEYSERVER/$KEY_NAME | gpg --import - 
# Sign your public key with the local trust key
gpg --batch --yes --pinentry-mode loopback --passphrase "${PASS}" --sign-key "${KEY}" 
# Set the trust level to ultimate (5)
echo -e "5\ny\n" | gpg --command-fd 0 --edit-key "${KEY}" trust

chmod ugo+r "${GNUPGHOME}/trustdb.gpg"

The script does three things:

  1. Generates a local Portage trust key, used to sign and trust other keys
  2. Downloads your signing public key from the internal keyserver
  3. Signs your public key with the local trust key and sets it to full trust

You can also do this by hand. The key steps: getuto to initialise the keyring, gpg --homedir=/etc/portage/gnupg --import public.key to import the key, then gpg --homedir=/etc/portage/gnupg --edit-key KEYID and enter sign, yes, the trust key’s passphrase, trust, 4, save. Finish with gpg --homedir=/etc/portage/gnupg --check-trustdb to update the trust database.

Running a Binhost Server

Portage can download binaries over FTP, FTPS, HTTP, HTTPS and SSH/SFTP. Here are the common ways to host them.

Web Server

The most common approach, suitable for both internal and public distribution.

Nginx

Serve /var/cache/binpkgs over HTTP with Nginx:

# /etc/nginx/conf.d/binhost.conf
server {
    listen 80;
    server_name binhost.example.com;

    root /var/cache/binpkgs;

    # Enable directory listing for easier browsing
    autoindex on;
    autoindex_exact_size off;
    autoindex_localtime on;

    # Support large file transfers
    sendfile on;
    tcp_nopush on;
    tcp_nodelay on;

    location / {
        try_files $uri $uri/ =404;
    }
}

Client configuration:

# /etc/portage/binrepos.conf/mybinhost.conf
[mybinhost]
priority = 1
sync-uri = http://binhost.example.com/
verify-signature = true

Caddy

If you prefer Caddy’s minimal config:

# Caddyfile
binhost.example.com:80 {
    root * /var/cache/binpkgs
    file_server browse
}

Python http.server (temporary)

For a quick one-off, Python’s built-in HTTP server works:

cd /var/cache/binpkgs
python -m http.server 8000

This is for temporary testing only, not production.

SSH

A good fit when security matters: SSH key authentication with no extra web server.

  1. Add the client’s root public key on the binhost server:
cat root.id_rsa.pub >> /home/binpkguser/.ssh/authorized_keys
  1. Client configuration:
# /etc/portage/binrepos.conf/ssh.conf
[ssh]
priority = 1
sync-uri = ssh://binpkguser@binhostserver/var/cache/binpkgs
verify-signature = true

With SSH, the root SSH key must not have a passphrase, because package installation runs unattended in the background. If the SSH server uses a non-standard port, append it to the address: ssh://binpkguser@binhostserver:2222/var/cache/binpkgs.

NFS

On an internal network, sharing the binary directory over NFS is the simplest option:

Server exports:

# /etc/exports
/var/cache/binpkgs 192.168.100.0/24(ro,no_subtree_check,root_squash)

Client fstab entry:

# /etc/fstab
binhost:/var/cache/binpkgs /opt/nfs-binpkgs nfs defaults 0 0

Once mounted, point PKGDIR at the mount and use --usepkg (-k) to read the local directory; no binrepos.conf is needed:

# /etc/portage/make.conf
PKGDIR="/opt/nfs-binpkgs"
# Use binaries from the NFS mount; fall back to a source build when missing
emerge -k -uDN @world

This is the NFS/SSHFS binhost pattern from the official docs. --usepkgonly (-K) requires the binary to exist. If the mount is read-only, do not enable buildpkg on the client, because it cannot write there.

S3 / Object Storage

If your homelab runs MinIO or you use AWS S3, sync the binaries to object storage with s3cmd or rclone and serve them through an HTTP(S) gateway.

Example upload script:

#!/bin/bash
# sync-binpkgs-to-s3.sh
# Sync local binary packages to S3-compatible storage

BUCKET="my-binpkgs"
PKGDIR="/var/cache/binpkgs"

# Sync with rclone (configure the remote first)
rclone sync "${PKGDIR}/" "minio:${BUCKET}/" \
    --transfers=8 \
    --checkers=16 \
    --fast-list \
    --delete-during \
    -v

echo "Sync completed at $(date)"

GitHub/Gitea

For a small number of packages (say, those built from a personal overlay), a Git repository can store and distribute them:

# Initialise the repository
cd /var/cache/binpkgs
git init
git checkout -b x86_64-pc-linux-gnu

# Add and commit
git add .
git commit -m "binpkgs: $(date +%Y-%m-%d) update"

# Push to the remote
git remote add origin [email protected]:yourname/binpkgs.git
git push --set-upstream origin x86_64-pc-linux-gnu

Note: Git is a poor fit for many or large binary files. With more packages, use Git LFS or one of the other options above. This approach suits small sets: a few dozen custom-built or overlay packages.

Clients cannot put a git URL in sync-uri. Clone the repository locally and point at that directory:

# /etc/portage/binrepos.conf/git.conf
[git-binhost]
priority = 1
sync-uri = file:///var/cache/binhost/git
verify-signature = true

You can also publish that directory with any static HTTP server and use its URL as sync-uri.

Maintaining Binary Packages

Cleaning Up Stale Packages

Old package versions pile up over time. Use eclean (from app-portage/gentoolkit) to remove binaries that no longer match any ebuild:

eclean-pkg   # Same as eclean packages

Recent Portage versions store downloaded binhost packages in /var/cache/binhost/<repo>, separate from /var/cache/binpkgs where buildpkg writes; eclean-pkg cleans both.

You can also use qpkg from app-portage/portage-utils to clean unused binaries:

qpkg -c

Maintaining the Packages Index

/var/cache/binpkgs contains a Packages index, a cache of metadata for all binaries. Portage and eclean maintain it automatically in normal operation.

If manual operations (deleting or copying binary files directly) leave the index inconsistent, rebuild it with emaint:

emaint binhost --fix

To wipe the entire binary package cache:

rm -r /var/cache/binpkgs/*

Merging Binaries from Multiple Nodes

A homelab may have several build nodes, each responsible for different packages (one for desktop packages, another for server packages), and their binaries eventually need to be merged onto one binhost for distribution.

The Basic Idea

The idea is simple: merge the /var/cache/binpkgs directories from each node into one, then rebuild the Packages index. Binpkg paths follow category/package/package-version-build_id.gpkg.tar, so different packages never collide.

graph LR
    subgraph Build nodes
        A["build-node-1<br/>/var/cache/binpkgs"] 
        B["build-node-2<br/>/var/cache/binpkgs"]
        C["build-node-3<br/>/var/cache/binpkgs"]
    end
    subgraph Central binhost
        D["Central PKGDIR<br/>/var/cache/binpkgs"]
        E["emaint binhost --fix<br/>rebuild Packages index"]
        F["Web/SSH/NFS<br/>distribution service"]
    end
    A -->|rsync| D
    B -->|rsync| D
    C -->|rsync| D
    D --> E --> F

Merging with rsync

The most direct method is pulling binaries from each build node to the central binhost with rsync:

#!/bin/bash
# merge-binpkgs.sh
# Merge binary packages from multiple build nodes into the central binhost

CENTRAL_PKGDIR="/var/cache/binpkgs"
LOG="/var/log/binpkg-merge.log"

# Build node list
BUILD_NODES=(
    "root@build-node-1"
    "root@build-node-2"
    "root@build-node-3"
)

echo "=== Binpkg merge started at $(date) ===" >> "${LOG}"

for node in "${BUILD_NODES[@]}"; do
    echo "Syncing from ${node}..." >> "${LOG}"
    rsync -avz --ignore-existing \
        "${node}:/var/cache/binpkgs/" \
        "${CENTRAL_PKGDIR}/" \
        >> "${LOG}" 2>&1
done

# Rebuild the index
emaint binhost --fix >> "${LOG}" 2>&1

echo "=== Binpkg merge finished at $(date) ===" >> "${LOG}"

Parameter notes:

  • --ignore-existing keeps an existing package with the same name and version on the central binhost. Useful when several nodes may build the same package.
  • -avz archive mode with compressed transfer, preserving permissions and timestamps.

If you want the newest build to always overwrite the old one, replace --ignore-existing with --update (overwrite only when the source is newer).

Handling Version Conflicts

When several nodes build the same version of the same package, they may differ in:

  • USE flags: node A builds dev-libs/openssl with USE="-bindist", node B with USE="bindist"
  • CFLAGS: node A uses -march=x86-64-v3, node B uses -march=x86-64

Since Portage 3.0.15, binpkg-multi-instance is on by default and the filename includes a build_id, so different builds of the same package coexist. Portage picks the right one by matching USE flags.

To avoid confusion, keep one make.conf configuration across build nodes (at least identical CFLAGS, CXXFLAGS and CPU_FLAGS_X86), enforced with Ansible or another configuration management tool.

A More Complete Merge Script

A more practical merge script with selective merging and conflict detection:

#!/bin/bash
# advanced-merge-binpkgs.sh

CENTRAL_PKGDIR="/var/cache/binpkgs"
LOG="/var/log/binpkg-merge.log"
LOCK_FILE="/var/lock/binpkg-merge.lock"

# Prevent concurrent runs
exec 200>"${LOCK_FILE}"
flock -n 200 || { echo "Another merge is running, exiting."; exit 1; }

# Build node config: node address + package categories it handles
declare -A NODE_CATEGORIES
NODE_CATEGORIES[
    "root@build-desktop"]="x11-*/ kde-*/ gnome-*/ media-*/ www-client/"
NODE_CATEGORIES[
    "root@build-server"]="sys-*/ net-*/ app-containers/ dev-db/"

log() {
    echo "[$(date '+%Y-%m-%d %H:%M:%S')] $1" >> "${LOG}"
}

log "=== Merge started ==="

for node in "${!NODE_CATEGORIES[@]}"; do
    categories="${NODE_CATEGORIES[$node]}"
    log "Syncing from ${node} (categories: ${categories})"
    
    # Sync selected categories
    for cat in ${categories}; do
        rsync -avz --update \
            "${node}:/var/cache/binpkgs/${cat}" \
            "${CENTRAL_PKGDIR}/" \
            >> "${LOG}" 2>&1
    done
done

# Rebuild the Packages index
log "Rebuilding Packages index..."
emaint binhost --fix >> "${LOG}" 2>&1

# Stats
PKG_COUNT=$(find "${CENTRAL_PKGDIR}" -name '*.gpkg.tar' | wc -l)
DIR_SIZE=$(du -sh "${CENTRAL_PKGDIR}" | awk '{print $1}')
log "=== Merge finished: ${PKG_COUNT} packages, total size: ${DIR_SIZE} ==="

Merging and GPG Signatures

If build nodes sign with different GPG keys, every client’s /etc/portage/gnupg must trust all of those keys.

A cleaner approach is to skip signing on the nodes and re-sign everything on the central binhost after merging. The gpkg-sign tool signs existing GPKG packages:

# Sign only unsigned packages, skip the rest
find /var/cache/binpkgs -name '*.gpkg.tar' \
  | xargs -n 1 -P "$(nproc)" gpkg-sign --skip-signed --allow-unsigned

# Rebuild the index after signing
emaint binhost --fix

gpkg-sign needs Portage’s BINPKG_GPG_SIGNING_GPG_HOME and BINPKG_GPG_SIGNING_KEY configured correctly. Clients then only need to trust the central binhost’s single key.

Distributed Builds with distcc

Binary packages leave one question open: can builds that must happen from source (because you changed USE flags or use a non-standard -march) be sped up? The answer is distcc, a distributed compiler.

distcc spreads compilation across several machines in parallel. Combined with binpkg the strategy is: use binaries where you can, and accelerate the rest with a distcc cluster. That works very well in a homelab with several machines.

Prerequisites

distcc has a few hard requirements:

  • Identical GCC versions on every node: mismatches cause compile errors or runtime crashes. Check with gcc --version.
  • Identical binutils versions: check with eselect binutils list. Mismatches cause link failures.
  • No -march=native: distcc dispatches jobs to different machines, and -march=native selects instructions for whatever CPU runs the job, producing incompatible code across CPUs. Use an explicit -march value such as -march=x86-64 or -march=znver3.

Use app-misc/resolve-march-native to see which flags -march=native expands to on your CPU, then pick a subset compatible with every machine in the cluster.

Installing distcc

Install distcc on every machine that takes part in builds:

emerge -av sys-devel/distcc

For the graphical monitor, enable the gui USE flag: echo 'sys-devel/distcc gui' >> /etc/portage/package.use/distcc.

Configuring the distccd Daemon

Configure and start distccd on every build node, including the machine that starts the build.

On systemd, add a drop-in that sets the allowed client IPs:

mkdir -p /etc/systemd/system/distccd.service.d
# /etc/systemd/system/distccd.service.d/00gentoo.conf
[Service]
Environment="ALLOWED_SERVERS=192.168.100.0/24"

For multiple subnets or finer control:

Environment="ALLOWED_SERVERS=192.168.100.0/24 --allow 10.0.0.0/8 --log-level error"

Enable and start the service:

systemctl daemon-reload
systemctl enable --now distccd

Configuring the Build Initiator

On the machine that starts builds, set the distcc host list:

# Hosts taking part in distributed builds
# Format: IP[/max jobs]
/usr/bin/distcc-config --set-hosts "localhost/4 192.168.100.11/8 192.168.100.12/8"

Parameter notes:

  • localhost/4: the local machine takes part with up to 4 concurrent jobs. Lower it or remove it if the machine is weak.
  • 192.168.100.11/8: a remote node with up to 8 concurrent jobs. Adjust to its CPU core count.
  • Without /N the default is 4

Pump mode speeds things up further by caching preprocessed headers on the server and cutting repeated transfers. Append the ,cpp,lzo suffix to each host:

/usr/bin/distcc-config --set-hosts "localhost/4,cpp,lzo 192.168.100.11/8,cpp,lzo"

Pointing Portage at distcc

Edit /etc/portage/make.conf, enable the distcc feature and tune MAKEOPTS:

# /etc/portage/make.conf

# Enable distcc (it does not conflict with binpkg; use both)
FEATURES="distcc buildpkg getbinpkg"

# MAKEOPTS formula:
# -jN : N = 2 × (local cores + total remote cores) + 1
# -lM : M = local CPU cores (prevents local overload)
#
# Example: 4 local cores + 2 remote × 8 cores = 20 cores total
# N = 2 × 20 + 1 = 41, M = 4
MAKEOPTS="-j41 -l4"

# Important: never use -march=native!
COMMON_FLAGS="-march=x86-64-v3 -O2 -pipe"
CFLAGS="${COMMON_FLAGS}"
CXXFLAGS="${COMMON_FLAGS}"

-lM matters: when some remote nodes are unavailable it caps the local load, so queued jobs do not pile onto the local machine and drag it down.

Disabling distcc for Some Packages

Some packages are a poor fit for distcc (Rust packages cause excessive local I/O, for example) and need their own config:

# /etc/portage/env/nodistcc.conf
MAKEOPTS="-j5"
FEATURES="-distcc"
# /etc/portage/package.env/nodistcc
dev-lang/rust nodistcc.conf
www-client/firefox nodistcc.conf
mail-client/thunderbird nodistcc.conf
sys-libs/libcxx nodistcc.conf

Combining with ccache

distcc and ccache work well together for two layers of speedup: ccache caches previous compilation results locally, and distcc sends cache misses to remote nodes. Remote nodes can run ccache too, so their results get cached as well.

The workflow:

flowchart TD
    A["Client starts a build"] --> B{"Local ccache<br/>hit?"}
    B -->|hit| C["Use the cache<br/>no network"]
    B -->|miss| D["distcc dispatches to a remote node"]
    D --> E{"Remote ccache<br/>hit?"}
    E -->|hit| F["Return the remote cache result"]
    E -->|miss| G["Compile remotely and cache"]
    G --> H["Return the result to the client"]
    F --> H
    
    style C fill:#2d8659,color:#fff
    style F fill:#2d8659,color:#fff
    style G fill:#c9841e,color:#fff

Configuration:

# /etc/portage/make.conf
FEATURES="distcc ccache buildpkg getbinpkg"
CCACHE_DIR="/var/cache/ccache"

Make ccache intercept builds on the remote distccd as well:

# /etc/systemd/system/distccd.service.d/00gentoo.conf
[Service]
Environment="ALLOWED_SERVERS=192.168.100.0/24"
Environment="CCACHE_DIR=/var/cache/ccache"
Environment="DISTCC_DIR=/var/tmp/portage/.distcc"

Also change distccd’s ExecStart so the compiler is called through the ccache path:

systemctl edit --full distccd.service

Set ExecStart to:

ExecStart=/bin/bash -c "PATH=/usr/lib/ccache/bin:$PATH exec /usr/bin/distccd --no-detach --daemon --port 3632 -N 15 --allow $ALLOWED_SERVERS"

Make sure /var/cache/ccache on remote nodes has the right ownership:

chown -R distcc:portage /var/cache/ccache

Monitoring Distributed Builds

distcc ships monitoring tools that show how jobs are distributed in real time:

# Text mode (refresh every 5 seconds)
DISTCC_DIR="/var/tmp/portage/.distcc/" distccmon-text 5

# Graphical mode (needs the gui USE flag)
DISTCC_DIR="/var/tmp/portage/.distcc/" distccmon-gnome

The Full distcc + binpkg Workflow

With distcc and binpkg combined, the whole build and distribution workflow looks like this:

flowchart TD
    A["emerge installs or updates a package"] --> B{"Matching binary<br/>on the binhost?"}
    B -->|yes| C["Download the binary<br/>and install"]
    B -->|no| D["Build from source"]
    D --> E["distcc spreads jobs<br/>across the cluster"]
    E --> F["Local and remote nodes<br/>compile in parallel"]
    F --> G["Build finished"]
    G --> H["buildpkg creates<br/>a binary"]
    H --> I["binpkg-signing<br/>GPG signature"]
    I --> J["Sync to the central binhost"]
    J --> K["Other nodes can use<br/>the binary next time"]
    C --> L["Installed"]
    K --> L

    style C fill:#2d8659,color:#fff
    style L fill:#2d8659,color:#fff
    style E fill:#2b7ab5,color:#fff
    style F fill:#2b7ab5,color:#fff

A complete make.conf for the build host:

# /etc/portage/make.conf — distcc + binpkg build host

# Compiler flags (never -march=native!)
COMMON_FLAGS="-march=x86-64-v3 -O2 -pipe"
CFLAGS="${COMMON_FLAGS}"
CXXFLAGS="${COMMON_FLAGS}"

# Enable all the speedups together
FEATURES="distcc ccache buildpkg binpkg-signing gpg-keepalive getbinpkg"

# MAKEOPTS: based on total cluster cores
# 8 local cores + 2 remote × 16 cores = 40 cores
# N = 2 × 40 + 1 = 81, M = 8
MAKEOPTS="-j81 -l8"

# ccache
CCACHE_DIR="/var/cache/ccache"

# Binary packages
BINPKG_GPG_SIGNING_GPG_HOME="/root/.gnupg"
BINPKG_GPG_SIGNING_KEY="0xYOURKEYFINGERPRINT"

# Exclude packages unsuitable for distcc and things that need no binary
EMERGE_DEFAULT_OPTS="${EMERGE_DEFAULT_OPTS} --usepkg-exclude 'sys-kernel/gentoo-sources virtual/*'"

Tip: start with a conservative -jN (1.5× total cores, say), watch distccmon-text and node load, then raise it gradually. Too much concurrency can actually slow things down through network and I/O overhead.

Automated Builds and Distribution

In a homelab, dedicate one build host to compiling and distributing binaries automatically.

Build Host make.conf

# /etc/portage/make.conf — build host

# Compiler optimisation (adjust for your CPU)
COMMON_FLAGS="-march=x86-64 -mtune=generic -O2 -pipe"
CFLAGS="${COMMON_FLAGS}"
CXXFLAGS="${COMMON_FLAGS}"

# Create binaries for every installed package
FEATURES="buildpkg binpkg-signing gpg-keepalive"

# GPG signing
BINPKG_GPG_SIGNING_GPG_HOME="/root/.gnupg"
BINPKG_GPG_SIGNING_KEY="0xYOURKEYFINGERPRINT"

# Compression format

Set the build host’s -march to the lowest instruction set every client supports. If all machines in your homelab are recent CPUs, x86-64-v3 (AVX2) gives better performance.

Scheduled Update Script

Create a cron script that updates the system and refreshes the binaries:

#!/bin/bash
# /root/scripts/binhost-update.sh

LOG="/var/log/binhost-update.log"

echo "=== Binhost update started at $(date) ===" >> "${LOG}"

# Sync the portage tree
emaint sync --auto >> "${LOG}" 2>&1

# Update the system (binaries are created automatically)
emerge -uDN @world --with-bdeps=y --keep-going >> "${LOG}" 2>&1

# Clean up stale binaries
eclean packages >> "${LOG}" 2>&1

# Rebuild the index
emaint binhost --fix >> "${LOG}" 2>&1

# Optional: clean up stale distfiles
eclean distfiles >> "${LOG}" 2>&1

echo "=== Binhost update finished at $(date) ===" >> "${LOG}"

Schedule it with cron:

# crontab -e
# Run the update at 03:00 every day
0 3 * * * /root/scripts/binhost-update.sh

Complete Client Configuration

A complete client configuration that uses both a private binhost and the official Gentoo binhost:

# /etc/portage/make.conf

# Signature verification is on by default; no binpkg-request-signature needed
FEATURES="getbinpkg"

# Exclude kernel and virtual packages from binaries
EMERGE_DEFAULT_OPTS="${EMERGE_DEFAULT_OPTS} --usepkg-exclude 'sys-kernel/gentoo-sources virtual/*'"
# /etc/portage/binrepos.conf/private.conf — private binhost (preferred)
[private]
priority = 10000
sync-uri = https://binhost.homelab.local/
verify-signature = true
# /etc/portage/binrepos.conf/gentoo.conf — official binhost (fallback)
[gentoo]
priority = 9999
sync-uri = https://mirrors.tuna.tsinghua.edu.cn/gentoo/releases/amd64/binpackages/23.0/x86-64/
verify-signature = true

With several binhosts, Portage searches them from highest priority down. Give the private binhost a higher number so your own signed builds win, and fall back to the official host when it has nothing.

Note: since Portage 3.0.77 downloaded binpkgs are verified by default. Downloads from an unsigned private binhost will fail: either sign it as described above, or set verify-signature to false for that one repo.

Notes for Scaling Up

For a handful of machines in a homelab, the setup above is enough. At dozens of machines, only three things really need extra work: consistent versions, offline control, and rollback.

Pinning the Portage Tree

Do not rely on “whatever was synced today” as an implicit version. The Gentoo tree is a Git repository, so pin the commit:

git clone https://github.com/gentoo-mirror/gentoo.git /var/db/repos/gentoo
git -C /var/db/repos/gentoo checkout <commit>

The official mirror has no date tags and git tag -l 'gentoo-*' returns nothing, so pinning a commit hash is the direct route. If you want a readable version, tag your own internal mirror, e.g. corp-20261112.

Then turn off automatic syncing in /etc/portage/repos.conf/gentoo.conf:

[gentoo]
location = /var/db/repos/gentoo
auto-sync = no
sync-type = git
sync-uri = https://github.com/gentoo-mirror/gentoo.git

All nodes use the same commit, and a tree upgrade is treated as one change: validate in staging, then push to production.

Pre-fetching distfiles

In offline or egress-restricted environments, pull the source archives locally first:

# Fetch only what @world needs right now
emerge --fetchonly -uDN @world --with-bdeps=y

# Or mirror the whole repository
emirrordist --mirror --distfiles /srv/distfiles --repo gentoo \
    --jobs 8 --delete --deletion-delay 2592000

Point clients’ GENTOO_MIRRORS at the internal mirror; for fully offline sites, copy the distfiles in on a USB stick.

Staged Rollout and Rollback

Update tree → compile/verify in staging → watch canary nodes for 24h → full rollout
  • Build packages in staging with emerge -uDN @world --buildpkg --keep-going, verify, then sync to the binhost.
  • In the canary phase, update 1-2 nodes first and watch systemctl is-system-running and key services.
  • There are three rollback paths: revert the tree to the previous commit, install the retained old binpkgs with emerge -avK @world, or use zfs rollback if you run ZFS.
  • Check security updates with glsa-check --test all and apply them with glsa-check --fix all, both in cron.

Start simple: pinned tree + binhost + a nightly build. Add canaries and approvals once it runs reliably.

FAQ

Q: Why does Portage still build from source?

The usual cause is a USE flag mismatch. When the binhost binary’s USE flags differ from your local config, Portage falls back to a source build. Check the difference with:

emerge --pretend --getbinpkg --usepkgonly --binpkg-respect-use=n <package>

Q: How do I know whether a package has a binary?

Open the binhost URL in a browser and look in the matching category directory for the package you need.

Q: keyblock resource: '/etc/portage/gnupg/pubring.kbx': No such file or directory

The keyring in /etc/portage/gnupg/ must exist first. If the directory is missing, run getuto. If it exists but is broken, back it up and regenerate:

mv /etc/portage/gnupg /etc/portage/gnupg.bak
getuto

References