Skip to content
Browse files

Generate a VirtualBox appliance (in OVF format) instead of a disk image

  • Loading branch information...
1 parent 5c17d7d commit 687e0059d552d39b5bd3cf1218026ed96c2c4adc @edolstra edolstra committed Oct 8, 2013
Showing with 35 additions and 10 deletions.
  1. +26 −0 modules/virtualisation/virtualbox-image.nix
  2. +1 −1 release-combined.nix
  3. +8 −9 release.nix
View
26 modules/virtualisation/virtualbox-image.nix
@@ -16,6 +16,7 @@ with pkgs.lib;
'';
postVM =
''
+ echo "creating VirtualBox disk image..."
${pkgs.vmTools.qemu}/bin/qemu-img convert -f raw -O vdi $diskImage $out/disk.vdi
rm $diskImage
'';
@@ -74,6 +75,31 @@ with pkgs.lib;
''
);
+ system.build.virtualBoxOVA = pkgs.runCommand "virtualbox-ova"
+ { buildInputs = [ pkgs.linuxPackages.virtualbox ];
+ vmName = "NixOS ${config.system.nixosVersion} (${pkgs.stdenv.system})";
+ fileName = "nixos-${config.system.nixosVersion}-${pkgs.stdenv.system}.ova";
+ }
+ ''
+ echo "creating VirtualBox VM..."
+ export HOME=$PWD
+ VBoxManage createvm --name "$vmName" --register \
+ --ostype ${if pkgs.stdenv.system == "x86_64-linux" then "Linux26_64" else "Linux26"}
+ VBoxManage modifyvm "$vmName" \
+ --memory 1536 --acpi on --vram 10 \
+ --nictype1 virtio --nic1 nat \
+ --audiocontroller ac97 --audio alsa \
+ --rtcuseutc on \
+ --usb on --mouse usbtablet
+ VBoxManage storagectl "$vmName" --name SATA --add sata --sataportcount 4 --bootable on --hostiocache on
+ VBoxManage storageattach "$vmName" --storagectl SATA --port 0 --device 0 --type hdd \
+ --medium ${config.system.build.virtualBoxImage}/disk.vdi
+
+ echo "exporting VirtualBox VM..."
+ mkdir -p $out
+ VBoxManage export "$vmName" --output "$out/$fileName"
+ '';
+
fileSystems."/".device = "/dev/disk/by-label/nixos";
boot.loader.grub.version = 2;
View
2 release-combined.nix
@@ -42,7 +42,7 @@ in rec {
(all nixos.iso_minimal)
(all nixos.iso_graphical)
- (all nixos.vdi)
+ (all nixos.ova)
(all nixos.tests.firefox)
(all nixos.tests.firewall)
View
17 release.nix
@@ -174,8 +174,8 @@ in {
});
- # A bootable VirtualBox image. FIXME: generate a OVF appliance?
- vdi = pkgs.lib.genAttrs systems (system:
+ # A bootable VirtualBox virtual appliance as an OVA file (i.e. packaged OVF).
+ ova = pkgs.lib.genAttrs systems (system:
with import <nixpkgs> { inherit system; };
@@ -190,19 +190,18 @@ in {
}).config;
in
- # Declare the VDI as a build product so that it shows up in Hydra.
- runCommand "nixos-vdi-${config.system.nixosVersion}-${system}"
+ # Declare the OVA as a build product so that it shows up in Hydra.
+ runCommand "nixos-ova-${config.system.nixosVersion}-${system}"
{ meta = {
- description = "NixOS VirtualBox disk image (${system})";
+ description = "NixOS VirtualBox appliance (${system})";
maintainers = lib.maintainers.eelco;
};
- vdi = config.system.build.virtualBoxImage;
+ ova = config.system.build.virtualBoxOVA;
}
''
mkdir -p $out/nix-support
- fn=$out/nixos-${config.system.nixosVersion}-${system}.vdi.xz
- xz < $vdi/*.vdi > $fn
- echo "file vdi $fn" >> $out/nix-support/hydra-build-products
+ fn=$(echo $ova/*.ova)
+ echo "file ova $fn" >> $out/nix-support/hydra-build-products
'' # */
);

0 comments on commit 687e005

Please sign in to comment.
Something went wrong with that request. Please try again.