Skip to content

Instantly share code, notes, and snippets.

@michaelbeaumont
Last active May 24, 2024 13:25
Show Gist options
  • Save michaelbeaumont/1b2b58d63ccdc446496f0156d6aca4ad to your computer and use it in GitHub Desktop.
Save michaelbeaumont/1b2b58d63ccdc446496f0156d6aca4ad to your computer and use it in GitHub Desktop.
Using mkosi and AUR to install packages
#!/usr/bin/env bash
set -ex
PACKAGES=(
neovim-git
)
# All this is basically to get around makepkg calling pacman with sudo
# Otherwise we could just call `aur sync` and be done with it
cd /tmp
pacman_deps=$(aur depends ${PACKAGES[@]} --json --all | jq -r '.[] | select(.ID == null) | .Name')
pacman -S --needed --noconfirm ${pacman_deps[@]}
# We install needed deps in topological order using tsort
aur_deps=$(aur depends ${PACKAGES[@]} -r | tsort)
aur fetch ${aur_deps[@]}
for pkg in ${aur_deps[@]}; do
pushd ${pkg}
sudo -u nobody BUILDDIR="/tmp/build" SRCDEST="/tmp/build" aur build --no-sync
pacinstall --dbsync --no-confirm --yolo ${pkg}
popd
done
# Move what we actually need into the image
cp -r --no-preserve=ownership /aur ${DESTDIR}
cp --parents /etc/pacman.d/aur.conf ${DESTDIR}
reflector --latest 5 --sort rate --save ${DESTDIR}/etc/pacman.d/mirrorlist
#!/usr/bin/env bash
set -ex
# Setup pacman to read modular configs
mkdir -p /etc/pacman.d
echo > /etc/pacman.d/dummy.conf "# This exists just so /etc/pacman.d is never empty and we can Include = /etc/pacman.d/*.conf"
echo -e "\nInclude = /etc/pacman.d/*.conf" >> /etc/pacman.conf
# Configure pacman
pacman-key --init
pacman-key --populate
# Install the aur packages we just built
pacman -Sy
pacinstall --dbsync \
--no-confirm \
--yolo \
$(pacman -Sql aur)
#!/usr/bin/env bash
set -e
if [[ "${1}" != "build" ]]; then
exit 0
fi
# Setup pacman
reflector --latest 5 --sort rate --save /etc/pacman.d/mirrorlist
pacman-key --init
pacman-key --populate
cd /tmp
# Manually build and install aurutils
sudo -u nobody git clone https://aur.archlinux.org/aurutils.git
pushd aurutils
(
source ./PKGBUILD
pacman -S \
--needed \
--noconfirm \
"${makedepends[@]}" "${depends[@]}" "${checkdepends[@]}"
)
sudo -u nobody PKGDEST="/tmp" PKGEXT=".pkg.tar" makepkg --clean --cleanbuild
popd
pacman -U --noconfirm /tmp/aurutils-*.pkg.tar
# Add local repo reference
echo > /etc/pacman.d/aur.conf "
[aur]
SigLevel = Optional TrustAll
Server = file:///aur"
echo -e "\nInclude = /etc/pacman.d/*.conf" >> /etc/pacman.conf
# Create empty repository
# All the arch tooling assumes we can use sudo when we can't here
# so we own this repo as -u nobody and call pacman explicitly
install -d /aur -o nobody
sudo -u nobody tar -ca -f /aur/aur.db.tar.xz -T /dev/null
sudo -u nobody ln -s /aur/aur.db.tar.xz /aur/aur.db
pacman -Sy
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment