From c15ca7e8a79628c36d998b975472d35112542d96 Mon Sep 17 00:00:00 2001
From: Fritz Grimpen <grimpen@uni-bremen.de>
Date: Sun, 19 Jan 2025 21:10:42 +0100
Subject: [PATCH] bhyve: Restore old behavior wrt PASS

---
 roles/bhyve-s6/templates/bhyve/run.j2 | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/roles/bhyve-s6/templates/bhyve/run.j2 b/roles/bhyve-s6/templates/bhyve/run.j2
index f8508a9..57bbdd2 100644
--- a/roles/bhyve-s6/templates/bhyve/run.j2
+++ b/roles/bhyve-s6/templates/bhyve/run.j2
@@ -29,7 +29,8 @@ foreground { fdmove -c 1 2 echo "bhyve-${NAME}: Starting VM ${NAME} with ${CPUS}
 s6-notifyoncheck -d -w 100 -n 70
 
 fdmove -c 2 1
-bhyve -c "{{ item.0.cpus }}" -m "{{ item.0.ram }}" -w -A -P -H
+{% macro bhyve_run(extra_args="") -%}
+bhyve -c "${CPUS}" -m "${RAM}" -w -A -P -H
 	-s "0,amd_hostbridge"
 	-s "2:0,ahci${AHCI}"
 	-s "3,virtio-net,${NIC}"
@@ -37,10 +38,12 @@ bhyve -c "{{ item.0.cpus }}" -m "{{ item.0.ram }}" -w -A -P -H
 	{% for disk in item.0.disks if disk.virtio|default(False) -%}
 	-s "{{ disk.virtio_slot }},virtio-blk,/dev/zvol/{{ bhyve_pool }}/bhyve/guests/{{ item.0.name }}/{{ disk.name }}"
 	{% endfor -%}
-	{% if item.0.password is defined -%}
-	-s "29,fbuf,tcp=[::1]:${PORT},w=800,h=600,password=${PASS}"
-	{% endif -%}
 	-s "31,lpc"
 	-l "com1,/dev/${COM}"
 	-l "bootrom,${ROM}"
-	"${NAME}"
+	{{ extra_args }} "${NAME}"
+{%- endmacro %}
+ifelse { test -n "$PASS" } {
+	{{ bhyve_run('-s "29,fbuf,tcp=[::1]:${PORT},w=800,h=600,password=${PASS}"') }}
+}
+	{{ bhyve_run() }}