2014-02-26 04:43:34 +00:00
|
|
|
{ stdenv, fetchurl, vmTools, writeScript, writeText, runCommand, makeInitrd
|
2016-10-30 01:52:47 +01:00
|
|
|
, python, perl, coreutils, dosfstools, gzip, mtools, netcat-gnu, openssh, qemu
|
2014-05-07 05:48:53 +01:00
|
|
|
, samba, socat, vde2, cdrkit, pathsFromGraph, gnugrep
|
2014-02-26 04:43:34 +00:00
|
|
|
}:
|
|
|
|
|
2014-03-04 07:13:22 +00:00
|
|
|
{ isoFile, productKey, arch ? null }:
|
2014-02-17 01:10:00 +00:00
|
|
|
|
2014-02-26 04:43:34 +00:00
|
|
|
with stdenv.lib;
|
|
|
|
|
2014-02-17 01:10:00 +00:00
|
|
|
let
|
2014-02-26 04:43:34 +00:00
|
|
|
controller = import ./controller {
|
|
|
|
inherit stdenv writeScript vmTools makeInitrd;
|
2016-10-30 01:52:47 +01:00
|
|
|
inherit samba vde2 openssh socat netcat-gnu coreutils gzip gnugrep;
|
2014-02-26 04:43:34 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
mkCygwinImage = import ./cygwin-iso {
|
|
|
|
inherit stdenv fetchurl runCommand python perl cdrkit pathsFromGraph;
|
2014-03-04 07:13:22 +00:00
|
|
|
arch = let
|
|
|
|
defaultArch = if stdenv.is64bit then "x86_64" else "i686";
|
|
|
|
in if arch == null then defaultArch else arch;
|
2014-02-26 04:43:34 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
installer = import ./install {
|
|
|
|
inherit controller mkCygwinImage;
|
|
|
|
inherit stdenv runCommand openssh qemu writeText dosfstools mtools;
|
|
|
|
};
|
2014-02-17 01:10:00 +00:00
|
|
|
in rec {
|
2014-02-26 04:43:34 +00:00
|
|
|
installedVM = installer {
|
2014-02-17 01:10:00 +00:00
|
|
|
inherit isoFile productKey;
|
|
|
|
};
|
|
|
|
|
2014-02-26 04:43:34 +00:00
|
|
|
runInVM = img: attrs: controller (attrs // {
|
2014-02-17 01:10:00 +00:00
|
|
|
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" {
|
2014-02-26 04:43:34 +00:00
|
|
|
command = concatStringsSep " && " ([
|
2014-02-17 01:10:00 +00:00
|
|
|
"net config server /autodisconnect:-1"
|
2014-02-26 04:43:34 +00:00
|
|
|
] ++ concatLists (mapAttrsToList genDriveCmds drives));
|
2014-02-17 01:10:00 +00:00
|
|
|
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}
|
2014-06-30 13:56:10 +01:00
|
|
|
mkdir -p "$out"
|
2014-02-17 01:10:00 +00:00
|
|
|
cp winvm.img "$out/disk.img"
|
|
|
|
cp state.gz "$out/state.gz"
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
resumeAndRun = command: runInVM "${suspendedVM}/disk.img" {
|
|
|
|
resumeFrom = "${suspendedVM}/state.gz";
|
2014-02-26 04:43:34 +00:00
|
|
|
qemuArgs = singleton "-snapshot";
|
2014-02-17 01:10:00 +00:00
|
|
|
inherit command;
|
|
|
|
};
|
|
|
|
}
|