2011-11-04 02:31:18 +01:00
|
|
|
#! /bin/sh -e
|
|
|
|
|
2013-06-05 18:11:19 +02:00
|
|
|
export NIXOS_CONFIG=$(dirname $(readlink -f $0))/amazon-base-config.nix
|
2013-01-24 19:37:42 +01:00
|
|
|
|
2013-11-08 12:40:58 +01:00
|
|
|
version=$(nix-instantiate --eval-only '<nixpkgs/nixos>' -A config.system.nixosVersion | sed s/'"'//g)
|
2013-01-24 19:37:42 +01:00
|
|
|
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-11-08 12:40:58 +01:00
|
|
|
nix-build '<nixpkgs/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-11-08 12:40:58 +01:00
|
|
|
for region in eu-west-1; 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
|