Skip to content

Commit 0749f3f

Browse files
committed
nixos-remote-pxe: add --pause-after-completion flag
1 parent c2c10ab commit 0749f3f

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

nixos-remote-pxe.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,7 @@ class Options:
221221
dhcp_subnet: int
222222
dhcp_range: Tuple[IPAddress, IPAddress]
223223
pixiecore_http_port: int
224+
pause_after_completion: bool
224225
nixos_anywhere_args: List[str]
225226

226227

@@ -259,6 +260,11 @@ def parse_args(args: list[str]) -> Options:
259260
default=64172,
260261
type=int,
261262
)
263+
parser.add_argument(
264+
"--pause-after-completion",
265+
help="Whether to wait for user confimation before tearing down the network setup once the installation completed",
266+
action="store_true"
267+
)
262268

263269
parsed, unknown_args = parser.parse_known_args(args)
264270
try:
@@ -296,6 +302,7 @@ def parse_args(args: list[str]) -> Options:
296302
dhcp_range=(start_ip, stop_ip),
297303
dhcp_interface=parsed.dhcp_interface,
298304
pixiecore_http_port=parsed.pixiecore_http_port,
305+
pause_after_completion=parsed.pause_after_completion,
299306
nixos_anywhere_args=unknown_args,
300307
)
301308

@@ -366,6 +373,9 @@ def build_pxe_image(netboot_image_flake: str) -> Path:
366373
)
367374
return Path(res.stdout.strip())
368375

376+
def pause():
377+
print("")
378+
input("Press [enter] to terminate this script and tear down the network to the server.")
369379

370380
def run_nixos_remote(options: Options):
371381
pxe_image_store_path = build_pxe_image(options.netboot_image_flake)
@@ -402,8 +412,13 @@ def run_nixos_remote(options: Options):
402412
)
403413
print(f" ssh -i {ssh_key.private_key} root@{event.ip_addr}")
404414
nixos_remote(event.ip_addr, options.flake, ssh_key.private_key, options.nixos_anywhere_args)
415+
# to avoid having to reboot physical machines all the time because networking disappears:
416+
if (options.pause_after_completion):
417+
print("You can connect to the machine by doing:")
418+
print(f" ssh -i {ssh_key.private_key} root@{event.ip_addr}")
419+
pause()
405420
return
406-
print("after")
421+
print("after") # i dont think this is ever printed, because the loop only exits by returning the entire function
407422
except Exception as e:
408423
print(e)
409424
except KeyboardInterrupt:

0 commit comments

Comments
 (0)