[buildout]
extends =
  ../file/buildout.cfg
  ../openssh/buildout.cfg
  ../p7zip/buildout.cfg
  ../qemu-kvm/buildout.cfg

parts = vm-debian

[vm-run-environment]
PATH = ${openssh:location}/bin:${qemu:location}/bin:%(PATH)s

[vm-install-environment]
PATH = ${file:location}/bin:${p7zip:location}/bin:${vm-run-environment:PATH}

[vm-run-base]
recipe = slapos.recipe.build:vm.run
environment = vm-run-environment
vm = ${vm-debian:location}
dist = ${vm-debian:dists}
wait-ssh = 100

[vm-debian]
recipe = slapos.recipe.build:vm.install-debian
environment = vm-install-environment
dists = debian-buster
size = 2Gi
preseed.partman/early_command =
  set -e /usr/lib/apt-setup/generators/99 AllowUnauthenticated; if [ "`debconf-get mirror/http/hostname`" = archive.debian.org ]; then echo "echo 'APT::Get::$2 \"true\";' >/target/etc/apt/apt.conf.d/01$2" >$1$2; chmod +x $1$2; fi
late-command =
# rdnssd causes too much trouble with recent QEMU, because the latter acts as
# a DNS proxy on both IPv4 and IPv6 without translating queries to what the
# host supports.
  dpkg -P rdnssd
# Fix partially Let's Encrypt certificate on old OS due to expired root CA.
# This is enough for Python but not wget.
  dpkg --compare-versions 20200601~ le `dpkg-query -f '$${Version}' -W ca-certificates 2>/dev/null ||echo 1:0` || (
    set ca-certificates_20200601~deb9u2_all.deb
    wget http://security.debian.org/debian-security/pool/updates/main/c/ca-certificates/$1
    echo 6cb3ce4329229d71a6f06b9f13c710457c05a469012ea31853ac300873d5a3e1 $1 |sha256sum -c
    dpkg -i $1
    rm $1
    cd /etc/ssl/certs
    rm DST_Root_CA_X3.pem 2e5ac55d.0 12d55845.0
  )
  mount |grep -q 'on / .*\bdiscard\b' || ! type fstrim || {
    apt-get clean
    sync
    fstrim -v /
  }
debconf.debconf =
  debconf/frontend noninteractive
  debconf/priority critical
debian-jessie/preseed.mirror/country = manual
debian-jessie/preseed.mirror/http/hostname = archive.debian.org
debian-jessie/preseed.mirror/http/directory = /debian
# minimal size
preseed.apt-setup/enable-source-repositories = false
preseed.recommends = false
preseed.tasks =

[debian-stable]
x86_64.iso = debian-amd64-netinst.iso
x86_64.kernel = install.amd/vmlinuz
x86_64.initrd = install.amd/initrd.gz

[debian-testing]
<= debian-stable
x86_64.iso = debian-amd64-testing-netinst.iso

[debian-jessie]
<= debian-stable
x86_64.iso = debian-amd64-jessie-netinst.iso

[debian-stretch]
<= debian-stable
x86_64.iso = debian-amd64-stretch-netinst.iso

[debian-buster]
<= debian-stable
x86_64.iso = debian-amd64-buster-netinst.iso

[debian-bullseye]
<= debian-stable
x86_64.iso = debian-amd64-bullseye-netinst.iso
