#!/usr/bin/env bash # Drive the dockerized Guix build environment (see docker/) to build the # operating-system definitions in this repo as `guix system docker-image` # tarballs, loadable straight into Docker Desktop. set -euo pipefail cd "$(dirname "$0")/.." compose() { docker compose run --rm guix "$@" } usage() { cat < [args] commands: build build/rebuild the guix builder image pull guix pull -C channels.scm (do this first, and again whenever channels.scm/channels.d/*.scm change) shell interactive shell inside the builder container image FILE.scm [NAME] build FILE.scm (e.g. metznet/machines/ldap.scm) as a docker image, writing build/NAME.tar.gz (NAME defaults to FILE's basename). -L points at /workspace (this checkout), so uncommitted local edits are picked up directly -- no commit/pull round-trip needed. Load with: docker load < build/NAME.tar.gz load-run FILE.scm build FILE.scm, docker load it into the host Docker, and drop into a shell in a container started from it EOF } cmd="${1:-}" [ -n "$cmd" ] && shift || true case "$cmd" in build) docker compose build ;; pull) compose guix pull -C channels.scm ;; shell) compose bash ;; image) scm="${1:?usage: $0 image FILE.scm [NAME]}" name="${2:-$(basename "$scm" .scm)}" compose bash -c " set -e # --no-grafts: with --disable-chroot (see docker/entrypoint.sh), # guix-daemon's store-path grafting (security-patch rewriting) hits # a permission error creating output files -- skipping grafts # avoids it entirely and just uses the un-grafted originals. out=\$(guix system docker-image -N --no-grafts -L /workspace '$scm') mkdir -p /workspace/build cp \"\$out\" '/workspace/build/$name.tar.gz' echo \"wrote build/$name.tar.gz\" " ;; load-run) scm="${1:?usage: $0 load-run FILE.scm}" name="$(basename "$scm" .scm)" "$0" image "$scm" "$name" image_id="$(docker load -q -i "build/$name.tar.gz" | sed 's/^Loaded image: //')" echo "loaded $image_id, starting container..." docker run --rm -it "$image_id" /run/current-system/profile/bin/bash --login ;; *) usage exit 1 ;; esac