···
2
+
# $ NIXOS_CONFIG=`pwd`/nixos/modules/virtualisation/nova-image.nix nix-build '<nixpkgs/nixos>' -A config.system.build.novaImage
{ config, lib, pkgs, ... }:
6
-
imports = [ ../profiles/qemu-guest.nix ../profiles/headless.nix ./ec2-data.nix ];
8
-
system.build.novaImage =
9
-
pkgs.vmTools.runInLinuxVM (
10
-
pkgs.runCommand "nova-image"
14
-
diskImage=$out/image
15
-
${pkgs.vmTools.qemu}/bin/qemu-img create -f raw $diskImage "4G"
18
-
buildInputs = [ pkgs.utillinux pkgs.perl ];
19
-
exportReferencesGraph =
20
-
[ "closure" config.system.build.toplevel ];
9
+
system.build.novaImage = import ../../lib/make-disk-image.nix {
10
+
inherit pkgs lib config;
12
+
diskSize = 1 * 1024;
13
+
configFile = pkgs.writeText "configuration.nix"
16
+
imports = [ <nixpkgs/nixos/modules/virtualisation/nova-image.nix> ];
23
-
# Create a single / partition.
24
-
${pkgs.parted}/sbin/parted /dev/vda mklabel msdos
25
-
${pkgs.parted}/sbin/parted /dev/vda -- mkpart primary ext2 1M -1s
26
-
. /sys/class/block/vda1/uevent
27
-
mknod /dev/vda1 b $MAJOR $MINOR
29
-
# Create an empty filesystem and mount it.
30
-
${pkgs.e2fsprogs}/sbin/mkfs.ext3 -L nixos /dev/vda1
31
-
${pkgs.e2fsprogs}/sbin/tune2fs -c 0 -i 0 /dev/vda1
33
-
mount /dev/vda1 /mnt
35
-
# The initrd expects these directories to exist.
36
-
mkdir /mnt/dev /mnt/proc /mnt/sys
37
-
mount --bind /proc /mnt/proc
38
-
mount --bind /dev /mnt/dev
39
-
mount --bind /sys /mnt/sys
41
-
# Copy all paths in the closure to the filesystem.
42
-
storePaths=$(perl ${pkgs.pathsFromGraph} /tmp/xchg/closure)
44
-
mkdir -p /mnt/nix/store
45
-
${pkgs.rsync}/bin/rsync -av $storePaths /mnt/nix/store/
47
-
# Register the paths in the Nix database.
48
-
printRegistration=1 perl ${pkgs.pathsFromGraph} /tmp/xchg/closure | \
49
-
chroot /mnt ${config.nix.package}/bin/nix-store --load-db --option build-users-group ""
51
-
# Create the system profile to allow nixos-rebuild to work.
52
-
chroot /mnt ${config.nix.package}/bin/nix-env --option build-users-group "" \
53
-
-p /nix/var/nix/profiles/system --set ${config.system.build.toplevel}
55
-
# `nixos-rebuild' requires an /etc/NIXOS.
57
-
touch /mnt/etc/NIXOS
59
-
# `switch-to-configuration' requires a /bin/sh
61
-
ln -s ${config.system.build.binsh}/bin/sh /mnt/bin/sh
63
-
# Install a configuration.nix.
64
-
mkdir -p /mnt/etc/nixos
65
-
cp ${./nova-config.nix} /mnt/etc/nixos/configuration.nix
67
-
# Generate the GRUB menu.
68
-
chroot /mnt ${config.system.build.toplevel}/bin/switch-to-configuration boot
70
-
umount /mnt/proc /mnt/dev /mnt/sys
22
+
../profiles/qemu-guest.nix
23
+
../profiles/headless.nix
fileSystems."/".device = "/dev/disk/by-label/nixos";
boot.kernelParams = [ "console=ttyS0" ];
79
-
boot.loader.grub.version = 2;
boot.loader.grub.device = "/dev/vda";
boot.loader.grub.timeout = 0;
34
+
services.openssh.enable = true;
35
+
services.openssh.permitRootLogin = "without-password";
# 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
# mount. Also, "move" /nix to /ephemeral0 by layering a unionfs-fuse
# mount on top of it so we have a lot more space for Nix operations.
boot.initrd.postMountCommands =
···
boot.initrd.supportedFilesystems = [ "unionfs-fuse" ];
111
-
# Allow root logins only using the SSH key that the user specified
112
-
# at instance creation time.
113
-
services.openssh.enable = true;
114
-
services.openssh.permitRootLogin = "without-password";