@@ -43,19 +43,19 @@ def get_parser() -> tuple[argparse.ArgumentParser, dict[str, argparse.ArgumentPa
4343 common_build_flags .add_argument ("--print-build-logs" , "-L" , action = "store_true" )
4444 common_build_flags .add_argument ("--show-trace" , action = "store_true" )
4545
46- flake_build_flags = argparse .ArgumentParser (add_help = False )
47- flake_build_flags .add_argument ("--accept-flake-config" , action = "store_true" )
48- flake_build_flags .add_argument ("--refresh" , action = "store_true" )
49- flake_build_flags .add_argument ("--impure" , action = "store_true" )
50- flake_build_flags .add_argument ("--offline" , action = "store_true" )
51- flake_build_flags .add_argument ("--no-net" , action = "store_true" )
52- flake_build_flags .add_argument ("--recreate-lock-file" , action = "store_true" )
53- flake_build_flags .add_argument ("--no-update-lock-file" , action = "store_true" )
54- flake_build_flags .add_argument ("--no-write-lock-file" , action = "store_true" )
55- flake_build_flags .add_argument ("--no-registries" , action = "store_true" )
56- flake_build_flags .add_argument ("--commit-lock-file" , action = "store_true" )
57- flake_build_flags .add_argument ("--update-input" )
58- flake_build_flags .add_argument ("--override-input" , nargs = 2 )
46+ flake_common_flags = argparse .ArgumentParser (add_help = False )
47+ flake_common_flags .add_argument ("--accept-flake-config" , action = "store_true" )
48+ flake_common_flags .add_argument ("--refresh" , action = "store_true" )
49+ flake_common_flags .add_argument ("--impure" , action = "store_true" )
50+ flake_common_flags .add_argument ("--offline" , action = "store_true" )
51+ flake_common_flags .add_argument ("--no-net" , action = "store_true" )
52+ flake_common_flags .add_argument ("--recreate-lock-file" , action = "store_true" )
53+ flake_common_flags .add_argument ("--no-update-lock-file" , action = "store_true" )
54+ flake_common_flags .add_argument ("--no-write-lock-file" , action = "store_true" )
55+ flake_common_flags .add_argument ("--no-registries" , action = "store_true" )
56+ flake_common_flags .add_argument ("--commit-lock-file" , action = "store_true" )
57+ flake_common_flags .add_argument ("--update-input" )
58+ flake_common_flags .add_argument ("--override-input" , nargs = 2 )
5959
6060 classic_build_flags = argparse .ArgumentParser (add_help = False )
6161 classic_build_flags .add_argument ("--no-build-output" , "-Q" , action = "store_true" )
@@ -74,7 +74,7 @@ def get_parser() -> tuple[argparse.ArgumentParser, dict[str, argparse.ArgumentPa
7474 sub_parsers = {
7575 "common_flags" : common_flags ,
7676 "common_build_flags" : common_build_flags ,
77- "flake_build_flags " : flake_build_flags ,
77+ "flake_common_flags " : flake_common_flags ,
7878 "classic_build_flags" : classic_build_flags ,
7979 "copy_flags" : copy_flags ,
8080 }
@@ -262,19 +262,27 @@ def parser_warn(msg: str) -> None:
262262def reexec (
263263 argv : list [str ],
264264 args : argparse .Namespace ,
265- build_flags : dict [ str , Args ] ,
266- flake_build_flags : dict [ str , Args ] ,
265+ build_flags : Args ,
266+ flake_build_flags : Args ,
267267) -> None :
268268 drv = None
269269 attr = "config.system.build.nixos-rebuild"
270270 try :
271271 # Parsing the args here but ignore ask_sudo_password since it is not
272272 # needed and we would end up asking sudo password twice
273273 if flake := Flake .from_arg (args .flake , Remote .from_arg (args .target_host , None )):
274- drv = nix .build_flake (attr , flake , ** flake_build_flags , no_link = True )
274+ drv = nix .build_flake (
275+ attr ,
276+ flake ,
277+ flake_build_flags | {"no_link" : True },
278+ )
275279 else :
276280 build_attr = BuildAttr .from_arg (args .attr , args .file )
277- drv = nix .build (attr , build_attr , ** build_flags , no_out_link = True )
281+ drv = nix .build (
282+ attr ,
283+ build_attr ,
284+ build_flags | {"no_out_link" : True },
285+ )
278286 except CalledProcessError :
279287 logger .warning (
280288 "could not build a newer version of nixos-rebuild, "
@@ -319,7 +327,8 @@ def execute(argv: list[str]) -> None:
319327 common_flags = vars (args_groups ["common_flags" ])
320328 common_build_flags = common_flags | vars (args_groups ["common_build_flags" ])
321329 build_flags = common_build_flags | vars (args_groups ["classic_build_flags" ])
322- flake_build_flags = common_build_flags | vars (args_groups ["flake_build_flags" ])
330+ flake_common_flags = common_flags | vars (args_groups ["flake_common_flags" ])
331+ flake_build_flags = common_build_flags | flake_common_flags
323332 copy_flags = common_flags | vars (args_groups ["copy_flags" ])
324333
325334 if args .upgrade or args .upgrade_all :
@@ -350,7 +359,7 @@ def execute(argv: list[str]) -> None:
350359 flake = Flake .from_arg (args .flake , target_host )
351360
352361 if can_run and not flake :
353- nixpkgs_path = nix .find_file ("nixpkgs" , ** build_flags )
362+ nixpkgs_path = nix .find_file ("nixpkgs" , build_flags )
354363 rev = nix .get_nixpkgs_rev (nixpkgs_path )
355364 if nixpkgs_path and rev :
356365 (nixpkgs_path / ".version-suffix" ).write_text (rev )
@@ -370,7 +379,10 @@ def execute(argv: list[str]) -> None:
370379
371380 dry_run = action == Action .DRY_BUILD
372381 no_link = action in (Action .SWITCH , Action .BOOT )
382+ build_flags |= {"no_out_link" : no_link , "dry_run" : dry_run }
383+ flake_build_flags |= {"no_link" : no_link , "dry_run" : dry_run }
373384 rollback = bool (args .rollback )
385+
374386 match action :
375387 case Action .BUILD_VM :
376388 attr = "config.system.build.vm"
@@ -395,24 +407,22 @@ def execute(argv: list[str]) -> None:
395407 case (_, True , _, _):
396408 raise NRError (f"--rollback is incompatible with '{ action } '" )
397409 case (_, False , Remote (_), Flake (_)):
398- path_to_config = nix .remote_build_flake (
410+ path_to_config = nix .build_remote_flake (
399411 attr ,
400412 flake ,
401413 build_host ,
414+ eval_flags = flake_common_flags ,
402415 flake_build_flags = flake_build_flags ,
403416 copy_flags = copy_flags ,
404- build_flags = build_flags ,
405417 )
406418 case (_, False , None , Flake (_)):
407419 path_to_config = nix .build_flake (
408420 attr ,
409421 flake ,
410- no_link = no_link ,
411- dry_run = dry_run ,
412- ** flake_build_flags ,
422+ flake_build_flags = flake_build_flags ,
413423 )
414424 case (_, False , Remote (_), None ):
415- path_to_config = nix .remote_build (
425+ path_to_config = nix .build_remote (
416426 attr ,
417427 build_attr ,
418428 build_host ,
@@ -424,9 +434,7 @@ def execute(argv: list[str]) -> None:
424434 path_to_config = nix .build (
425435 attr ,
426436 build_attr ,
427- no_out_link = no_link ,
428- dry_run = dry_run ,
429- ** build_flags ,
437+ build_flags = build_flags ,
430438 )
431439 case never :
432440 # should never happen, but mypy is not smart enough to
@@ -442,7 +450,7 @@ def execute(argv: list[str]) -> None:
442450 path_to_config ,
443451 to_host = target_host ,
444452 from_host = build_host ,
445- ** copy_flags ,
453+ copy_flags = copy_flags ,
446454 )
447455 if action in (Action .SWITCH , Action .BOOT ):
448456 nix .set_profile (
@@ -468,7 +476,7 @@ def execute(argv: list[str]) -> None:
468476 f"Done. The virtual machine can be started by running '{ vm_path } '"
469477 )
470478 case Action .EDIT :
471- nix .edit (flake , ** flake_build_flags )
479+ nix .edit (flake , flake_build_flags )
472480 case Action .DRY_RUN :
473481 assert False , "DRY_RUN should be a DRY_BUILD alias"
474482 case Action .LIST_GENERATIONS :
@@ -488,9 +496,9 @@ def execute(argv: list[str]) -> None:
488496 print (tabulate (generations , headers = headers ))
489497 case Action .REPL :
490498 if flake :
491- nix .repl_flake ("toplevel" , flake , ** flake_build_flags )
499+ nix .repl_flake ("toplevel" , flake , flake_build_flags )
492500 else :
493- nix .repl ("system" , build_attr , ** build_flags )
501+ nix .repl ("system" , build_attr , build_flags )
494502 case _:
495503 assert_never (action )
496504
0 commit comments