vm/windows: Factor out bootstrapping process.
This now isolates the vmTools integration from the bootstrap process and thus removes our fixed Windows ISO and product key. The latter can now be provided by an attribute "windowsImage" to runInWindowsVM. Signed-off-by: aszlig <aszlig@redmoonstudios.org>
This commit is contained in:
parent
e40f41e505
commit
d8e66722a3
61
pkgs/build-support/vm/windows/bootstrap.nix
Normal file
61
pkgs/build-support/vm/windows/bootstrap.nix
Normal file
@ -0,0 +1,61 @@
|
||||
{ isoFile, productKey }:
|
||||
|
||||
let
|
||||
inherit (import <nixpkgs> {}) lib stdenv qemu;
|
||||
in rec {
|
||||
installedVM = import ./install {
|
||||
inherit isoFile productKey;
|
||||
};
|
||||
|
||||
runInVM = img: attrs: import ./controller (attrs // {
|
||||
inherit (installedVM) sshKey;
|
||||
qemuArgs = attrs.qemuArgs or [] ++ [
|
||||
"-boot order=c"
|
||||
"-drive file=${img},index=0,media=disk"
|
||||
];
|
||||
});
|
||||
|
||||
runAndSuspend = let
|
||||
drives = {
|
||||
s = {
|
||||
source = "nixstore";
|
||||
target = "/nix/store";
|
||||
};
|
||||
x = {
|
||||
source = "xchg";
|
||||
target = "/tmp/xchg";
|
||||
};
|
||||
};
|
||||
|
||||
genDriveCmds = letter: { source, target }: [
|
||||
"net use ${letter}: '\\\\192.168.0.2\\${source}' /persistent:yes"
|
||||
"mkdir -p '${target}'"
|
||||
"mount -o bind '/cygdrive/${letter}' '${target}'"
|
||||
"echo '/cygdrive/${letter} ${target} none bind 0 0' >> /etc/fstab"
|
||||
];
|
||||
in runInVM "winvm.img" {
|
||||
command = lib.concatStringsSep " && " ([
|
||||
"net config server /autodisconnect:-1"
|
||||
] ++ lib.concatLists (lib.mapAttrsToList genDriveCmds drives));
|
||||
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;
|
||||
};
|
||||
}
|
@ -1,64 +1,5 @@
|
||||
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 = let
|
||||
drives = {
|
||||
s = {
|
||||
source = "nixstore";
|
||||
target = "/nix/store";
|
||||
};
|
||||
x = {
|
||||
source = "xchg";
|
||||
target = "/tmp/xchg";
|
||||
};
|
||||
};
|
||||
|
||||
genDriveCmds = letter: { source, target }: [
|
||||
"net use ${letter}: '\\\\192.168.0.2\\${source}' /persistent:yes"
|
||||
"mkdir -p '${target}'"
|
||||
"mount -o bind '/cygdrive/${letter}' '${target}'"
|
||||
"echo '/cygdrive/${letter} ${target} none bind 0 0' >> /etc/fstab"
|
||||
];
|
||||
in runInVM "winvm.img" {
|
||||
command = lib.concatStringsSep " && " ([
|
||||
"net config server /autodisconnect:-1"
|
||||
] ++ lib.concatLists (lib.mapAttrsToList genDriveCmds drives));
|
||||
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;
|
||||
};
|
||||
inherit (import <nixpkgs> {}) lib stdenv;
|
||||
|
||||
builder = ''
|
||||
source /tmp/xchg/saved-env 2> /dev/null || true
|
||||
@ -77,10 +18,13 @@ in {
|
||||
shell = "/bin/sh";
|
||||
};
|
||||
};
|
||||
in lib.overrideDerivation drv (attrs: {
|
||||
in lib.overrideDerivation drv (attrs: let
|
||||
bootstrap = import ./bootstrap.nix attrs.windowsImage;
|
||||
in {
|
||||
requiredSystemFeatures = [ "kvm" ];
|
||||
buildur = "${stdenv.shell}";
|
||||
args = ["-e" (resumeAndRun builder)];
|
||||
args = ["-e" (bootstrap.resumeAndRun builder)];
|
||||
windowsImage = bootstrap.suspendedVM;
|
||||
origArgs = attrs.args;
|
||||
origBuilder = if attrs.builder == attrs.stdenv.shell
|
||||
then "/bin/sh"
|
||||
|
Loading…
Reference in New Issue
Block a user