Create a service that downloads the latest versions without installling them. Needs a service and a timer service.

The Code:

sudo nano /usr/local/bin/arch-bg-download.sh

#!/usr/bin/env bash
# Script to pre-download official repo and AUR updates in the background.

# 1. Update package databases and pre-download official repository packages
echo "Pre-downloading official repository updates..."
pacman -Sywq --noconfirm

# 2. Pre-download AUR updates if yay is installed (Runs as regular user context, not root)
if command -v yay &> /dev/null; then
    echo "Pre-downloading AUR updates..."
    # Find the primary human user to execute yay safely without root permissions
    REAL_USER=$(loginctl list-users --no-legend | awk '{print $2}' | grep -v 'root' | head -n 1)
    if [ -not -z "$REAL_USER" ]; then
        sudo -u "$REAL_USER" yay -Syua --downloadonly --noconfirm
    fi
fi

echo "Background download finished successfully."

sudo chmod +x /usr/local/bin/arch-bg-download.sh

The service:

sudo nano /etc/systemd/system/arch-bg-download.service

[Unit]
Description=Pre-download official and AUR updates in the background
After=network-online.target
Wants=network-online.target

[Service]
Type=oneshot
ExecStart=/usr/local/bin/arch-bg-download.sh

[Install]
WantedBy=multi-user.target

The timer:

sudo nano /etc/systemd/system/arch-bg-download.timer

[Unit]
Description=Run the background update downloader periodically

[Timer]
OnBootSec=10min
OnUnitActiveSec=6h
Persistent=true

[Install]
WantedBy=timers.target

Make it persistent:

sudo systemctl daemon-reload
sudo systemctl enable –now arch-bg-download.timer