Skip to content

Commit

Permalink
Merge pull request #7 from MatthewCroughan/mc/sshPort
Browse files Browse the repository at this point in the history
makeDarwinImage: test sshPort is being set and used in nixosModule
  • Loading branch information
MatthewCroughan authored Dec 14, 2023
2 parents 1c05db4 + 2dec745 commit 5c69277
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
2 changes: 1 addition & 1 deletion makeDarwinImage/module.nix
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ in
config = let
run-macos = cfg.package.makeRunScript {
extraQemuFlags = [ "-vnc ${cfg.vncListenAddr}:${toString cfg.vncDisplayNumber}" ] ++ cfg.extraQemuFlags;
inherit (cfg) threads cores sockets mem;
inherit (cfg) threads cores sockets mem sshPort;
};
in lib.mkIf cfg.enable {
networking.firewall.allowedTCPPorts = lib.optionals cfg.openFirewall [ (5900 + cfg.vncDisplayNumber) cfg.sshPort ];
Expand Down
3 changes: 2 additions & 1 deletion makeDarwinImage/run.nix
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
, threads ? 4
, cores ? 2
, sockets ? 1
, sshPort ? 2222
, mem ? "4G"
, diskImage ? (makeDarwinImage {})
, extraQemuFlags ? []
Expand Down Expand Up @@ -36,7 +37,7 @@ writeShellScriptBin "run-macOS.sh" ''
-device ich9-intel-hda -device hda-duplex
-drive id=OpenCoreBoot,if=virtio,snapshot=on,readonly=on,format=qcow2,file="${OpenCoreBoot}"
-drive id=MacHDD,if=virtio,file="macos-ventura.qcow2",format=qcow2
-netdev user,id=net0,hostfwd=tcp::2222-:22 -device virtio-net-pci,netdev=net0,id=net0,mac=52:54:00:c9:18:27
-netdev user,id=net0,hostfwd=tcp::${toString sshPort}-:22 -device virtio-net-pci,netdev=net0,id=net0,mac=52:54:00:c9:18:27
#-monitor stdio
-device virtio-vga
${lib.concatStringsSep " " extraQemuFlags}
Expand Down
13 changes: 7 additions & 6 deletions makeDarwinImage/vm-test.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
nixosTest {
name = "macos-ventura";
nodes = {
machine = { ... }: {
machine = { config, ... }: {
virtualisation.memorySize = 6144;
imports = [ nixosModule ];
environment.systemPackages = [ openssh sshpass ];
networking.firewall.allowedTCPPorts = [ 5900 2222 ];
networking.firewall.allowedTCPPorts = [ 5900 "${toString config.services.macos-ventura.sshPort}"];
networking.firewall.enable = false;
services.macos-ventura = {
enable = true;
Expand All @@ -15,26 +15,27 @@ nixosTest {
mem = "4G";
vncListenAddr = "0.0.0.0";
extraQemuFlags = [ "-nographic" ];
sshPort = 2021;
};
};
};
testScript = let
testScript = { nodes, ... }: let
sshProductVersion = writeShellScript "foo" ''
# Wait until a successful ssh-keyscan
while ! ssh-keyscan -p 2222 127.0.0.1; do
while ! ssh-keyscan -p ${toString nodes.machine.config.services.macos-ventura.sshPort} 127.0.0.1; do
sleep 3
echo "SSH not ready" >&2
done
echo "SSH ready!" >&2
# Should return stdout like "ProductVersion: 13.6"
sshpass -p admin ssh -o StrictHostKeyChecking=no -p 2222 [email protected] sw_vers | grep ProductVersion | awk '{print $2}'
sshpass -p admin ssh -o StrictHostKeyChecking=no -p ${toString nodes.machine.config.services.macos-ventura.sshPort} [email protected] sw_vers | grep ProductVersion | awk '{print $2}'
'';
in ''
start_all()
machine.wait_for_unit("multi-user.target")
machine.wait_for_unit("macos-ventura.service")
machine.wait_for_open_port(2222)
machine.wait_for_open_port(${toString nodes.machine.config.services.macos-ventura.sshPort})
with subtest("Check that the macOS Ventura machine returns ProductVersion 13.6 via SSH"):
assert "13.6" in machine.succeed("${sshProductVersion}")
'';
Expand Down

0 comments on commit 5c69277

Please sign in to comment.