# Guix build environment for building `guix system docker-image` images
# from this repo on a machine (e.g. macOS) that can't run Guix natively.
#
# Guix state lives under /gnu and /var/guix, which the compose file mounts
# as named volumes so pulls/builds are cached across container runs. This
# image only bakes in the *initial* binary install; everything built via
# `guix pull` / `guix system` happens at `docker run` time against those
# volumes.
FROM debian:bookworm-slim

RUN apt-get update && apt-get install -y --no-install-recommends \
      bash gnupg dirmngr wget ca-certificates xz-utils tar locales procps sudo netbase \
    && rm -rf /var/lib/apt/lists/* \
    && sed -i '/en_US.UTF-8/s/^# //' /etc/locale.gen \
    && locale-gen

# Official installer: extracts the binary tarball to /gnu and /var/guix,
# creates the guixbuild group/users, and (since no init system is present
# in the container) prints instructions to run guix-daemon manually, which
# entrypoint.sh does. `yes ''` answers every prompt with its default,
# which includes authorizing the ci.guix.gnu.org / bordeaux substitute
# servers so builds don't compile everything from source.
RUN wget -O /tmp/guix-install.sh https://guix.gnu.org/guix-install.sh \
    && chmod +x /tmp/guix-install.sh \
    && yes '' | /tmp/guix-install.sh \
    && rm -f /tmp/guix-install.sh \
    && test -x /root/.config/guix/current/bin/guix

ENV PATH="/root/.config/guix/current/bin:/usr/local/bin:${PATH}" \
    GUIX_LOCPATH="/root/.config/guix/current/lib/locale" \
    LANG="en_US.UTF-8"

COPY entrypoint.sh /usr/local/bin/entrypoint.sh
RUN chmod +x /usr/local/bin/entrypoint.sh

WORKDIR /workspace
ENTRYPOINT ["/usr/local/bin/entrypoint.sh"]
CMD ["bash"]
