Fix EC2 creation script for latest nixops

This commit is contained in:
Rob Vermaas 2013-11-07 14:42:44 +00:00
parent c93f57ba1c
commit 361eb3a5f5
2 changed files with 11 additions and 4 deletions

View File

@ -0,0 +1,5 @@
{ modulesPath, ...}:
{
imports = [ "${modulesPath}/virtualisation/amazon-config.nix" ];
services.journald.rateLimitBurst = 0;
}

View File

@ -8,9 +8,11 @@ import nixops.util
from nixops import deployment from nixops import deployment
from boto.ec2.blockdevicemapping import BlockDeviceMapping, BlockDeviceType from boto.ec2.blockdevicemapping import BlockDeviceMapping, BlockDeviceType
import boto.ec2 import boto.ec2
from nixops.statefile import StateFile, get_default_state_file
parser = argparse.ArgumentParser(description='Create an EBS-backed NixOS AMI') parser = argparse.ArgumentParser(description='Create an EBS-backed NixOS AMI')
parser.add_argument('--region', dest='region', required=True, help='EC2 region to create the image in') parser.add_argument('--region', dest='region', required=True, help='EC2 region to create the image in')
parser.add_argument('--channel', dest='channel', default="13.10", help='Channel to use')
parser.add_argument('--keep', dest='keep', action='store_true', help='Keep NixOps machine after use') parser.add_argument('--keep', dest='keep', action='store_true', help='Keep NixOps machine after use')
parser.add_argument('--hvm', dest='hvm', action='store_true', help='Create HVM image') parser.add_argument('--hvm', dest='hvm', action='store_true', help='Create HVM image')
parser.add_argument('--key', dest='key_name', action='store_true', help='Keypair used for HVM instance creation', default="rob") parser.add_argument('--key', dest='key_name', action='store_true', help='Keypair used for HVM instance creation', default="rob")
@ -37,11 +39,11 @@ f.write('''{{
'''.format(args.region, ebs_size)) '''.format(args.region, ebs_size))
f.close() f.close()
db = deployment.open_database(deployment.get_default_state_file()) db = StateFile(get_default_state_file())
try: try:
depl = deployment.open_deployment(db, "ebs-creator") depl = db.open_deployment("ebs-creator")
except Exception: except Exception:
depl = deployment.create_deployment(db) depl = db.create_deployment()
depl.name = "ebs-creator" depl.name = "ebs-creator"
depl.auto_response = "y" depl.auto_response = "y"
depl.nix_exprs = [os.path.abspath("./ebs-creator.nix"), os.path.abspath("./ebs-creator-config.nix")] depl.nix_exprs = [os.path.abspath("./ebs-creator.nix"), os.path.abspath("./ebs-creator-config.nix")]
@ -64,7 +66,7 @@ m.run_command("mkdir -p /mnt")
m.run_command("mount {0} /mnt".format(device)) m.run_command("mount {0} /mnt".format(device))
m.run_command("touch /mnt/.ebs") m.run_command("touch /mnt/.ebs")
m.run_command("mkdir -p /mnt/etc/nixos") m.run_command("mkdir -p /mnt/etc/nixos")
m.run_command("nix-channel --add http://nixos.org/channels/nixos-unstable") m.run_command("nix-channel --add http://nixos.org/channels/nixos-{} nixos".format(args.channel))
m.run_command("nix-channel --update") m.run_command("nix-channel --update")
m.run_command("nixos-rebuild switch") m.run_command("nixos-rebuild switch")
version = m.run_command("nixos-version", capture_stdout=True).replace('"', '').rstrip() version = m.run_command("nixos-version", capture_stdout=True).replace('"', '').rstrip()