2011-11-04 02:31:18 +01:00
|
|
|
#! /bin/sh -e
|
|
|
|
|
2012-12-18 19:44:47 +01:00
|
|
|
nixos=$(nix-instantiate --find-file nixos)
|
2013-01-24 19:37:42 +01:00
|
|
|
export NIXOS_CONFIG=$nixos/modules/virtualisation/amazon-config.nix
|
|
|
|
|
|
|
|
version=$(nix-instantiate --eval-only '<nixos>' -A config.system.nixosVersion | sed s/'"'//g)
|
|
|
|
echo "NixOS version is $version"
|
2011-11-04 02:31:18 +01:00
|
|
|
|
|
|
|
buildAndUploadFor() {
|
|
|
|
system="$1"
|
|
|
|
arch="$2"
|
|
|
|
|
2011-11-08 21:49:21 +01:00
|
|
|
echo "building $system image..."
|
2013-01-24 19:37:42 +01:00
|
|
|
nix-build '<nixos>' \
|
2011-11-04 02:31:18 +01:00
|
|
|
-A config.system.build.amazonImage --argstr system "$system" -o ec2-ami
|
|
|
|
|
|
|
|
ec2-bundle-image -i ./ec2-ami/nixos.img --user "$AWS_ACCOUNT" --arch "$arch" \
|
|
|
|
-c "$EC2_CERT" -k "$EC2_PRIVATE_KEY"
|
|
|
|
|
2013-01-24 19:37:42 +01:00
|
|
|
for region in eu-west-1 us-east-1 us-west-1 us-west-2; do
|
2011-11-08 21:49:21 +01:00
|
|
|
echo "uploading $system image for $region..."
|
2011-11-04 02:31:18 +01:00
|
|
|
|
2013-01-24 19:37:42 +01:00
|
|
|
name=nixos-$version-$arch-s3
|
|
|
|
bucket="$(echo $name-$region | tr '[A-Z]_' '[a-z]-')"
|
2011-11-04 02:31:18 +01:00
|
|
|
|
2011-11-08 21:56:33 +01:00
|
|
|
if [ "$region" = eu-west-1 ]; then s3location=EU;
|
|
|
|
elif [ "$region" = us-east-1 ]; then s3location=US;
|
|
|
|
else s3location="$region"
|
|
|
|
fi
|
|
|
|
|
2011-11-08 21:49:21 +01:00
|
|
|
ec2-upload-bundle -b "$bucket" -m /tmp/nixos.img.manifest.xml \
|
2013-01-24 19:37:42 +01:00
|
|
|
-a "$EC2_ACCESS_KEY" -s "$EC2_SECRET_KEY" --location "$s3location" \
|
|
|
|
--url http://s3.amazonaws.com
|
2011-11-04 02:31:18 +01:00
|
|
|
|
2012-03-23 19:09:40 +01:00
|
|
|
kernel=$(ec2-describe-images -o amazon --filter "manifest-location=*pv-grub-hd0_1.03-$arch*" --region "$region" | cut -f 2)
|
2011-11-08 21:49:21 +01:00
|
|
|
echo "using PV-GRUB kernel $kernel"
|
2011-11-04 02:31:18 +01:00
|
|
|
|
2011-11-08 21:49:21 +01:00
|
|
|
ami=$(ec2-register "$bucket/nixos.img.manifest.xml" -n "$name" -d "NixOS $system r$revision" \
|
|
|
|
--region "$region" --kernel "$kernel" | cut -f 2)
|
2011-11-04 02:31:18 +01:00
|
|
|
|
2011-11-08 21:49:21 +01:00
|
|
|
echo "AMI ID is $ami"
|
|
|
|
|
2013-01-24 19:37:42 +01:00
|
|
|
echo $ami >> $region.s3.ami-id
|
2011-11-08 21:49:21 +01:00
|
|
|
|
|
|
|
ec2-modify-image-attribute --region "$region" "$ami" -l -a all
|
|
|
|
done
|
2011-11-04 02:31:18 +01:00
|
|
|
}
|
|
|
|
|
2011-11-04 04:50:17 +01:00
|
|
|
buildAndUploadFor x86_64-linux x86_64
|