blob: 2ecadbae7cfbe1e74569e0ff80554a724f1404c1 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
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"
|