From 590acc193c1d823d99ca216f19fbbb9588f8c3ef Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Wed, 20 Jan 2010 18:10:02 +0000 Subject: [PATCH] * A module for generating a disk image suitable for use with Amazon's Elastic Compute Cloud (EC2). TODO: run ec2-bundle-image here. svn path=/nixos/trunk/; revision=19580 --- modules/virtualisation/amazon-image.nix | 43 +++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 modules/virtualisation/amazon-image.nix diff --git a/modules/virtualisation/amazon-image.nix b/modules/virtualisation/amazon-image.nix new file mode 100644 index 000000000000..e834b392c6fa --- /dev/null +++ b/modules/virtualisation/amazon-image.nix @@ -0,0 +1,43 @@ +{ config, pkgs, ... }: + +with pkgs.lib; + +{ + system.build.ext2Image = + pkgs.vmTools.runInLinuxVM ( + pkgs.runCommand "amazon-image" + { preVM = + '' + mkdir $out + diskImage=$out/nixos.img + qemu-img create -f raw $diskImage "1024M" + ''; + buildInputs = [ pkgs.utillinux pkgs.perl pkgs.rsync ]; + exportReferencesGraph = + [ "closure" config.system.build.toplevel ]; + } + '' + # Create an empty filesysten and mount it. + ${pkgs.e2fsprogs}/sbin/mkfs.ext3 /dev/vda + mkdir /mnt + mount /dev/vda /mnt + + # Copy all paths in the closure to the filesystem. + storePaths=$(perl ${pkgs.pathsFromGraph} $ORIG_TMPDIR/closure) + + mkdir -p /mnt/nix/store + rsync -av $storePaths /mnt/nix/store/ + + # Amazon assumes that there is a /sbin/init, so symlink it + # to the stage 2 init script. Since we cannot set the path + # to the system configuration via the systemConfig kernel + # parameter, use a /system symlink. + mkdir -p /mnt/sbin + ln -s ${config.system.build.bootStage2} /mnt/sbin/init + ln -s ${config.system.build.toplevel} /mnt/system + + umount /mnt + '' + ); + +}