lol

nova-image: use make-disk-image.nix

+25 -79
+1 -1
nixos/lib/make-disk-image.nix
··· 110 110 umount /mnt/proc /mnt/dev /mnt/sys 111 111 umount /mnt 112 112 113 - # Do an fsck to make sure resize2fs works. 113 + # Do a fsck to make sure resize2fs works. 114 114 fsck.${fsType} -f -y $rootDisk 115 115 '' 116 116 )
-5
nixos/modules/virtualisation/nova-config.nix
··· 1 - { config, pkgs, modulesPath, ... }: 2 - 3 - { 4 - imports = [ "${modulesPath}/virtualisation/nova-image.nix" ]; 5 - }
+24 -73
nixos/modules/virtualisation/nova-image.nix
··· 1 + # Usage: 2 + # $ NIXOS_CONFIG=`pwd`/nixos/modules/virtualisation/nova-image.nix nix-build '<nixpkgs/nixos>' -A config.system.build.novaImage 3 + 1 4 { config, lib, pkgs, ... }: 2 5 3 6 with lib; 4 7 5 8 { 6 - imports = [ ../profiles/qemu-guest.nix ../profiles/headless.nix ./ec2-data.nix ]; 7 - 8 - system.build.novaImage = 9 - pkgs.vmTools.runInLinuxVM ( 10 - pkgs.runCommand "nova-image" 11 - { preVM = 12 - '' 13 - mkdir $out 14 - diskImage=$out/image 15 - ${pkgs.vmTools.qemu}/bin/qemu-img create -f raw $diskImage "4G" 16 - mv closure xchg/ 17 - ''; 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; 11 + partitioned = true; 12 + diskSize = 1 * 1024; 13 + configFile = pkgs.writeText "configuration.nix" 14 + '' 15 + { 16 + imports = [ <nixpkgs/nixos/modules/virtualisation/nova-image.nix> ]; 21 17 } 22 - '' 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 18 + ''; 19 + }; 28 20 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 32 - mkdir /mnt 33 - mount /dev/vda1 /mnt 34 - 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 40 - 41 - # Copy all paths in the closure to the filesystem. 42 - storePaths=$(perl ${pkgs.pathsFromGraph} /tmp/xchg/closure) 43 - 44 - mkdir -p /mnt/nix/store 45 - ${pkgs.rsync}/bin/rsync -av $storePaths /mnt/nix/store/ 46 - 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 "" 50 - 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} 54 - 55 - # `nixos-rebuild' requires an /etc/NIXOS. 56 - mkdir -p /mnt/etc 57 - touch /mnt/etc/NIXOS 58 - 59 - # `switch-to-configuration' requires a /bin/sh 60 - mkdir -p /mnt/bin 61 - ln -s ${config.system.build.binsh}/bin/sh /mnt/bin/sh 62 - 63 - # Install a configuration.nix. 64 - mkdir -p /mnt/etc/nixos 65 - cp ${./nova-config.nix} /mnt/etc/nixos/configuration.nix 66 - 67 - # Generate the GRUB menu. 68 - chroot /mnt ${config.system.build.toplevel}/bin/switch-to-configuration boot 69 - 70 - umount /mnt/proc /mnt/dev /mnt/sys 71 - umount /mnt 72 - '' 73 - ); 21 + imports = [ 22 + ../profiles/qemu-guest.nix 23 + ../profiles/headless.nix 24 + ./ec2-data.nix 25 + ]; 74 26 75 27 fileSystems."/".device = "/dev/disk/by-label/nixos"; 76 28 77 29 boot.kernelParams = [ "console=ttyS0" ]; 78 - 79 - boot.loader.grub.version = 2; 80 30 boot.loader.grub.device = "/dev/vda"; 81 31 boot.loader.grub.timeout = 0; 82 32 33 + # Allow root logins 34 + services.openssh.enable = true; 35 + services.openssh.permitRootLogin = "without-password"; 36 + 83 37 # Put /tmp and /var on /ephemeral0, which has a lot more space. 84 38 # Unfortunately we can't do this with the `fileSystems' option 85 39 # because it has no support for creating the source of a bind 86 40 # mount. Also, "move" /nix to /ephemeral0 by layering a unionfs-fuse 87 41 # mount on top of it so we have a lot more space for Nix operations. 42 + 88 43 /* 89 44 boot.initrd.postMountCommands = 90 45 '' ··· 106 61 ''; 107 62 108 63 boot.initrd.supportedFilesystems = [ "unionfs-fuse" ]; 109 - */ 64 + */ 110 65 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"; 115 66 }