Vagrant.configure(2) do |config|
  config.vm.box = "maier/alpine-3.6-x86_64"
  config.vm.synced_folder ENV['STACK_BUILD_DIR'], "/vagrant-build", type: "rsync", rsync__verbose: true, rsync__exclude: [".stack-work/", "_release/", ".cabal-sandbox/", "cabal.sandbox.config", "dist/", ".#*#", "*.vdi", "*.vmdk", "*.raw", ".DS_Store"], rsync__args: ["--verbose", "--archive", "--delete", "-z", "--copy-links"], rsync__rsync_path: "/usr/bin/rsync", rsync__chown: false
  config.vm.synced_folder "../../..", "/vagrant", type: "rsync", rsync__verbose: true, rsync__exclude: [".stack-work/", "_release/", ".cabal-sandbox/", "cabal.sandbox.config", "dist/", ".#*#", "*.vdi", "*.vmdk", "*.raw", ".DS_Store"], rsync__args: ["--verbose", "--archive", "--delete", "-z", "--copy-links"], rsync__rsync_path: "/usr/bin/rsync", rsync__chown: false
  config.vm.provider "virtualbox" do |vb|
    vb.memory = "3072"
  end
  config.ssh.forward_agent = true
  config.vm.provision "shell", inline: <<-SHELL
    set -xe
    apk update
    apk add alpine-sdk linux-headers musl-dev gmp-dev zlib-dev git rsync gnupg xz unzip
    apk --no-cache add --repository http://dl-cdn.alpinelinux.org/alpine/edge/community ghc ghc-dev cabal
    if ! which stack; then
      curl -sSL https://www.stackage.org/stack/linux-x86_64-static \
        | tar xzvf - --wildcards --strip-components=1 -C /usr/local/bin '*/stack'
      chmod a+x /usr/local/bin/stack
    fi
    mkdir -p /home/vagrant/.stack
    echo 'system-ghc: true' >/home/vagrant/.stack/config.yaml
    mkdir -p /vagrant-build /vagrant
    chown vagrant:vagrant /vagrant /vagrant-build /home/vagrant/.stack /home/vagrant/.stack/config.yaml
  SHELL
end
