variables:
  CACHE_BOOTSTRAP_GUIX_VERSION: 1.1.0

before_script:
  # Extract the APT cached packages, so as not to download ntp, wget and xz-utils at each job
  - (test -f apt-cache.tar.gz && ln -s $PWD/apt-cache.tar.gz /apt-cache.tar.gz && cd / && tar xf apt-cache.tar.gz) || true
  # Remove the docker policy of never caching packages
  - rm -f /etc/apt/apt.conf.d/docker-clean
  # Install (from the cache if possible)
  - apt-get update
  - apt-get install -y ntp wget xz-utils
  # Download the guix binary installation if we have not ours in the cache
  - test -f guix-binary.x86_64-linux.tar.xz || wget -O guix-binary.x86_64-linux.tar.xz https://ftp.gnu.org/gnu/guix/guix-binary-$CACHE_BOOTSTRAP_GUIX_VERSION.x86_64-linux.tar.xz
  # Extract the guix binary installation, either ours (fairly up to date) or the one just downloaded (older)
  - tar --warning=no-timestamp -xf guix-binary.x86_64-linux.tar.xz
  # Perform the binary installation, cf guix manual
  - mv var/guix /var
  - mv gnu /
  - mkdir -p /root/.config/guix
  - ln -sf /var/guix/profiles/per-user/root/current-guix /root/.config/guix/current
  - ln -s /var/guix/profiles/per-user/root/guix-profile /root/.guix-profile || echo "No profile yet"
  - source /root/.config/guix/current/etc/profile
  - source /root/.guix-profile/etc/profile || echo "No profile yet"
  - groupadd --system guixbuild
  - for i in $(seq 1 10) ; do useradd -g guixbuild -G guixbuild -d /var/empty -s $(which nologin) -c "Guix build user $i" --system guixbuilder$i ; done
  - guix-daemon --build-users-group=guixbuild --disable-chroot &
  - guix archive --authorize < /root/.config/guix/current/share/guix/ci.guix.gnu.org.pub
  # Update, but allow it to fail (guix server down)
  - guix pull || true

after_script:
  # Regenerate the caches; they grow steadily (the guix cache grows way faster)
  - tar cf apt-cache.tar.gz /var/cache/apt
  - tar cf guix-binary.x86_64-linux.tar.xz /var/guix /gnu

cache:
  paths:
    - guix-binary.x86_64-linux.tar.xz
    - apt-cache.tar.gz

test:
  script:
    - guix environment --ad-hoc --pure hello -- hello
