Two of my machines run Arch Linux: my laptop and my main desktop. The desktop is a dual-boot system, with one SSD for Arch Linux and a second one for FreeBSD 16-CURRENT.
My home server is an Aoostar WTR Max running TrueNAS. Its data pool is a five-disk RAIDZ2, and the apps live on a separate mirror of two NVMe SSDs. Since late October the NAS also caches packages for the other machines: it keeps a copy of every package one of them has requested and serves later requests from the LAN.
The setup consists of two small containers on TrueNAS: pacoloco for pacman, and nginx with proxy_cache for FreeBSD’s pkg. This post documents both, including the client configuration and troubleshooting.

Reasoning
A caching proxy stores only what the clients ask for. After four weeks the Arch cache holds 2.7 GB and the FreeBSD cache 18 GB. A full mirror needs many times that space and a regular rsync run, and most of it would never be installed here.
The cache does not weaken package verification. pacman still checks package signatures against its keyring, and pkg still verifies the signed repository catalogue and the checksum of every package. The NAS only stores files that upstream has already signed, so plain HTTP inside the LAN is sufficient.
Arch Linux: pacoloco
pacoloco is a caching proxy written for pacman repositories. It knows that database files change and package files do not, and it can refresh the packages it has already cached before a client asks for the new version.
The configuration file:
cache_dir: /var/cache/pacolocoport: 9129download_timeout: 3600purge_files_after: 2592000 # drop files nobody fetched for 30 daysrepos: archlinux: urls: # list two or three mirrors close to you first - https://geo.mirror.pkgbuild.com bioarchlinux: urls: - https://repo.bioarchlinux.orgprefetch: cron: 0 0 4 * * * * # refresh cached packages nightly at 04:00 ttl_unaccessed_in_days: 30 ttl_unupdated_in_days: 200
Each repository takes a list of upstream mirrors, which pacoloco tries in order. The prefetch job runs at 04:00 and downloads new versions of packages that are already in the cache, so a morning pacman -Syu is usually served entirely from the NAS.
On TrueNAS the container runs as a custom app with this compose definition. The paths under /mnt/tank/apps are examples and stand for a dataset on your own pool:
services: pacoloco: image: ghcr.io/anatol/pacoloco:1.9 restart: unless-stopped ports: - "9129:9129" volumes: - /mnt/tank/apps/pacoloco/pacoloco.yaml:/etc/pacoloco.yaml:ro - /mnt/tank/apps/pacoloco/cache:/var/cache/pacoloco
The image runs as UID and GID 65532. The cache directory must belong to that user, otherwise every download fails with “permission denied”:
chown -R 65532:65532 /mnt/tank/apps/pacoloco/cache
Client configuration
In /etc/pacman.conf the NAS is listed first in every repository, ahead of the regular mirrorlist. nas.lan stands for the hostname or IP address of the NAS:
[core]Server = http://nas.lan:9129/repo/archlinux/$repo/os/$archInclude = /etc/pacman.d/mirrorlist[extra]Server = http://nas.lan:9129/repo/archlinux/$repo/os/$archInclude = /etc/pacman.d/mirrorlist[bioarchlinux]Server = http://nas.lan:9129/repo/bioarchlinux/$arch
I put the line into pacman.conf and not into the mirrorlist for two reasons. A mirror ranking script rewrites the mirrorlist and would remove it. And with the Include line still in place, pacman falls back to the public mirrors when the NAS is unreachable, which matters for a laptop that leaves the house.
pacman -Sp linux prints the URL pacman would use and is a quick way to confirm that requests go to port 9129.
FreeBSD: nginx as a caching proxy
I am not aware of a pacoloco equivalent for pkg, but one is not needed. A FreeBSD package repository is a tree of static files, and package files are never rewritten under the same name. nginx can cache that with a short configuration:
proxy_cache_path /var/cache/nginx/pkg levels=1:2 keys_zone=pkg:50m max_size=150g inactive=60d use_temp_path=off;server { listen 80; server_name _; proxy_cache pkg; proxy_cache_lock on; proxy_cache_use_stale error timeout updating http_502 http_503 http_504; proxy_ssl_server_name on; proxy_set_header Host pkg.freebsd.org; proxy_http_version 1.1; # pkg.freebsd.org sends no-cache on everything; packages are still signed # and verified by pkg, so caching them here is safe. proxy_ignore_headers Cache-Control Expires Set-Cookie; proxy_hide_header X-Cache; proxy_hide_header X-Cache-Hits; add_header X-Pkgcache $upstream_cache_status always; # Catalogues change with every repo build: keep them only briefly. location ~ (/Latest/|/(meta\.conf|meta\.(txz|tzst)|packagesite\.[a-z]+|data\.[a-z]+|filesite\.[a-z]+|digests\.[a-z]+)$) { proxy_cache_valid 200 10m; proxy_pass https://pkg.freebsd.org; } # Package files are never rewritten under the same name. location / { proxy_cache_valid 200 60d; proxy_cache_valid 404 1m; proxy_pass https://pkg.freebsd.org; }}
Three details deserve an explanation.
The upstream forbids caching. pkg.freebsd.org answers with Cache-Control: private, no-cache. Without proxy_ignore_headers nginx obeys that header and stores nothing, and the proxy appears to work while every request is a miss.
Catalogues and packages need different lifetimes. The catalogue files (meta.conf, packagesite, data) are replaced by every repository build. They are cached for ten minutes, long enough for several machines to update in a row and short enough that nobody works with an old catalogue. Everything else is kept for 60 days.
proxy_cache_lock avoids duplicate downloads. When two machines request the same uncached file at the same moment, only one request goes upstream and the other waits for the result.
The X-Pkgcache header reports what the cache did with a request:
$ curl -sI http://nas.lan:9130/FreeBSD:16:amd64/latest/meta.conf | grep -i pkgcacheX-Pkgcache: HIT
Client configuration
The override goes into /usr/local/etc/pkg/repos/FreeBSD.conf. It only replaces the URL. The signature settings are inherited from /etc/pkg/FreeBSD.conf.
FreeBSD-ports: { url: "http://nas.lan:9130/${ABI}/latest", mirror_type: "none"}FreeBSD-ports-kmods: { url: "http://nas.lan:9130/${ABI}/kmods_latest", mirror_type: "none"}FreeBSD-base: { url: "http://nas.lan:9130/${ABI}/base_latest", mirror_type: "none"}
The repository names and paths must match the ones in /etc/pkg/FreeBSD.conf of the system in question. The ones above are from a 16-CURRENT machine with pkgbase. A release names its kmods and base paths differently, and older systems have a single repository called FreeBSD. mirror_type has to be "none" because the stock configuration sets it to srv, and an SRV lookup cannot work for the NAS.
After the change, pkg update -f fetches all catalogues through the cache.
Prefetching for pkg
nginx has no notion of package versions, so I added a small sidecar container to the same app. It runs a Python script from cron at 04:30. The script reads the cache keys of the stored files to learn which packages the clients use, looks up the current version of each one in packagesite, and requests the new files through the proxy. It never deletes anything; expiry stays with nginx.
services: pkgcache: image: nginx:1.30.6-alpine restart: unless-stopped ports: - "9130:80" volumes: - /mnt/tank/apps/pkgcache/pkgcache.conf:/etc/nginx/conf.d/default.conf:ro - /mnt/tank/apps/pkgcache/cache:/var/cache/nginx/pkg prefetch: image: alpine:3.22 restart: unless-stopped depends_on: - pkgcache environment: TZ: Etc/UTC # set your own time zone command: >- sh -c "apk add --no-cache python3 tar zstd tzdata >/dev/null && echo '30 4 * * * python3 /pkg-prefetch.py >> /log/pkg-prefetch.log 2>&1' > /etc/crontabs/root && exec crond -f -l 8" volumes: - /mnt/tank/apps/pkgcache/pkg-prefetch.py:/pkg-prefetch.py:ro - /mnt/tank/apps/pkgcache/cache:/cache:ro - /mnt/tank/apps/pkgcache/log:/log
The sidecar exists because the TrueNAS host has no zstd, which is needed to unpack the catalogue.
Results
The first pkg upgrade through the cache covered 51 packages and 839 MiB, including a new kernel. A later request for the same kernel package was answered with X-Pkgcache: HIT.
The difference is largest when the upstream is slow. On one evening in November, pkg.freebsd.org delivered a test file at 1.8 MB/s, while the same file came from the cache at 111 MB/s. That was a single measurement of a 10 MB file and not a benchmark, but it describes the experience well: a miss is as slow as the upstream happens to be, and a hit is as fast as the LAN.
Notes
- The cache directories do not need a backup. Their content can be downloaded again at any time.
- The two caches are independent. Either one can be removed without affecting the other, and removing the
Serverline or the override file returns a client to the public mirrors. - A cache serves only what it has seen. A machine with an unusual package set gains little on its first update and more on every later one.





