Skip to content
Permalink
Browse files

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 044a24e)
  • Loading branch information
rbvermaa committed May 21, 2014
1 parent cdfb873 commit 973fa21b52d0222ea5033ef265b2fbc0d2ab85c2
@@ -0,0 +1,5 @@
{ config, pkgs, ...}:
{
imports = [ ./amazon-base-config.nix ];
ec2.hvm = true;
}
@@ -0,0 +1,33 @@
{ config, pkgs, lib, ...}:
let
cloudUtils = pkgs.fetchurl {

This comment has been minimized.

Copy link
@wmertens

wmertens May 25, 2014

Contributor

shouldn't this be a pkg?

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
'';
}
@@ -18,7 +18,7 @@
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 @@

m = depl.machines['machine']


# Do the installation.
device="/dev/xvdg"
if args.hvm:
@@ -66,24 +65,27 @@
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)
@@ -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 ];
};
}

0 comments on commit 973fa21

Please sign in to comment.
You can’t perform that action at this time.