As pointed out by Earnestly and demonicmaniac3 over at #archlinux irc channel, this is because pacman
won't re-download anything if it's already locally installed. But it will download whatever it is you're specifically instructing it to, which make a whole lot of sense come to think of it.
This means if you're trying to download packages intended for a custom/local repo, you need to either make sure the packages you're about to download is not installed locally or do one of these options:
Use a empty package database temporarly/locally
pacman -y --dbpath /tmp ...
This will create the illusion that nothing is installed locally and every single package needed is downloaded. This also requires you to do -y
since there's no master package-list in your made up database.
Perform a system upgrade
pacman -Syuw ...
This should re-install/upgrade any package may it be installed or not already.
Note: Not verified (I know too little about pacman's logic and am in a time pickle to test it)
Isolating downloaded files
As pointed out in the comments, you most likely want to place the downloaded files in a separate directory so you can use them, this is done with --cachedir
:
pacman --cachedir /tmp/somewhere ...
Final example
sudo pacman -Syw --cachedir /tmp/somewhere --dbpath /tmp/pacmandb base base-devel linux linux-firmware
And then you most likely want to add it to a mirror using repo-add by issuing something like:
repo-add /tmp/somewhere/my_mirror.db.tar.gz /tmp/somewhere/{*.pkg.tar.xz,*.pkg.tar.zst}
Generate a dependency-list using expac
expac -S '%E' -l '\n' base base-devel linux linux-firmware | tr '\n' ' '
Calling expac
on the <package string>
(all the packages you are about to download) would give you a list of packages needed to run whatever it is you're downloading. You could use this list to fetch/add to your already existing string of packages scheduled for installation.
expac
separates each individual dependency in a one-liner by default but splits them up between packages, so we convert each one-liner string into multiple new lines, and then use tr to convert newlines to spaces.
I prefer the expac
version since it holds up programmatically and would be useable in many scripts, but the quick and "dirty" version is to simply redirect the database which pacman checks.