Compiling on a clean chroot

Full original document in English:

https://wiki.archlinux.org/title/DeveloperWiki:Building_in_a_clean_chroot

The document that starts below, also indicates the changes necessary to include the azul repository to the chroot.

Configuring a chroot

The devtools package provides tools for creating and building within clean chroots. Install it:

sudo pacman -S devtools

To do a clean chroot, create a directory in which the chroot will reside. For example, $HOME/chroot (without sudo):

mkdir ~/chroot

Define the CHROOT variable:

CHROOT=$HOME/chroot

Now create the chroot (the root subdirectory is required because the $CHROOT directory will get other subdirectories for clean working copies. You will be prompted to enter the user's password to run it):

mkarchroot $CHROOT/root base-devel

Note: Set the CHROOT variable to $HOME/.bashrc using the export command if the location is going to be used repeatedly (without root):

nano $HOME/.bashrc

At the end, add:

export CHROOT=$HOME/chroot

Ctrl+o to save, Ctrl+x to exit.

NOTE: On btrfs disks, the chroot is created as a subvolume, so you need to remove it by deleting the subvolume with:

btrfs subvolume delete $CHROOT/root

Edit ~/.makepkg.conf to set the packager name and any makeflags. Also adjust the mirror list in $CHROOT/root/etc/pacman.d/mirrorlist and enable the test repository in $CHROOT/root/etc/pacman.conf, if desired. Let's see the steps:

Add maintainer name:

sudo nano ~/chroot/root/etc/makepkg.conf

Find the line:

#PACKAGER="John Doe <john@doe.com>"

....and aggregate the data.

Now it is possible to add an extra repository. In the case of the blue repository, we can add it to the chroot. (instead of the blue repository, it can be any other). To add it, edit the pacman.conf file:

sudo nano ~/chroot/root/etc/pacman.conf

At the end add:

[azul]
Include = /etc/pacman.d/azul-mirrorlist

NOTE: You can also uncomment the multilib repository.

Copy the mirrors file azul-mirrorlist:

sudo cp /etc/pacman.d/azul-mirrorlist ~/chroot/root/etc/pacman.d/

This is done so that when something is compiled, the existing packages in the azul repository are also used.



Compiling in the chroot

First, make sure the base chroot ($CHROOT/root) is up to date. To do this, run from the terminal and without sudo:

arch-nspawn $CHROOT/root pacman -Syu



Compile a package

Then create a package by running makechrootpkg in the directory containing your PKGBUILD (always inside the chroot folder), as follows (without using sudo):

makechrootpkg -c -r $CHROOT

NOTE: Passing the -c flag to makechrootpkg ensures that the working chroot ($CHROOT/$USER) is cleaned before compiling. Reapplying this operation will create a folder named your username, where a copy of root will reside, and whatever modifications are needed to create the package. Then it will sync with root, to start with a clean condition. (Synchronizing chroot copy: root-> user). Inside user, in the build folder, where a folder with the same name as the one with the PKGBUILD file will reside; there will be the src and the pkg.



Preinstall the necessary packages

To create a package with unavailable dependencies from the enabled repositories in $CHROOT/root/pacman.conf, you can manually add them to the folder where the PKGBUILD is located, and indicate them at build time with -I <package>. See an example:

makechrootpkg -c -r $CHROOT -I build-dependency-1.0-1-x86_64.pkg.tar.xz -I required-package-2.0-2-x86_64.pkg.tar.xz



Passing arguments to makepkg

To pass arguments to makepkg, list them after an end-of-options marker; for example, to force a check():

makechrootpkg -c -r $CHROOT -- --check