1
0
Fork 0
nix-scripts/artiq/windows/qemu.nix

54 lines
1.5 KiB
Nix
Raw Normal View History

{ pkgs,
diskImage,
qemuMem,
sshUser ? "user",
sshPassword ? "user",
}:
with pkgs;
let
qemu-img = "${qemu_kvm}/bin/qemu-img";
2019-04-18 23:34:09 +08:00
runQemu = isolateNetwork: forwardedPorts: extraArgs:
let
restrict =
if isolateNetwork
then "on"
else "off";
# use socat instead of `tcp:…` to allow multiple connections
2019-04-18 23:34:09 +08:00
guestfwds =
builtins.concatStringsSep ""
(map ({ listenAddr, targetAddr, port }:
",guestfwd=tcp:${listenAddr}:${toString port}-cmd:${socat}/bin/socat\\ -\\ tcp:${targetAddr}:${toString port}"
2019-04-18 23:34:09 +08:00
) forwardedPorts);
args = [
"-enable-kvm"
"-m" qemuMem
"-bios" "${OVMF.fd}/FV/OVMF.fd"
2019-04-18 23:34:09 +08:00
"-netdev" "user,id=n1,net=192.168.1.0/24,restrict=${restrict},hostfwd=tcp::2022-:22${guestfwds}"
"-device" "e1000,netdev=n1"
];
argStr = builtins.concatStringsSep " " (args ++ extraArgs);
2019-04-18 21:55:02 +08:00
in "${qemu_kvm}/bin/qemu-system-x86_64 ${argStr}";
2019-04-18 23:40:03 +08:00
sshOpts = "-o StrictHostKeyChecking=accept-new -o UserKnownHostsFile=/dev/null";
ssh = cmd: ''
echo ssh windows '${cmd}'
${sshpass}/bin/sshpass -p${sshPassword} -- \
${openssh}/bin/ssh -np 2022 ${sshOpts} \
${sshUser}@localhost \
'${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 ssh scp;
inputs = [ qemu_kvm openssh sshpass ];
}