1#! /bin/sh -e
2
3BUCKET_NAME=${BUCKET_NAME:-nixos-images}
4export NIX_PATH=nixpkgs=../../../..
5export NIXOS_CONFIG=$(dirname $(readlink -f $0))/../../../modules/virtualisation/google-compute-image.nix
6export TIMESTAMP=$(date +%Y%m%d%H%M)
7
8nix-build '<nixpkgs/nixos>' \
9 -A config.system.build.googleComputeImage --argstr system x86_64-linux -o gce --option extra-binary-caches http://hydra.nixos.org -j 10
10
11img=$(echo gce/*.tar.gz)
12if ! gsutil ls gs://${BUCKET_NAME}/$(basename $img); then
13 gsutil cp $img gs://${BUCKET_NAME}/$(basename $img)
14fi
15gcloud compute images create $(basename $img .raw.tar.gz | sed 's|\.|-|' | sed 's|_|-|') --source-uri gs://${BUCKET_NAME}/$(basename $img)