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)
This commit is contained in:
parent
cdfb8738a4
commit
973fa21b52
4 changed files with 50 additions and 9 deletions
5
nixos/maintainers/scripts/ec2/amazon-hvm-config.nix
Normal file
5
nixos/maintainers/scripts/ec2/amazon-hvm-config.nix
Normal file
|
@ -0,0 +1,5 @@
|
|||
{ config, pkgs, ...}:
|
||||
{
|
||||
imports = [ ./amazon-base-config.nix ];
|
||||
ec2.hvm = true;
|
||||
}
|
33
nixos/maintainers/scripts/ec2/amazon-hvm-install-config.nix
Normal file
33
nixos/maintainers/scripts/ec2/amazon-hvm-install-config.nix
Normal file
|
@ -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
|
||||
'';
|
||||
}
|
|
@ -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)
|
||||
|
|
|
@ -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 ];
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue