2010-01-20 18:10:02 +00:00
|
|
|
{ config, pkgs, ... }:
|
|
|
|
|
|
|
|
with pkgs.lib;
|
|
|
|
|
|
|
|
{
|
2011-04-06 16:09:34 +01:00
|
|
|
require = [ ./ec2-data.nix ];
|
|
|
|
|
2010-01-21 08:03:58 +00:00
|
|
|
system.build.amazonImage =
|
2010-01-20 18:10:02 +00:00
|
|
|
pkgs.vmTools.runInLinuxVM (
|
|
|
|
pkgs.runCommand "amazon-image"
|
|
|
|
{ preVM =
|
|
|
|
''
|
|
|
|
mkdir $out
|
|
|
|
diskImage=$out/nixos.img
|
2010-07-13 21:47:31 +01:00
|
|
|
${pkgs.vmTools.kvm}/bin/qemu-img create -f raw $diskImage "4G"
|
2011-10-22 00:39:05 +01:00
|
|
|
mv closure xchg/
|
2010-01-20 18:10:02 +00:00
|
|
|
'';
|
2010-01-21 08:03:58 +00:00
|
|
|
buildInputs = [ pkgs.utillinux pkgs.perl ];
|
2011-09-14 19:20:50 +01:00
|
|
|
exportReferencesGraph =
|
2010-01-20 18:10:02 +00:00
|
|
|
[ "closure" config.system.build.toplevel ];
|
|
|
|
}
|
|
|
|
''
|
2010-08-27 16:31:04 +01:00
|
|
|
# Create an empty filesystem and mount it.
|
2010-01-22 17:31:23 +00:00
|
|
|
${pkgs.e2fsprogs}/sbin/mkfs.ext3 -L nixos /dev/vda
|
|
|
|
${pkgs.e2fsprogs}/sbin/tune2fs -c 0 -i 0 /dev/vda
|
2010-01-20 18:10:02 +00:00
|
|
|
mkdir /mnt
|
|
|
|
mount /dev/vda /mnt
|
|
|
|
|
2010-01-22 20:22:40 +00:00
|
|
|
# The initrd expects these directories to exist.
|
|
|
|
mkdir /mnt/dev /mnt/proc /mnt/sys
|
2011-09-14 19:20:50 +01:00
|
|
|
|
2011-07-29 15:55:42 +01:00
|
|
|
mount -o bind /proc /mnt/proc
|
2010-01-22 20:22:40 +00:00
|
|
|
|
2010-01-20 18:10:02 +00:00
|
|
|
# Copy all paths in the closure to the filesystem.
|
2011-10-22 00:39:05 +01:00
|
|
|
storePaths=$(perl ${pkgs.pathsFromGraph} /tmp/xchg/closure)
|
2010-01-20 18:10:02 +00:00
|
|
|
|
2011-10-30 15:19:58 +00:00
|
|
|
mkdir -p /mnt/nix/store
|
2011-10-22 00:39:05 +01:00
|
|
|
echo "copying everything (will take a while)..."
|
2011-10-30 15:19:58 +00:00
|
|
|
cp -prd $storePaths /mnt/nix/store/
|
2010-01-20 18:10:02 +00:00
|
|
|
|
2010-01-22 17:31:23 +00:00
|
|
|
# Register the paths in the Nix database.
|
2011-10-22 00:39:05 +01:00
|
|
|
printRegistration=1 perl ${pkgs.pathsFromGraph} /tmp/xchg/closure | \
|
2010-01-22 17:31:23 +00:00
|
|
|
chroot /mnt ${config.environment.nix}/bin/nix-store --load-db
|
|
|
|
|
|
|
|
# Create the system profile to allow nixos-rebuild to work.
|
|
|
|
chroot /mnt ${config.environment.nix}/bin/nix-env \
|
2011-10-30 15:19:58 +00:00
|
|
|
-p /nix/var/nix/profiles/system --set ${config.system.build.toplevel}
|
2010-01-22 17:31:23 +00:00
|
|
|
|
|
|
|
# `nixos-rebuild' requires an /etc/NIXOS.
|
|
|
|
mkdir -p /mnt/etc
|
|
|
|
touch /mnt/etc/NIXOS
|
2010-07-15 12:09:30 +01:00
|
|
|
|
|
|
|
# Install a configuration.nix.
|
|
|
|
mkdir -p /mnt/etc/nixos
|
|
|
|
cp ${./amazon-config.nix} /mnt/etc/nixos/configuration.nix
|
2010-07-20 14:53:14 +01:00
|
|
|
|
2010-07-22 15:40:29 +01:00
|
|
|
# Generate the GRUB menu.
|
|
|
|
chroot /mnt ${config.system.build.toplevel}/bin/switch-to-configuration boot
|
2010-01-20 18:10:02 +00:00
|
|
|
|
2011-07-29 15:55:42 +01:00
|
|
|
umount /mnt/proc
|
2010-01-20 18:10:02 +00:00
|
|
|
umount /mnt
|
|
|
|
''
|
|
|
|
);
|
|
|
|
|
2010-01-22 17:31:23 +00:00
|
|
|
fileSystems =
|
|
|
|
[ { mountPoint = "/";
|
|
|
|
device = "/dev/disk/by-label/nixos";
|
|
|
|
}
|
2010-08-29 23:09:15 +01:00
|
|
|
{ mountPoint = "/ephemeral0";
|
2010-07-20 14:53:14 +01:00
|
|
|
device = "/dev/xvdc";
|
2010-08-29 23:09:15 +01:00
|
|
|
neededForBoot = true;
|
2010-01-22 17:31:23 +00:00
|
|
|
}
|
|
|
|
];
|
2010-01-21 08:03:58 +00:00
|
|
|
|
|
|
|
swapDevices =
|
2010-07-20 14:53:14 +01:00
|
|
|
[ { device = "/dev/xvdb"; } ];
|
|
|
|
|
2010-08-29 23:29:10 +01:00
|
|
|
boot.initrd.kernelModules = [ "xen-blkfront" "aufs" ];
|
2010-07-20 14:53:14 +01:00
|
|
|
boot.kernelModules = [ "xen-netfront" ];
|
2010-01-21 08:03:58 +00:00
|
|
|
|
2010-08-29 23:29:10 +01:00
|
|
|
boot.extraModulePackages = [ config.boot.kernelPackages.aufs2 ];
|
|
|
|
|
2010-07-22 15:40:29 +01:00
|
|
|
# Generate a GRUB menu. Amazon's pv-grub uses this to boot our kernel/initrd.
|
|
|
|
boot.loader.grub.device = "nodev";
|
|
|
|
boot.loader.grub.timeout = 0;
|
|
|
|
boot.loader.grub.extraPerEntryConfig = "root (hd0)";
|
|
|
|
|
2011-09-14 19:20:50 +01:00
|
|
|
# Put /tmp and /var on /ephemeral0, which has a lot more space.
|
|
|
|
# Unfortunately we can't do this with the `fileSystems' option
|
|
|
|
# because it has no support for creating the source of a bind
|
2010-08-29 23:29:10 +01:00
|
|
|
# mount. Also, "move" /nix to /ephemeral0 by layering an AUFS
|
|
|
|
# on top of it so we have a lot more space for Nix operations.
|
2010-08-29 23:09:15 +01:00
|
|
|
boot.initrd.postMountCommands =
|
|
|
|
''
|
|
|
|
mkdir -m 1777 -p $targetRoot/ephemeral0/tmp
|
2010-09-01 12:00:35 +01:00
|
|
|
mkdir -m 1777 -p $targetRoot/tmp
|
2010-08-29 23:09:15 +01:00
|
|
|
mount --bind $targetRoot/ephemeral0/tmp $targetRoot/tmp
|
2010-08-29 23:29:10 +01:00
|
|
|
|
2010-08-29 23:09:15 +01:00
|
|
|
mkdir -m 755 -p $targetRoot/ephemeral0/var
|
2010-09-01 12:00:35 +01:00
|
|
|
mkdir -m 755 -p $targetRoot/var
|
2010-08-29 23:09:15 +01:00
|
|
|
mount --bind $targetRoot/ephemeral0/var $targetRoot/var
|
2010-08-29 23:29:10 +01:00
|
|
|
|
|
|
|
mkdir -m 755 -p $targetRoot/ephemeral0/nix
|
|
|
|
mount -t aufs -o dirs=$targetRoot/ephemeral0/nix=rw:$targetRoot/nix=rr none $targetRoot/nix
|
2010-08-29 23:09:15 +01:00
|
|
|
'';
|
|
|
|
|
2010-01-21 08:03:58 +00:00
|
|
|
# There are no virtual consoles.
|
|
|
|
services.mingetty.ttys = [ ];
|
|
|
|
|
|
|
|
# Allow root logins only using the SSH key that the user specified
|
|
|
|
# at instance creation time.
|
2010-03-11 17:02:53 +00:00
|
|
|
services.openssh.enable = true;
|
|
|
|
services.openssh.permitRootLogin = "without-password";
|
2010-01-20 18:10:02 +00:00
|
|
|
}
|