When you install new packages via pacman it saves copies of these packages in its cache. Thіs alloweѕ you for example to roll back to an old package since the the official repos only provide the most recent version of a package. This caching has the downside that it can take away a lot of space. This is especially interesting if you are running on an Raspberry Pi like me. Cleaning the cache allowed me to reclaim more than 4GB.

Since I don't really care about the cache I looked for an automated solution. I decided to use a systemd timer to clean the cache daily. Maybe setting the CacheDir of pacman to /dev/null would have also worked.

/etc/systemd/system/paccache.service
[Unit]
Description=Cleans the pacman package cache

[Service]
Type=simple
ExecStart=/usr/bin/paccache --quiet --remove --keep 0

The service is controlled by the following timer:

/etc/systemd/system/paccache.timer
[Unit]
Description=Periodically cleans the pacman package cache

[Timer]
OnCalendar=daily

[Install]
WantedBy=timers.target

After adding those two files remember to reload systemd:

systemctl daemon-reload

The timer can be started and enabled like a normal unit:

systemctl enable --now paccache.timer