Disclaimer

The purpose of this guide is to help AUR users compile complex packages using an AUR helper such as yay in a clean environment and help to keep primary user facing systems free of clutter.

It is wise to read the Arch Wiki on building in a clean chroot. If this method does not work, or immolates the computer, follow the instructions on the wiki page to properly build the package in a clean chroot.

Building the Package

Firstly, install devtools on the primary machine.

you@primary $ sudo pacman -S devtools

Set an environment variable for the package to be installed.

you@primary $ export PKG=librewolf

Make the directory in which the new chroot will be created.

you@primary $ mkdir -p $HOME/aur/chroot/$PKG/

Define the CHROOT environment variable to minimize typing in subsequent steps.

you@primary $ export CHROOT=$HOME/aur/chroot/$PKG

mkarchroot will create the root directory in the librewolf directory.

root@primary # mkarchroot $CHROOT/root base base-devel vi vim nano sudo wget

Use arch-nspawn to switch the shell into chroot.

you@primary $ arch-nspawn $CHROOT/root su -

Set a root passwd.

root@chroot # passwd

Edit /etc/makepkg.conf to compile on all cores.

root@chroot # awk -v cpu="$(nproc)" -v makeflags="#MAKEFLAGS=\"-j2\"" '{sub(makeflags,sprintf("MAKEFLAGS=\"-j%s\"", cpu))} 1' /etc/makepkg.conf >> /etc/makepkg.conf.tmp && mv /etc/makepkg.conf.tmp /etc/makepkg.conf

Edit /etc/pacman.conf to enable multilib. It's not needed for librewolf, however this command can come in handy for any AUR package which requires 32-bit libraries.

root@chroot # awk '$0=="#[multilib]"{c=2} c&&c--{sub(/#/,"")} 1' /etc/pacman.conf >> /etc/pacman.conf.tmp && mv /etc/pacman.conf.tmp /etc/pacman.conf

Ensure the chroot is up to date.

root@chroot # pacman -Syyu

Create a user to build aur packages in the wheel group

root@chroot # useradd -m -G wheel aur

Set the aur user's password.

root@chroot # passwd aur

Use visudo command to grant wheel users the ability to sudo. You can learn to use vi and vim here and it's quite fun.

root@chroot # visudo

Alternatively nano can be used as well.

root@chroot # EDITOR=nano visudo

Switch to the new aur user.

root@chroot # su - aur

Create the build directory for the package.

aur@chroot $ mkdir build && cd build

Copy the snapshot link for yay from the aur and wget the link

aur@chroot $ wget https://aur.archlinux.org/cgit/aur.git/snapshot/yay.tar.gz

Extract the yay.tar.gz archive and make the yay package.

aur@chroot $ tar xf yay.tar.gz && cd yay && makepkg -si

Use yay to build librewolf.

aur@chroot $ yay -S librewolf

Once this process is completed, exit the terminal.

librewolf can now be installed from the $CHROOT/root/home/aur/.cache/yay/librewolf/ directory on the primary computer with pacman -U.

root@primary # pacman -U $CHROOT/root/home/aur/.cache/yay/librewolf/librewolf-135.0.1-1-x86_64.pkg.tar.zst