2019-04-14 05:33:31 +08:00
|
|
|
{ pkgs,
|
|
|
|
diskImage,
|
|
|
|
qemuMem,
|
|
|
|
sshUser ? "user",
|
|
|
|
sshPassword ? "user",
|
|
|
|
}:
|
|
|
|
|
|
|
|
with pkgs;
|
|
|
|
|
|
|
|
let
|
|
|
|
qemu = qemu_kvm;
|
|
|
|
qemu-img = "${qemu}/bin/qemu-img";
|
2019-04-15 02:52:09 +08:00
|
|
|
runQemu = isolateNetwork: extraArgs:
|
2019-04-14 05:33:31 +08:00
|
|
|
let
|
2019-04-15 02:52:09 +08:00
|
|
|
restrict =
|
|
|
|
if isolateNetwork
|
|
|
|
then "on"
|
|
|
|
else "off";
|
2019-04-14 05:33:31 +08:00
|
|
|
args = [
|
|
|
|
"-enable-kvm"
|
|
|
|
"-m" qemuMem
|
|
|
|
"-bios" "${OVMF.fd}/FV/OVMF.fd"
|
2019-04-15 02:52:09 +08:00
|
|
|
"-netdev" "user,id=n1,restrict=${restrict},hostfwd=tcp::2022-:22"
|
|
|
|
"-device" "e1000,netdev=n1"
|
2019-04-14 05:33:31 +08:00
|
|
|
];
|
|
|
|
argStr = builtins.concatStringsSep " " (args ++ extraArgs);
|
|
|
|
in "qemu-system-x86_64 ${argStr}";
|
|
|
|
|
|
|
|
escape = builtins.replaceStrings [ "\\" ] [ "\\\\" ];
|
|
|
|
sshOpts = "-o StrictHostKeyChecking=accept-new -o UserKnownHostsFile=/tmp/known_hosts";
|
|
|
|
ssh = cmd: ''
|
|
|
|
echo ssh windows '${escape cmd}'
|
|
|
|
${sshpass}/bin/sshpass -p${sshPassword} -- \
|
|
|
|
${openssh}/bin/ssh -np 2022 ${sshOpts} \
|
|
|
|
${sshUser}@localhost \
|
|
|
|
'${escape cmd}'
|
|
|
|
'';
|
|
|
|
scp = src: target: ''
|
|
|
|
echo "Copy ${src} to ${target}"
|
|
|
|
${sshpass}/bin/sshpass -p${sshPassword} -- \
|
|
|
|
${openssh}/bin/scp -P 2022 ${sshOpts} \
|
|
|
|
"${src}" "${sshUser}@localhost:${target}"
|
|
|
|
'';
|
|
|
|
|
|
|
|
in
|
|
|
|
{
|
|
|
|
inherit qemu-img runQemu escape ssh scp;
|
|
|
|
inputs = [ qemu openssh sshpass ];
|
|
|
|
}
|