blob: d766cbcf8e3a1f87ec6be50f8e7c37ef51000d79 (
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
|
{ isoFile
, productKey
}:
let
inherit (import <nixpkgs> {}) lib stdenv runCommand openssh qemu;
bootstrapAfterLogin = runCommand "bootstrap.sh" {} ''
cat > "$out" <<EOF
mkdir -p ~/.ssh
cat > ~/.ssh/authorized_keys <<PUBKEY
$(cat "${cygwinSshKey}/key.pub")
PUBKEY
ssh-host-config -y -c 'binmode ntsec' -w dummy
net use S: '\\192.168.0.2\nixstore'
mkdir -p /nix/store
echo "/cygdrives/s /nix/store none bind 0 0" >> /etc/fstab
shutdown -s now
EOF
'';
cygwinSshKey = stdenv.mkDerivation {
name = "snakeoil-ssh-cygwin";
buildCommand = ''
ensureDir "$out"
${openssh}/bin/ssh-keygen -t ecdsa -f "$out/key" -N ""
'';
};
sshKey = "${cygwinSshKey}/key";
packages = [ "openssh" "shutdown" ];
instfloppy = import ./unattended-image.nix {
cygwinPackages = packages;
inherit productKey;
};
cygiso = import ../cygwin-iso {
inherit packages;
extraContents = lib.singleton {
source = bootstrapAfterLogin;
target = "bootstrap.sh";
};
};
installController = import ../controller {
inherit sshKey;
installMode = true;
qemuArgs = [
"-boot order=c,once=d"
"-drive file=${instfloppy},readonly,index=0,if=floppy"
"-drive file=winvm.img,index=0,media=disk"
"-drive file=${isoFile},index=1,media=cdrom"
"-drive file=${cygiso}/iso/cd.iso,index=2,media=cdrom"
];
};
in stdenv.mkDerivation {
name = "cygwin-base-vm";
buildCommand = ''
${qemu}/bin/qemu-img create -f qcow2 winvm.img 2G
${installController}
ensureDir "$out"
cp winvm.img "$out/disk.img"
'';
passthru = {
inherit sshKey;
};
}
|