chroot: add support for XDG_CONFIG_HOME/pacman/makepkg.conf
Allow users to override makepkg.conf settings by placing a config file in $XDG_CONFIG_HOME/pacman/makepkg.conf. When present, this config will be mounted read-only in the chroot at /etc/makepkg.conf.d/xdg.conf, allowing its settings to take precedence over the base config.
Closes #1283
I tried with this quick and dirty script
#!/bin/sh
set -e
# Test directory setup
TEST_ROOT="/tmp/paru_test"
CHROOT_DIR="$TEST_ROOT/chroot"
XDG_CONFIG_HOME="$TEST_ROOT/config"
export XDG_CONFIG_HOME
# Clean up previous test if exists
rm -rf "$TEST_ROOT"
# Create test directories and configs
mkdir -p "$CHROOT_DIR"
mkdir -p "$XDG_CONFIG_HOME/pacman"
# Create test makepkg.conf with distinctive settings
cat > "$XDG_CONFIG_HOME/pacman/makepkg.conf" <<EOF
PKGEXT='.pkg.tar'
BUILDDIR=/tmp/custom_build
PACKAGER="Test User <[email protected]>"
EOF
# Initialize the chroot with basic packages
echo "Creating chroot environment..."
sudo pacstrap -c "$CHROOT_DIR" base
# Create a basic system makepkg.conf
sudo tee "$CHROOT_DIR/etc/makepkg.conf" > /dev/null <<EOF
PKGEXT='.pkg.tar.zst'
BUILDDIR=/tmp/makepkg
PACKAGER="System <[email protected]>"
EOF
# Copy XDG config to chroot
sudo mkdir -p "$CHROOT_DIR/etc/makepkg.conf.d"
sudo cp "$XDG_CONFIG_HOME/pacman/makepkg.conf" "$CHROOT_DIR/etc/makepkg.conf.d/xdg.conf"
# Test config precedence
echo "=== Testing makepkg.conf settings ==="
sudo chroot "$CHROOT_DIR" /bin/bash <<'CHROOT_SCRIPT'
echo "Base makepkg.conf:"
cat /etc/makepkg.conf
echo -e "\nXDG config makepkg.conf:"
cat /etc/makepkg.conf.d/xdg.conf
echo -e "\nTesting variable precedence:"
. /etc/makepkg.conf
if [ -d /etc/makepkg.conf.d ]; then
for conf in /etc/makepkg.conf.d/*.conf; do
if [ -f "$conf" ]; then
echo "Sourcing $conf"
. "$conf"
fi
done
fi
echo -e "\nFinal values:"
echo "PKGEXT=$PKGEXT"
echo "BUILDDIR=$BUILDDIR"
echo "PACKAGER=$PACKAGER"
CHROOT_SCRIPT
This fails for me with Failed to create mount point /var/lib/aurbuild/x86_64/root/etc/makepkg.conf.d/xdg.conf: Read-only file system
I assume because it also read-only mounts --bind-ro /etc/makepkg.conf.d:/etc/makepkg.conf.d?
Feature is good but I don't think it's implemented right. AFAIK makepkg.conf in home will take priority and if that exists no .d config files will be read.
So I think we should look for ~/.makepkg.conf and $XDG_CONFIG_HOME/pacman/makepkg.conf in that order. If we find either, mount it to /etc/makepkg.conf and leave out the real /etc/makepkg.conf and .d dirs.
Also dirs::config_dir() should be used instead of the env lookup. dirs should also do homedir too I believe.
Oh I just realised the user makepkg.conf extends the system not replaces it. And the .d config files not applying is only when you manually specify --config to makepkg.
So maybe this approach is the best? I'm not sure the priority of the main config file vs .d dropins though.