Add Guix step including bootstrap bin, build guix, build iso and fix some small bug

This commit is contained in:
vxtls 2026-02-28 19:19:18 -05:00
parent fb146bbf97
commit 3178f1f9e0
36 changed files with 890 additions and 7 deletions

View file

@ -2,4 +2,21 @@
#
# SPDX-License-Identifier: GPL-3.0-or-later
exec /steps/improve/after.sh
set -e
. /steps/bootstrap.cfg
. /steps/env
if [ "${INTERACTIVE}" = True ]; then
env - PATH=${PREFIX}/bin PS1="\w # " setsid openvt -fec1 -- bash -i
fi
if [ "${CHROOT}" = False ]; then
# Ignore errors due to missing swap/fstab.
swapoff -a >/dev/null 2>&1 || true
sync
echo u > /proc/sysrq-trigger
mount -o remount,ro /
echo o > /proc/sysrq-trigger
while true; do sleep 1; done
fi

View file

@ -0,0 +1,76 @@
#!/bin/sh
# SPDX-License-Identifier: GPL-3.0-or-later
set -e
dist="${DISTFILES:-/external/distfiles}"
env_out="/tmp/guix-bootstrap-seeds.env"
required_files="
${dist}/static-binaries-0-i686-linux.tar.xz
${dist}/guile-static-stripped-2.2.4-i686-linux.tar.xz
${dist}/mes-minimal-stripped-0.19-i686-linux.tar.xz
${dist}/mescc-tools-static-stripped-0.5.2-i686-linux.tar.xz
${dist}/bootstrap-exec-bash-i686-linux
${dist}/bootstrap-exec-mkdir-i686-linux
${dist}/bootstrap-exec-tar-i686-linux
${dist}/bootstrap-exec-xz-i686-linux
"
for f in ${required_files}; do
if [ ! -e "${f}" ]; then
echo "Missing required seed artifact: ${f}" >&2
exit 1
fi
done
if [ ! -x /usr/bin/guix-hash-compat ]; then
echo "Missing /usr/bin/guix-hash-compat" >&2
exit 1
fi
# Prepare file layout expected by bootstrap.scm for i686/x86_64.
mkdir -p "${dist}/i686-linux" "${dist}/x86_64-linux"
cp -f "${dist}/static-binaries-0-i686-linux.tar.xz" \
"${dist}/i686-linux/static-binaries-0-i686-linux.tar.xz"
cp -f "${dist}/static-binaries-0-i686-linux.tar.xz" \
"${dist}/x86_64-linux/static-binaries-0-i686-linux.tar.xz"
cp -f "${dist}/guile-static-stripped-2.2.4-i686-linux.tar.xz" \
"${dist}/i686-linux/guile-static-stripped-2.2.4-i686-linux.tar.xz"
cp -f "${dist}/guile-static-stripped-2.2.4-i686-linux.tar.xz" \
"${dist}/x86_64-linux/guile-static-stripped-2.2.4-i686-linux.tar.xz"
cp -f "${dist}/bootstrap-exec-bash-i686-linux" \
"${dist}/i686-linux/bootstrap-exec-bash-i686-linux"
cp -f "${dist}/bootstrap-exec-mkdir-i686-linux" \
"${dist}/i686-linux/bootstrap-exec-mkdir-i686-linux"
cp -f "${dist}/bootstrap-exec-tar-i686-linux" \
"${dist}/i686-linux/bootstrap-exec-tar-i686-linux"
cp -f "${dist}/bootstrap-exec-xz-i686-linux" \
"${dist}/i686-linux/bootstrap-exec-xz-i686-linux"
static_binaries_hash="$(/usr/bin/guix-hash-compat "${dist}/static-binaries-0-i686-linux.tar.xz")"
guile_seed_hash="$(/usr/bin/guix-hash-compat "${dist}/guile-static-stripped-2.2.4-i686-linux.tar.xz")"
mes_minimal_hash="$(/usr/bin/guix-hash-compat "${dist}/mes-minimal-stripped-0.19-i686-linux.tar.xz")"
mescc_tools_hash="$(/usr/bin/guix-hash-compat "${dist}/mescc-tools-static-stripped-0.5.2-i686-linux.tar.xz")"
exec_bash_hash="$(/usr/bin/guix-hash-compat -r "${dist}/bootstrap-exec-bash-i686-linux")"
exec_mkdir_hash="$(/usr/bin/guix-hash-compat -r "${dist}/bootstrap-exec-mkdir-i686-linux")"
exec_tar_hash="$(/usr/bin/guix-hash-compat -r "${dist}/bootstrap-exec-tar-i686-linux")"
exec_xz_hash="$(/usr/bin/guix-hash-compat -r "${dist}/bootstrap-exec-xz-i686-linux")"
cat > "${env_out}" <<ENVEOF
DISTFILES=${dist}
STATIC_BINARIES_SEED_FILE=static-binaries-0-i686-linux.tar.xz
STATIC_BINARIES_SEED_HASH=${static_binaries_hash}
GUILE_SEED_FILE=guile-static-stripped-2.2.4-i686-linux.tar.xz
GUILE_SEED_HASH=${guile_seed_hash}
MES_MINIMAL_SEED_FILE=mes-minimal-stripped-0.19-i686-linux.tar.xz
MES_MINIMAL_SEED_HASH=${mes_minimal_hash}
MESCC_TOOLS_SEED_FILE=mescc-tools-static-stripped-0.5.2-i686-linux.tar.xz
MESCC_TOOLS_SEED_HASH=${mescc_tools_hash}
EXEC_BASH_HASH=${exec_bash_hash}
EXEC_MKDIR_HASH=${exec_mkdir_hash}
EXEC_TAR_HASH=${exec_tar_hash}
EXEC_XZ_HASH=${exec_xz_hash}
ENVEOF
chmod 0644 "${env_out}"

View file

@ -0,0 +1,31 @@
#!/bin/sh
# SPDX-License-Identifier: GPL-3.0-or-later
set -e
. /steps/bootstrap.cfg
. /steps/env
daemon_socket="/var/guix/daemon-socket/socket"
out_dir="/external/guix-images"
if [ ! -S "${daemon_socket}" ]; then
echo "guix-daemon socket is missing: ${daemon_socket}" >&2
echo "Run improve/guix-daemon-and-pull.sh first." >&2
exit 1
fi
mkdir -p "${out_dir}"
iso_store_path="$(guix system image \
--system=x86_64-linux \
-t iso9660 \
-e '(@@ (gnu system install) installation-os)' \
--no-substitutes)"
if [ ! -e "${iso_store_path}" ]; then
echo "guix system image did not return a valid path: ${iso_store_path}" >&2
exit 1
fi
ln -sfn "${iso_store_path}" "${out_dir}/guix-system-install-x86_64.iso"

View file

@ -0,0 +1,144 @@
#!/bin/sh
# SPDX-License-Identifier: GPL-3.0-or-later
set -e
. /steps/bootstrap.cfg
. /steps/env
daemon_socket="/var/guix/daemon-socket/socket"
channel_root="/var/lib/guix/local-channels"
channel_repo="${channel_root}/guix"
channel_work="/tmp/guix-local-channel-work"
channels_file="/root/.config/guix/channels.scm"
distfiles="${DISTFILES:-/external/distfiles}"
PATH="/usr/sbin:/sbin:${PATH}"
have_group() {
if command -v getent >/dev/null 2>&1; then
getent group "$1" >/dev/null 2>&1
else
grep -q "^$1:" /etc/group
fi
}
have_user() {
if command -v getent >/dev/null 2>&1; then
getent passwd "$1" >/dev/null 2>&1
else
grep -q "^$1:" /etc/passwd
fi
}
mkdir -p /proc /sys /dev /var/guix/daemon-socket /var/lib/guix /root/.config/guix
mount | grep ' on /proc ' >/dev/null 2>&1 || mount -t proc proc /proc
mount | grep ' on /sys ' >/dev/null 2>&1 || mount -t sysfs sysfs /sys
mount | grep ' on /dev ' >/dev/null 2>&1 || mount -t devtmpfs devtmpfs /dev
if ! have_group guixbuild; then
groupadd --system guixbuild
fi
nologin_bin="$(command -v nologin || true)"
if [ -z "${nologin_bin}" ]; then
if [ -x /usr/sbin/nologin ]; then
nologin_bin=/usr/sbin/nologin
elif [ -x /sbin/nologin ]; then
nologin_bin=/sbin/nologin
else
echo "Could not find nologin binary." >&2
exit 1
fi
fi
i=1
while [ "${i}" -le 10 ]; do
idp="$(printf '%02d' "${i}")"
user="guixbuilder${idp}"
if ! have_user "${user}"; then
useradd -g guixbuild -G guixbuild \
-d /var/empty -s "${nologin_bin}" \
-c "Guix build user ${idp}" --system \
"${user}"
fi
i=$((i + 1))
done
if [ ! -S "${daemon_socket}" ]; then
guix-daemon \
--build-users-group=guixbuild \
--listen="${daemon_socket}" \
>/tmp/guix-daemon.log 2>&1 &
fi
retry=0
while [ "${retry}" -lt 60 ]; do
if [ -S "${daemon_socket}" ]; then
break
fi
retry=$((retry + 1))
sleep 1
done
if [ ! -S "${daemon_socket}" ]; then
echo "guix-daemon did not become ready: ${daemon_socket}" >&2
exit 1
fi
src_tar=""
for f in "${distfiles}"/guix-1.5.0*.tar.* "${distfiles}"/guix-v1.5.0*.tar.*; do
if [ -f "${f}" ]; then
src_tar="${f}"
break
fi
done
if [ -z "${src_tar}" ]; then
echo "Could not find Guix 1.5.0 source tarball in ${distfiles}" >&2
exit 1
fi
rm -rf "${channel_work}" "${channel_repo}"
mkdir -p "${channel_work}" "${channel_root}"
case "${src_tar}" in
*.tar.gz|*.tgz) tar -C "${channel_work}" -xzf "${src_tar}" ;;
*.tar.xz) tar -C "${channel_work}" -xJf "${src_tar}" ;;
*.tar.bz2) tar -C "${channel_work}" -xjf "${src_tar}" ;;
*.tar) tar -C "${channel_work}" -xf "${src_tar}" ;;
*)
echo "Unsupported tarball format: ${src_tar}" >&2
exit 1
;;
esac
src_dir="$(find "${channel_work}" -mindepth 1 -maxdepth 1 -type d | head -n 1)"
if [ -z "${src_dir}" ]; then
echo "Failed to unpack Guix source from ${src_tar}" >&2
exit 1
fi
mv "${src_dir}" "${channel_repo}"
(
cd "${channel_repo}"
git init -q
git add -A
git -c user.name='guix-local' -c user.email='guix-local@example.invalid' commit -q -m 'local guix channel snapshot'
)
channel_commit="$(git -C "${channel_repo}" rev-parse HEAD)"
cat > "${channels_file}" <<EOF
(use-modules (guix channels))
(list
(channel
(name 'guix)
(url "file://${channel_repo}")
(branch "master")
(commit "${channel_commit}")))
EOF
chmod 0644 "${channels_file}"
guix pull --bootstrap --no-substitutes