1414import sys
1515from tempfile import TemporaryDirectory
1616from dataclasses import dataclass
17- from typing import NoReturn , Union , Iterator , Tuple , IO , Optional
17+ from typing import NoReturn , Union , Iterator , Tuple , IO , Optional , List
1818from pathlib import Path
1919from netaddr import IPNetwork , AddrFormatError , IPAddress
2020
@@ -221,6 +221,7 @@ class Options:
221221 dhcp_subnet : int
222222 dhcp_range : Tuple [IPAddress , IPAddress ]
223223 pixiecore_http_port : int
224+ nixos_anywhere_args : List [str ]
224225
225226
226227def die (msg : str ) -> NoReturn :
@@ -229,7 +230,9 @@ def die(msg: str) -> NoReturn:
229230
230231
231232def parse_args (args : list [str ]) -> Options :
232- parser = argparse .ArgumentParser ()
233+ parser = argparse .ArgumentParser (
234+ description = "Note: All arguments not listed here will be passed on to nixos-anywhere (see `nixos-anywhere --help`)."
235+ )
233236 parser .add_argument (
234237 "--flake" ,
235238 help = "Flake url of nixos configuration to install" ,
@@ -257,7 +260,7 @@ def parse_args(args: list[str]) -> Options:
257260 type = int ,
258261 )
259262
260- parsed = parser .parse_args (args )
263+ parsed , unknown_args = parser .parse_known_args (args )
261264 try :
262265 dhcp_subnet = IPNetwork (parsed .dhcp_subnet )
263266 except AddrFormatError as e :
@@ -293,6 +296,7 @@ def parse_args(args: list[str]) -> Options:
293296 dhcp_range = (start_ip , stop_ip ),
294297 dhcp_interface = parsed .dhcp_interface ,
295298 pixiecore_http_port = parsed .pixiecore_http_port ,
299+ nixos_anywhere_args = unknown_args ,
296300 )
297301
298302
@@ -312,7 +316,7 @@ def ssh_private_key() -> Iterator[SshKey]:
312316 yield SshKey (private_key = private_key , public_key = public_key )
313317
314318
315- def nixos_remote (ip : str , flake : str , ssh_private_key : Path ) -> None :
319+ def nixos_remote (ip : str , flake : str , ssh_private_key : Path , nixos_anywhere_args : List [ str ] ) -> None :
316320 run (
317321 [
318322 # FIXME: path
@@ -323,8 +327,8 @@ def nixos_remote(ip: str, flake: str, ssh_private_key: Path) -> None:
323327 "-L" ,
324328 # do not substitute because we do not have internet and copying locally is faster.
325329 "--no-substitute-on-destination" ,
326- ip
327- ],
330+ ip ,
331+ ] + nixos_anywhere_args ,
328332 extra_env = dict (SSH_PRIVATE_KEY = ssh_private_key .read_text ()),
329333 check = False
330334 )
@@ -397,7 +401,7 @@ def run_nixos_remote(options: Options):
397401 "Will now run nixos-remote on this target. You can also try to connect to the machine by doing:"
398402 )
399403 print (f" ssh -i { ssh_key .private_key } root@{ event .ip_addr } " )
400- nixos_remote (event .ip_addr , options .flake , ssh_key .private_key )
404+ nixos_remote (event .ip_addr , options .flake , ssh_key .private_key , options . nixos_anywhere_args )
401405 return
402406 print ("after" )
403407 except Exception as e :
0 commit comments