3
0
Fork 0
forked from mirrors/nixpkgs
nixpkgs/pkgs/build-support/vm/windows/default.nix
aszlig c731467e2c
vm/windows: Split install into several stages.
These stages are in particular:

 * Install of the bare Windows VM with Cygwin and shut down.
 * Boot up the same VM again without the installation media and dump the
   VMs memory to state.gz.
 * Resume from state.gz and build whatever we want to build.

Every single stage involves a new "controller", which is more like an
abstraction on the Nix side that constructs the madness described in
276b72fb93.

Signed-off-by: aszlig <aszlig@redmoonstudios.org>
2014-02-26 04:51:56 +01:00

50 lines
1.1 KiB
Nix

let
inherit (import <nixpkgs> {}) lib stdenv requireFile writeText qemu;
winISO = /path/to/iso/XXX;
installedVM = import ./install {
isoFile = winISO;
productKey = "XXX";
};
runInVM = img: attrs: import ./controller (attrs // {
inherit (installedVM) sshKey;
qemuArgs = attrs.qemuArgs or [] ++ [
"-boot order=c"
"-drive file=${img},index=0,media=disk"
];
});
runAndSuspend = runInVM "winvm.img" {
suspendTo = "state.gz";
};
suspendedVM = stdenv.mkDerivation {
name = "cygwin-suspended-vm";
buildCommand = ''
${qemu}/bin/qemu-img create \
-b "${installedVM}/disk.img" \
-f qcow2 winvm.img
${runAndSuspend}
ensureDir "$out"
cp winvm.img "$out/disk.img"
cp state.gz "$out/state.gz"
'';
};
resumeAndRun = command: runInVM "${suspendedVM}/disk.img" {
resumeFrom = "${suspendedVM}/state.gz";
qemuArgs = lib.singleton "-snapshot";
inherit command;
};
runFromSuspended = command: stdenv.mkDerivation {
name = "cygwin-vm-run";
buildCommand = ''
${resumeAndRun command}
'';
};
in runFromSuspended "uname -a"