First guide : how to build your first package with Qubes Builder v2
This guide will help you to build your first packages with Qubes Builder v2.
Context
Three years ago I used Qubes Builder v1 regularly for building ArchLinux/Fedora/Debian packages.
Then Qubes Builder v2 replaced it, and I tried using it four or five times by following the qubes-builderv2 README. And each time it failed with errors I couldn’t solve without a very large investment.
Last week, the need to use the Qubes Builder v2 becomes more important for me while trying to solve a Gentoo template issue. Then I found the Qubes Builder v2 dev guide (qubes-builder-v2) which is much simpler for a first usage. By following this guide I found some minor inaccuracies, so I write two simple scripts to automate the building of the required qubes. My main goal was to re-create easily this environment.
What we will do?
We will :
- create a template (tpl-f42-builder) with the required dependencies.
- create an app qube (qbuilder) used to build the packages from the source (git clone)
- build two first
core-admin-clientpackages for dom0
Create the tpl-f42-builder template
Rewrite or copy the create_builder_template.sh script to dom0:
#! /bin/bash
# create $VM as the qubes-builder template
# qubes-builderv2, based on Augsch123's salt recipe (8774 issue)
set -o errexit
set -o nounset
TPL=fedora-42-xfce
VM=tpl-f42-builder-$(date +"%N")
qvm-clone $TPL $VM
# dependencies-fedora.txt
qvm-run --pass-io --no-gui $VM 'sudo dnf -y install asciidoc createrepo_c devscripts docker gpg m4 mock openssl pacman podman python3-click python3-docker python3-jinja2-cli python3-lxml python3-packaging python3-pathspec python3-podman python3-pyyaml rb_libtorrent-examples reprepro rpm rpm-sign rsync sequoia-chameleon-gnupg sequoia-sq sequoia-sqv tree'
# dependencies-fedora-qubes-executor.txt
qvm-run --pass-io --no-gui $VM 'sudo dnf -y install createrepo_c debootstrap devscripts dnf-plugins-core dpkg-dev git mock pbuilder perl-Digest-MD5 perl-Digest-SHA pykickstart python3-debian python3-pyyaml python3-sh reprepro rpm-build rpmdevtools systemd-udev wget which'
# Init docker env
qvm-run --pass-io --no-gui $VM 'sudo usermod -aG docker user'
qvm-shutdown --wait $VM
qvm-run --pass-io --no-gui $VM 'docker ps'
echo $VM created
qvm-shutdown $VM
echo $VM stopped
Steps:
- replace the
TPLvariable value with your reference fedora template - execute the script
- rename the
tpl-f42-builder-xxxxxxtemplate totpl-f42-builder
Create the qbuilder app qube
Rewrite or copy the create_builder_qube.sh script to dom0:
#! /bin/bash
# create $VM as a builderv2 qube
# qbuilder v2, based on www.qubes-os.org/doc/qubes-builder-v2/
set -o errexit
set -o nounset
VM=qbuilder-$(date +"%N")
TPL=tpl-f42-builder
qvm-create $VM --class=AppVM --label=red --template=$TPL --prop=memory=600 --prop=maxmem=6000
qvm-volume resize $VM:private 60GB
# persistent docker directory
qvm-run --pass-io --no-gui $VM 'sudo mkdir /rw/config/qubes-bind-dirs.d; echo "binds=( '/var/lib/docker' )" | sudo tee /rw/config/qubes-bind-dirs.d/docker.conf'
qvm-shutdown --wait $VM
sleep 2
qvm-start $VM
# qubes-builderv2 repo
qvm-run --pass-io --no-gui $VM 'cd /home/user ; git clone https://github.com/QubesOS/qubes-builderv2'
qvm-run --pass-io --no-gui $VM 'cd /home/user/qubes-builderv2 ; git submodule update --init'
# verify docker with an example
qvm-run --pass-io --no-gui $VM 'docker run hello-world'
qvm-shutdown --wait $VM
sleep 2
qvm-start $VM
# validate /var/lib/docker persistence
qvm-run --pass-io --no-gui $VM 'docker images'
echo $VM created
Steps:
- execute the script
- rename the
qbuilder-xxxxxxxapp qube toqbuilder
Build a package
For the next, follow the qubes-builder-v2 guide:
- Open a terminal in
qbuilder, then
cd qubes-builderv2/
tools/generate-container-image.sh docker
tools/generate-container-image.sh dockerwill create a qubes-builder-fedora docker image. This is your Qubes builder executor (fetch, build the packages). Thedocker imagescommand should list it.- Create the
builder.ymlconfiguration file, from the Configuration section of qubes-builder-v2. This YAML file configures the above qubes-builder-fedora docker as an executor - Build your first packages
./qb -c core-admin-client -d host-fc37 package fetch prep build
Your built packages for dom0 (host-fc37) are :
[user@qbuilder qubes-builderv2]$ ls -lh artifacts/components/core-admin-client/4.2.17-1.1/host-fc37/build/rpm/*.noarch.rpm
-rw-rw-r--. 2 user user 631K Jul 22 22:38 artifacts/components/core-admin-client/4.2.17-1.1/host-fc37/build/rpm/python3-qubesadmin-4.2.17-1.1.fc37.noarch.rpm
-rw-rw-r--. 2 user user 72K Jul 22 22:38 artifacts/components/core-admin-client/4.2.17-1.1/host-fc37/build/rpm/qubes-core-admin-client-4.2.17-1.1.fc37.noarch.rpm
What’s next ?
Now you will be able to build the Qubes OS packages/templates/iso, so you can more easily test contributor PRs, fix Qubes OS issues or test your new features, then do Pull Requests to the official git repositories.
Resources :
- Read the 8774 issue with the Augsch123’s Salt formulas
- Read the qubes-builderv2 README
- Read the recipe examples in the QubesOS git repositories (
.qubesbuilder, CI.gitlab-ci.yml) - Read the qb documentation
- Try the other executors (disposable, podman, local, windows, …)