14
14
import sys
15
15
from tempfile import TemporaryDirectory
16
16
from dataclasses import dataclass
17
- from typing import NoReturn , Union , Iterator , Tuple , IO , Optional
17
+ from typing import NoReturn , Union , Iterator , Tuple , IO , Optional , List
18
18
from pathlib import Path
19
19
from netaddr import IPNetwork , AddrFormatError , IPAddress
20
20
@@ -221,6 +221,7 @@ class Options:
221
221
dhcp_subnet : int
222
222
dhcp_range : Tuple [IPAddress , IPAddress ]
223
223
pixiecore_http_port : int
224
+ nixos_anywhere_args : List [str ]
224
225
225
226
226
227
def die (msg : str ) -> NoReturn :
@@ -229,7 +230,9 @@ def die(msg: str) -> NoReturn:
229
230
230
231
231
232
def 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
+ )
233
236
parser .add_argument (
234
237
"--flake" ,
235
238
help = "Flake url of nixos configuration to install" ,
@@ -257,7 +260,7 @@ def parse_args(args: list[str]) -> Options:
257
260
type = int ,
258
261
)
259
262
260
- parsed = parser .parse_args (args )
263
+ parsed , unknown_args = parser .parse_known_args (args )
261
264
try :
262
265
dhcp_subnet = IPNetwork (parsed .dhcp_subnet )
263
266
except AddrFormatError as e :
@@ -293,6 +296,7 @@ def parse_args(args: list[str]) -> Options:
293
296
dhcp_range = (start_ip , stop_ip ),
294
297
dhcp_interface = parsed .dhcp_interface ,
295
298
pixiecore_http_port = parsed .pixiecore_http_port ,
299
+ nixos_anywhere_args = unknown_args ,
296
300
)
297
301
298
302
@@ -312,7 +316,7 @@ def ssh_private_key() -> Iterator[SshKey]:
312
316
yield SshKey (private_key = private_key , public_key = public_key )
313
317
314
318
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 :
316
320
run (
317
321
[
318
322
# FIXME: path
@@ -323,8 +327,8 @@ def nixos_remote(ip: str, flake: str, ssh_private_key: Path) -> None:
323
327
"-L" ,
324
328
# do not substitute because we do not have internet and copying locally is faster.
325
329
"--no-substitute-on-destination" ,
326
- ip
327
- ],
330
+ ip ,
331
+ ] + nixos_anywhere_args ,
328
332
extra_env = dict (SSH_PRIVATE_KEY = ssh_private_key .read_text ()),
329
333
check = False
330
334
)
@@ -397,7 +401,7 @@ def run_nixos_remote(options: Options):
397
401
"Will now run nixos-remote on this target. You can also try to connect to the machine by doing:"
398
402
)
399
403
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 )
401
405
return
402
406
print ("after" )
403
407
except Exception as e :
0 commit comments