~sircmpwn/sr.ht-dev

builds.sr.ht: add Void Linux build image v5 PROPOSED

Derek: 1
 add Void Linux build image

 6 files changed, 184 insertions(+), 0 deletions(-)
#400510 alpine.yml success
#400511 archlinux.yml success
#400512 debian.yml success
> > What is the size of the base install?
> 
> From the docs[1], it looks like it’s 600-700MB. Should I give it 1-2GB
> just to be safe?
No, that's fine.
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~sircmpwn/sr.ht-dev/patches/19663/mbox | git am -3
Learn more about email & git
View this thread in the archives

[PATCH builds.sr.ht v5] add Void Linux build image Export this patch

This commit adds the scripts necessary to build and run Void Linux.
They're based on the official instructions [1] and the Fedora image,
which takes a similar approach.

Void Linux is a rolling release distro, but it allows users to pick
between two C compilers: glibc and musl. Thus, it includes two
"compiler" release directories: `void/musl` and `void/glibc`. Specifying
the `void` parent directory selects `glibc` by default.

I checked several times for typos, but please let me know if I missed
any!

[1]: https://docs.voidlinux.org/installation/guides/chroot.html
---
add one minor fix from the previous patch. Per the installation
instructions, XBPS needs to know the archiecture being installed. For
musl, this is `x86_64-musl`, not `x86_64` as it is for glibc. Thus, when
determining the correct repository, genimg also sets $xbps_arch to the
correct architecture.

 images/void/functions       |  40 +++++++++++
 images/void/genimg          | 136 ++++++++++++++++++++++++++++++++++++
 images/void/glibc/functions |   1 +
 images/void/glibc/genimg    |   3 +
 images/void/musl/functions  |   1 +
 images/void/musl/genimg     |   3 +
 6 files changed, 184 insertions(+)
 create mode 100644 images/void/functions
 create mode 100755 images/void/genimg
 create mode 120000 images/void/glibc/functions
 create mode 100755 images/void/glibc/genimg
 create mode 120000 images/void/musl/functions
 create mode 100755 images/void/musl/genimg

diff --git a/images/void/functions b/images/void/functions
new file mode 100644
index 0000000..d05e63d
--- /dev/null
+++ b/images/void/functions
@@ -0,0 +1,40 @@
#!/bin/sh
poweroff_cmd="sudo poweroff"
default_arch=x86_64

boot() {
  if [ "$arch" != "x86_64" ]
  then
    echo "Unsupported architecture $arch" >&2
    exit 1
  fi

  _boot $(cpu_opts x86_64)
}

install() {
  port=$1
  shift 1
  guest_ssh -p $port build@localhost sudo xbps-install -Syu
  guest_ssh -p $port build@localhost sudo xbps-install -y "$@"
}

sanity_check() {
  echo "Booting..."
  cmd_boot x86_64 8022 qemu &
  trap 'cmd_cleanup 8022' EXIT
  _wait_boot 8022
  echo "Testing sudo..."
  guest_ssh -p 8022 build@localhost sudo ls -a
  echo "Testing xbps..."
  guest_ssh -p $port build@localhost sudo xbps-install -Syu
  install 8022 curl
  echo "Testing networking..."
  guest_ssh -p 8022 build@localhost curl https://example.org
  echo "Testing git..."
  guest_ssh -p 8022 build@localhost git --version
  echo "Testing mercurial..."
  guest_ssh -p 8022 build@localhost hg --version
  echo "Everything works!"
  guest_ssh -p 8022 build@localhost $poweroff_cmd || true
}
diff --git a/images/void/genimg b/images/void/genimg
new file mode 100755
index 0000000..96d1958
--- /dev/null
+++ b/images/void/genimg
@@ -0,0 +1,136 @@
#!/bin/sh -eux
arch=x86_64
NBD_DEVICE=/dev/nbd0
compiler="${compiler:-glibc}"

case $compiler in
  glibc)
    repository=https://alpha.de.repo.voidlinux.org/current
    xbps_arch=x86_64
    ;;
  musl)
    repository=https://alpha.de.repo.voidlinux.org/current/musl
    xbps_arch=x86_64-musl
    ;;
  *)
    echo "unsupported compiler $compiler"
    exit 1
    ;;
esac

cleanup() {
  # Order is important!
  umount -f /mnt/dev 2>/dev/null || true
  umount -f /mnt/proc 2>/dev/null || true
  umount -f /mnt/sys 2>/dev/null || true
  umount -f /mnt 2>/dev/null || true
  qemu-nbd --disconnect $NBD_DEVICE || true
}

run_root() {
  chroot /mnt /usr/bin/env \
    PATH=/sbin:/usr/sbin:/bin:/usr/bin \
    sh -c "$*"
}

mkdir -p "$arch"

qemu-img create -f qcow2 $arch/root.img.qcow2 20G
modprobe nbd
qemu-nbd --connect=$NBD_DEVICE $arch/root.img.qcow2
trap cleanup EXIT

# Wait a second to make sure the NBD device is available
sleep 1

# create partitions: 2GB for swap, everything else for main
sfdisk --no-reread $NBD_DEVICE <<EOF
label: dos
1M,2048M,S
,,L,*
EOF

mkswap ${NBD_DEVICE}p1
mkfs.ext4 ${NBD_DEVICE}p2

mount ${NBD_DEVICE}p2 /mnt

# Install Void Linux
XBPS_ARCH=$xbps_arch xbps-install -Sy -R "$repository" -r /mnt base-system

mount --rbind /sys /mnt/sys && mount --make-rslave /mnt/sys
mount --rbind /dev /mnt/dev && mount --make-rslave /mnt/dev
mount --rbind /proc /mnt/proc && mount --make-rslave /mnt/proc

# configure DNS & networking
echo 'nameserver 1.1.1.1' > /mnt/etc/resolv.conf
cat > /mnt/etc/rc.local <<EOF
ip link set dev eth0 up
ip addr add 10.0.2.15/25 brd + dev eth0
ip route add default via 10.0.2.2
EOF

echo build > /mnt/etc/hostname
cat > /mnt/etc/hosts <<EOF
127.0.0.1 localhost.localdomain localhost
::1 localhost.localdomain localhost
127.0.0.1 build.localdomain build
EOF

# disable DHCP client since we're using a static network config
run_root rm /var/service/dhcpcd

# install necessary packages
run_root xbps-install -Syu
run_root xbps-install -y git mercurial chrony grub
run_root grub-install $NBD_DEVICE

# remove default grub boot timeout
sed -e 's/GRUB_TIMEOUT=5/GRUB_TIMEOUT=0/' -i /mnt/etc/default/grub

# setup `build` user (uid 1000) without a password, and ssh with passwordless login
run_root groupadd wheel
run_root useradd build --gid wheel --uid 1000
run_root passwd -d build

echo '%wheel ALL=(ALL) NOPASSWD: ALL' >> /mnt/etc/sudoers

cat >> /mnt/etc/ssh/sshd_config <<EOF
PasswordAuthentication yes
PermitEmptyPasswords yes
UsePAM no
EOF

run_root ln -s /etc/sv/sshd /var/service

# set locale, timezone; configure git, NTP, fstab, docker
echo 'LANG=en_US.UTF-8' > /mnt/etc/locale.conf

swap_uuid=$(blkid --match-tag UUID --output value ${NBD_DEVICE}p1)
root_uuid=$(blkid --match-tag UUID --output value ${NBD_DEVICE}p2)

cat >> /mnt/etc/fstab <<EOF
UUID=$swap_uuid swap swap defaults                 0 0
UUID=$root_uuid /    ext4 rw,relatime,data=ordered 0 0
EOF

mkdir -p /mnt/etc/docker
cat >/mnt/etc/docker/daemon.json <<EOF
{
	"bip": "172.18.0.1/16"
}
EOF

cat > /mnt/home/build/.gitconfig <<EOF
[user]
  name = builds.sr.ht
  email = builds@sr.ht
EOF
run_root chown build:wheel /home/build/.gitconfig

run_root ln -sf /usr/share/zoneinfo/UTC /etc/localtime
run_root ln -s /etc/sv/chronyd /var/service

# make sure everything's installed and configured correctly
# This will make dracut generate an initramfs and grub generate a working config
run_root xbps-reconfigure -fa
diff --git a/images/void/glibc/functions b/images/void/glibc/functions
new file mode 120000
index 0000000..c0b5bcc
--- /dev/null
+++ b/images/void/glibc/functions
@@ -0,0 +1 @@
../functions
\ No newline at end of file
diff --git a/images/void/glibc/genimg b/images/void/glibc/genimg
new file mode 100755
index 0000000..43c6ba4
--- /dev/null
+++ b/images/void/glibc/genimg
@@ -0,0 +1,3 @@
#!/bin/sh -eux
export compiler=glibc
exec ../genimg
diff --git a/images/void/musl/functions b/images/void/musl/functions
new file mode 120000
index 0000000..c0b5bcc
--- /dev/null
+++ b/images/void/musl/functions
@@ -0,0 +1 @@
../functions
\ No newline at end of file
diff --git a/images/void/musl/genimg b/images/void/musl/genimg
new file mode 100755
index 0000000..2ad61af
--- /dev/null
+++ b/images/void/musl/genimg
@@ -0,0 +1,3 @@
#!/bin/sh -eux
export compiler=musl
exec ../genimg
-- 
2.20.1 (Apple Git-117)
Sorry for the delay in reviewing this, not a high priority right now.
Some feedback:

On Tue Jan 19, 2021 at 1:50 AM EST, Derek wrote: