Combine OVA generation steps
Previously this was done in three derivations (one to build the raw disk image, one to convert to OVA, one to add a hydra-build-products file). Now it's done in one step to reduce the amount of copying to/from S3. In particular, not uploading the raw disk image prevents us from hitting hydra-queue-runner's size limit of 2 GiB.
This commit is contained in:
parent
84f33c6edc
commit
5cc7bcda30
@ -22,12 +22,13 @@
|
|||||||
, # Shell code executed after the VM has finished.
|
, # Shell code executed after the VM has finished.
|
||||||
postVM ? ""
|
postVM ? ""
|
||||||
|
|
||||||
|
, name ? "nixos-disk-image"
|
||||||
}:
|
}:
|
||||||
|
|
||||||
with lib;
|
with lib;
|
||||||
|
|
||||||
pkgs.vmTools.runInLinuxVM (
|
pkgs.vmTools.runInLinuxVM (
|
||||||
pkgs.runCommand "nixos-disk-image"
|
pkgs.runCommand name
|
||||||
{ preVM =
|
{ preVM =
|
||||||
''
|
''
|
||||||
mkdir $out
|
mkdir $out
|
||||||
|
@ -22,7 +22,9 @@ in {
|
|||||||
|
|
||||||
config = {
|
config = {
|
||||||
|
|
||||||
system.build.virtualBoxImage = import ../../lib/make-disk-image.nix {
|
system.build.virtualBoxOVA = import ../../lib/make-disk-image.nix {
|
||||||
|
name = "nixos-ova-${config.system.nixosLabel}-${pkgs.stdenv.system}";
|
||||||
|
|
||||||
inherit pkgs lib config;
|
inherit pkgs lib config;
|
||||||
partitioned = true;
|
partitioned = true;
|
||||||
diskSize = cfg.baseImageSize;
|
diskSize = cfg.baseImageSize;
|
||||||
@ -37,19 +39,13 @@ in {
|
|||||||
postVM =
|
postVM =
|
||||||
''
|
''
|
||||||
echo "creating VirtualBox disk image..."
|
echo "creating VirtualBox disk image..."
|
||||||
${pkgs.vmTools.qemu}/bin/qemu-img convert -f raw -O vdi $diskImage $out/disk.vdi
|
${pkgs.vmTools.qemu}/bin/qemu-img convert -f raw -O vdi $diskImage disk.vdi
|
||||||
rm $diskImage
|
rm $diskImage
|
||||||
'';
|
|
||||||
};
|
|
||||||
|
|
||||||
system.build.virtualBoxOVA = pkgs.runCommand "virtualbox-ova"
|
|
||||||
{ buildInputs = [ pkgs.linuxPackages.virtualbox ];
|
|
||||||
vmName = "NixOS ${config.system.nixosLabel} (${pkgs.stdenv.system})";
|
|
||||||
fileName = "nixos-image-${config.system.nixosLabel}-${pkgs.stdenv.system}.ova";
|
|
||||||
}
|
|
||||||
''
|
|
||||||
echo "creating VirtualBox VM..."
|
echo "creating VirtualBox VM..."
|
||||||
export HOME=$PWD
|
export HOME=$PWD
|
||||||
|
export PATH=${pkgs.linuxPackages.virtualbox}/bin:$PATH
|
||||||
|
vmName="NixOS ${config.system.nixosLabel} (${pkgs.stdenv.system})"
|
||||||
VBoxManage createvm --name "$vmName" --register \
|
VBoxManage createvm --name "$vmName" --register \
|
||||||
--ostype ${if pkgs.stdenv.system == "x86_64-linux" then "Linux26_64" else "Linux26"}
|
--ostype ${if pkgs.stdenv.system == "x86_64-linux" then "Linux26_64" else "Linux26"}
|
||||||
VBoxManage modifyvm "$vmName" \
|
VBoxManage modifyvm "$vmName" \
|
||||||
@ -61,12 +57,17 @@ in {
|
|||||||
--usb on --mouse usbtablet
|
--usb on --mouse usbtablet
|
||||||
VBoxManage storagectl "$vmName" --name SATA --add sata --portcount 4 --bootable on --hostiocache on
|
VBoxManage storagectl "$vmName" --name SATA --add sata --portcount 4 --bootable on --hostiocache on
|
||||||
VBoxManage storageattach "$vmName" --storagectl SATA --port 0 --device 0 --type hdd \
|
VBoxManage storageattach "$vmName" --storagectl SATA --port 0 --device 0 --type hdd \
|
||||||
--medium ${config.system.build.virtualBoxImage}/disk.vdi
|
--medium disk.vdi
|
||||||
|
|
||||||
echo "exporting VirtualBox VM..."
|
echo "exporting VirtualBox VM..."
|
||||||
mkdir -p $out
|
mkdir -p $out
|
||||||
VBoxManage export "$vmName" --output "$out/$fileName"
|
fn="$out/nixos-${config.system.nixosLabel}-${pkgs.stdenv.system}.ova"
|
||||||
|
VBoxManage export "$vmName" --output "$fn"
|
||||||
|
|
||||||
|
mkdir -p $out/nix-support
|
||||||
|
echo "file ova $fn" >> $out/nix-support/hydra-build-products
|
||||||
'';
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
fileSystems."/".device = "/dev/disk/by-label/nixos";
|
fileSystems."/".device = "/dev/disk/by-label/nixos";
|
||||||
|
|
||||||
|
@ -150,31 +150,13 @@ in rec {
|
|||||||
|
|
||||||
with import nixpkgs { inherit system; };
|
with import nixpkgs { inherit system; };
|
||||||
|
|
||||||
let
|
hydraJob ((import lib/eval-config.nix {
|
||||||
|
|
||||||
config = (import lib/eval-config.nix {
|
|
||||||
inherit system;
|
inherit system;
|
||||||
modules =
|
modules =
|
||||||
[ versionModule
|
[ versionModule
|
||||||
./modules/installer/virtualbox-demo.nix
|
./modules/installer/virtualbox-demo.nix
|
||||||
];
|
];
|
||||||
}).config;
|
}).config.system.build.virtualBoxOVA)
|
||||||
|
|
||||||
in
|
|
||||||
# Declare the OVA as a build product so that it shows up in Hydra.
|
|
||||||
hydraJob (runCommand "nixos-ova-${config.system.nixosVersion}-${system}"
|
|
||||||
{ meta = {
|
|
||||||
description = "NixOS VirtualBox appliance (${system})";
|
|
||||||
maintainers = maintainers.eelco;
|
|
||||||
};
|
|
||||||
ova = config.system.build.virtualBoxOVA;
|
|
||||||
preferLocalBuild = true;
|
|
||||||
}
|
|
||||||
''
|
|
||||||
mkdir -p $out/nix-support
|
|
||||||
fn=$(echo $ova/*.ova)
|
|
||||||
echo "file ova $fn" >> $out/nix-support/hydra-build-products
|
|
||||||
'') # */
|
|
||||||
|
|
||||||
);
|
);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user