From 687e0059d552d39b5bd3cf1218026ed96c2c4adc Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Tue, 8 Oct 2013 15:40:48 +0200 Subject: [PATCH] Generate a VirtualBox appliance (in OVF format) instead of a disk image --- modules/virtualisation/virtualbox-image.nix | 26 +++++++++++++++++++++ release-combined.nix | 2 +- release.nix | 17 +++++++------- 3 files changed, 35 insertions(+), 10 deletions(-) diff --git a/modules/virtualisation/virtualbox-image.nix b/modules/virtualisation/virtualbox-image.nix index bd14a7ffda00..306367d0ef52 100644 --- a/modules/virtualisation/virtualbox-image.nix +++ b/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; diff --git a/release-combined.nix b/release-combined.nix index 07c0a677722f..9b914506215d 100644 --- a/release-combined.nix +++ b/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) diff --git a/release.nix b/release.nix index 63488d712bbd..06fb43bf6d62 100644 --- a/release.nix +++ b/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 { 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 '' # */ );