diff options
author | Rob Vermaas <rob.vermaas@gmail.com> | 2014-05-21 16:31:52 +0200 |
---|---|---|
committer | Rob Vermaas <rob.vermaas@gmail.com> | 2014-05-21 16:37:55 +0200 |
commit | 973fa21b52d0222ea5033ef265b2fbc0d2ab85c2 (patch) | |
tree | e36666ef872d15787f676690e2fbfa2bb42381db /nixos/maintainers | |
parent | cdfb8738a4f93f1e4146b8f7251632640de8e34a (diff) |
Better support for HVM instances. Now the NixOS images can
be used on HVM instances without needing nixops. Previously the grub setup was incorrect, so a plain 'nixos-rebuild switch' and a reboot would result in a broken system. Also added growing of the partition of the root disk in the initrd, so you can run resize2fs after initial boot, without needing an extra reboot. This is useful especially for nixops' deployment.ec2.ebsInitialRootDiskSize option. (cherry picked from commit 044a24e58bcf4cf48df02df936c542839fb08d90)
Diffstat (limited to 'nixos/maintainers')
4 files changed, 50 insertions, 9 deletions
diff --git a/nixos/maintainers/scripts/ec2/amazon-hvm-config.nix b/nixos/maintainers/scripts/ec2/amazon-hvm-config.nix new file mode 100644 index 0000000000000..d0c7f3a6a6c9c --- /dev/null +++ b/nixos/maintainers/scripts/ec2/amazon-hvm-config.nix @@ -0,0 +1,5 @@ +{ config, pkgs, ...}: +{ + imports = [ ./amazon-base-config.nix ]; + ec2.hvm = true; +} diff --git a/nixos/maintainers/scripts/ec2/amazon-hvm-install-config.nix b/nixos/maintainers/scripts/ec2/amazon-hvm-install-config.nix new file mode 100644 index 0000000000000..d9feba164a76c --- /dev/null +++ b/nixos/maintainers/scripts/ec2/amazon-hvm-install-config.nix @@ -0,0 +1,33 @@ +{ config, pkgs, lib, ...}: +let + cloudUtils = pkgs.fetchurl { + url = "https://launchpad.net/cloud-utils/trunk/0.27/+download/cloud-utils-0.27.tar.gz"; + sha256 = "16shlmg36lidp614km41y6qk3xccil02f5n3r4wf6d1zr5n4v8vd"; + }; + growpart = pkgs.stdenv.mkDerivation { + name = "growpart"; + src = cloudUtils; + buildPhase = '' + cp bin/growpart $out + sed -i 's|awk|gawk|' $out + sed -i 's|sed|gnused|' $out + ''; + dontInstall = true; + dontPatchShebangs = true; + }; +in +{ + imports = [ ./amazon-base-config.nix ]; + ec2.hvm = true; + boot.loader.grub.device = lib.mkOverride 0 "nodev"; + + boot.initrd.extraUtilsCommands = '' + cp -v ${pkgs.gawk}/bin/gawk $out/bin/gawk + cp -v ${pkgs.gnused}/bin/sed $out/bin/gnused + cp -v ${pkgs.utillinux}/sbin/sfdisk $out/bin/sfdisk + cp -v ${growpart} $out/bin/growpart + ''; + boot.initrd.postDeviceCommands = '' + [ -e /dev/xvda ] && [ -e /dev/xvda1 ] && TMPDIR=/run sh $(type -P growpart) /dev/xvda 1 + ''; +} diff --git a/nixos/maintainers/scripts/ec2/create-ebs-amis.py b/nixos/maintainers/scripts/ec2/create-ebs-amis.py index 4e1aea659803a..14607b9a36782 100755 --- a/nixos/maintainers/scripts/ec2/create-ebs-amis.py +++ b/nixos/maintainers/scripts/ec2/create-ebs-amis.py @@ -18,7 +18,7 @@ parser.add_argument('--hvm', dest='hvm', action='store_true', help='Create HVM i parser.add_argument('--key', dest='key_name', action='store_true', help='Keypair used for HVM instance creation', default="rob") args = parser.parse_args() -instance_type = "m3.xlarge" if args.hvm else "m1.small" +instance_type = "m3.medium" if args.hvm else "m1.small" ebs_size = 8 if args.hvm else 20 @@ -52,7 +52,6 @@ depl.deploy(allow_reboot=True) m = depl.machines['machine'] - # Do the installation. device="/dev/xvdg" if args.hvm: @@ -66,24 +65,27 @@ m.run_command("mkdir -p /mnt") m.run_command("mount {0} /mnt".format(device)) m.run_command("touch /mnt/.ebs") m.run_command("mkdir -p /mnt/etc/nixos") + m.run_command("nix-channel --add http://nixos.org/channels/nixos-{} nixos".format(args.channel)) m.run_command("nix-channel --update") -m.run_command("nixos-rebuild switch") -version = m.run_command("nixos-version", capture_stdout=True).split(' ')[0] + +version = m.run_command("nix-instantiate --eval-only -A lib.nixpkgsVersion '<nixpkgs>'", capture_stdout=True).split(' ')[0].replace('"','').strip() print >> sys.stderr, "NixOS version is {0}".format(version) -m.upload_file("./amazon-base-config.nix", "/mnt/etc/nixos/configuration.nix") -m.run_command("nixos-install") if args.hvm: + m.upload_file("./amazon-base-config.nix", "/mnt/etc/nixos/amazon-base-config.nix") + m.upload_file("./amazon-hvm-config.nix", "/mnt/etc/nixos/configuration.nix") + m.upload_file("./amazon-hvm-install-config.nix", "/mnt/etc/nixos/amazon-hvm-install-config.nix") + m.run_command("NIXOS_CONFIG=/etc/nixos/amazon-hvm-install-config.nix nixos-install") m.run_command('nix-env -iA nixos.pkgs.grub') m.run_command('cp /nix/store/*-grub-0.97*/lib/grub/i386-pc/* /mnt/boot/grub') - m.run_command('sed -i "s|hd0|hd0,0|" /mnt/boot/grub/menu.lst') m.run_command('echo "(hd1) /dev/xvdg" > device.map') m.run_command('echo -e "root (hd1,0)\nsetup (hd1)" | grub --device-map=device.map --batch') - +else: + m.upload_file("./amazon-base-config.nix", "/mnt/etc/nixos/configuration.nix") + m.run_command("nixos-install") m.run_command("umount /mnt") - if args.hvm: ami_name = "nixos-{0}-x86_64-ebs-hvm".format(version) description = "NixOS {0} (x86_64; EBS root; hvm)".format(version) diff --git a/nixos/maintainers/scripts/ec2/ebs-creator.nix b/nixos/maintainers/scripts/ec2/ebs-creator.nix index 5a5c57c72eb5e..37795d5d5b4a5 100644 --- a/nixos/maintainers/scripts/ec2/ebs-creator.nix +++ b/nixos/maintainers/scripts/ec2/ebs-creator.nix @@ -8,6 +8,7 @@ deployment.ec2.securityGroups = [ "admin" ]; deployment.ec2.ebsBoot = false; deployment.ec2.keyPair = resources.ec2KeyPairs.keypair.name; + deployment.ec2.zone = "us-east-1e"; environment.systemPackages = [ pkgs.parted ]; }; } |