anchor.diff:      };
   
       testSubs = ''
  -      my ${"$" + name}_sharepath = '${sharePath}';
  -
  -      sub checkRunning_${name} {
  -        my $cmd = 'VBoxManage list runningvms | grep -q "^\"${name}\""';
  -        my ($status, $out) = $machine->execute(ru $cmd);
  -        return $status == 0;
  -      }
  -
  -      sub cleanup_${name} {
  -        $machine->execute(ru "VBoxManage controlvm ${name} poweroff")
  -          if checkRunning_${name};
  -        $machine->succeed("rm -rf ${sharePath}");
  -        $machine->succeed("mkdir -p ${sharePath}");
  -        $machine->succeed("chown alice.users ${sharePath}");
  -      }
  -
  -      sub createVM_${name} {
  -        vbm("createvm --name ${name} ${createFlags}");
  -        vbm("modifyvm ${name} ${vmFlags}");
  -        vbm("setextradata ${name} VBoxInternal/PDM/HaltOnReset 1");
  -        vbm("storagectl ${name} ${controllerFlags}");
  -        vbm("storageattach ${name} ${diskFlags}");
  -        vbm("sharedfolder add ${name} ${sharedFlags}");
  -        vbm("sharedfolder add ${name} ${nixstoreFlags}");
  -        cleanup_${name};
  -
  -        ${mkLog "$HOME/VirtualBox VMs/${name}/Logs/VBox.log" "HOST-${name}"}
  -      }
  -
  -      sub destroyVM_${name} {
  -        cleanup_${name};
  -        vbm("unregistervm ${name} --delete");
  -      }
  -
  -      sub waitForVMBoot_${name} {
  -        $machine->execute(ru(
  -          'set -e; i=0; '.
  -          'while ! test -e ${sharePath}/boot-done; do '.
  -          'sleep 10; i=$(($i + 10)); [ $i -le 3600 ]; '.
  -          'VBoxManage list runningvms | grep -q "^\"${name}\""; '.
  -          'done'
  -        ));
  -      }
  -
  -      sub waitForIP_${name} ($) {
  -        my $property = "/VirtualBox/GuestInfo/Net/$_[0]/V4/IP";
  -        my $getip = "VBoxManage guestproperty get ${name} $property | ".
  -                    "sed -n -e 's/^Value: //p'";
  -        my $ip = $machine->succeed(ru(
  -          'for i in $(seq 1000); do '.
  -          'if ipaddr="$('.$getip.')" && [ -n "$ipaddr" ]; then '.
  -          'echo "$ipaddr"; exit 0; '.
  -          'fi; '.
  -          'sleep 1; '.
  -          'done; '.
  -          'echo "Could not get IPv4 address for ${name}!" >&2; '.
  -          'exit 1'
  -        ));
  -        chomp $ip;
  -        return $ip;
  -      }
  -
  -      sub waitForStartup_${name} {
  -        for (my $i = 0; $i <= 120; $i += 10) {
  -          $machine->sleep(10);
  -          return if checkRunning_${name};
  -          eval { $_[0]->() } if defined $_[0];
  -        }
  -        die "VirtualBox VM didn't start up within 2 minutes";
  -      }
  -
  -      sub waitForShutdown_${name} {
  -        for (my $i = 0; $i <= 120; $i += 10) {
  -          $machine->sleep(10);
  -          return unless checkRunning_${name};
  -        }
  -        die "VirtualBox VM didn't shut down within 2 minutes";
  -      }
  -
  -      sub shutdownVM_${name} {
  -        $machine->succeed(ru "touch ${sharePath}/shutdown");
  -        $machine->execute(
  -          'set -e; i=0; '.
  -          'while test -e ${sharePath}/shutdown '.
  -          '        -o -e ${sharePath}/boot-done; do '.
  -          'sleep 1; i=$(($i + 1)); [ $i -le 3600 ]; '.
  -          'done'
  -        );
  -        waitForShutdown_${name};
  -      }
  +
  +
  +      ${name}_sharepath = "${sharePath}"
  +
  +
  +      def check_running_${name}():
  +          cmd = "VBoxManage list runningvms | grep -q '^\"${name}\"'"
  +          (status, _) = machine.execute(ru(cmd))
  +          return status == 0
  +
  +
  +      def cleanup_${name}():
  +          if check_running_${name}():
  +              machine.execute(ru("VBoxManage controlvm ${name} poweroff"))
  +          machine.succeed("rm -rf ${sharePath}")
  +          machine.succeed("mkdir -p ${sharePath}")
  +          machine.succeed("chown alice.users ${sharePath}")
  +
  +
  +      def create_vm_${name}():
  +          # fmt: off
  +          vbm(f"createvm --name ${name} ${createFlags}")
  +          vbm(f"modifyvm ${name} ${vmFlags}")
  +          vbm(f"setextradata ${name} VBoxInternal/PDM/HaltOnReset 1")
  +          vbm(f"storagectl ${name} ${controllerFlags}")
  +          vbm(f"storageattach ${name} ${diskFlags}")
  +          vbm(f"sharedfolder add ${name} ${sharedFlags}")
  +          vbm(f"sharedfolder add ${name} ${nixstoreFlags}")
  +          cleanup_${name}()
  +
  +          ${mkLog "$HOME/VirtualBox VMs/${name}/Logs/VBox.log" "HOST-${name}"}
  +          # fmt: on
  +
  +
  +      def destroy_vm_${name}():
  +          cleanup_${name}()
  +          vbm("unregistervm ${name} --delete")
  +
  +
  +      def wait_for_vm_boot_${name}():
  +          machine.execute(
  +              ru(
  +                  "set -e; i=0; "
  +                  "while ! test -e ${sharePath}/boot-done; do "
  +                  "sleep 10; i=$(($i + 10)); [ $i -le 3600 ]; "
  +                  "VBoxManage list runningvms | grep -q '^\"${name}\"'; "
  +                  "done"
  +              )
  +          )
  +
  +
  +      def wait_for_ip_${name}(interface):
  +          property = f"/VirtualBox/GuestInfo/Net/{interface}/V4/IP"
  +          # fmt: off
  +          getip = f"VBoxManage guestproperty get ${name} {property} | sed -n -e 's/^Value: //p'"
  +          # fmt: on
  +
  +          ip = machine.succeed(
  +              ru(
  +                  "for i in $(seq 1000); do "
  +                  f'if ipaddr="$({getip})" && [ -n "$ipaddr" ]; then '
  +                  'echo "$ipaddr"; exit 0; '
  +                  "fi; "
  +                  "sleep 1; "
  +                  "done; "
  +                  "echo 'Could not get IPv4 address for ${name}!' >&2; "
  +                  "exit 1"
  +              )
  +          ).strip()
  +          return ip
  +
  +
  +      def wait_for_startup_${name}(nudge=lambda: None):
  +          for _ in range(0, 130, 10):
  +              machine.sleep(10)
  +              if check_running_${name}():
  +                  return
  +              nudge()
  +          raise Exception("VirtualBox VM didn't start up within 2 minutes")
  +
  +
  +      def wait_for_shutdown_${name}():
  +          for _ in range(0, 130, 10):
  +              machine.sleep(10)
  +              if not check_running_${name}():
  +                  return
  +          raise Exception("VirtualBox VM didn't shut down within 2 minutes")
  +
  +
  +      def shutdown_vm_${name}():
  +          machine.succeed(ru("touch ${sharePath}/shutdown"))
  +          machine.execute(
  +              "set -e; i=0; "
  +              "while test -e ${sharePath}/shutdown "
  +              "        -o -e ${sharePath}/boot-done; do "
  +              "sleep 1; i=$(($i + 1)); [ $i -le 3600 ]; "
  +              "done"
  +          )
  +          wait_for_shutdown_${name}()
       '';
     };
   
  
positive.code: 
  assert use64bitGuest -> useKvmNestedVirt;
  
  with import ../lib/testing.nix { inherit system pkgs; };
  with pkgs.lib;
  
  let
  
negative.code:     rotated = map (i: "${logfile}.${toString i}") (range 1 9);
      all = concatMapStringsSep " " (f: "\"${f}\"") ([logfile] ++ rotated);
      logcmd = "tail -F ${all} 2> /dev/null | logger -t \"${tag}\"";
    in if debug then "machine.execute(ru('${logcmd} & disown'))" else "pass";
  
    testVM = vmName: vmScript: let
      cfg = (import ../lib/eval-config.nix {
  