diff --git a/pkgs/by-name/ni/nixos-rebuild-ng/src/nixos_rebuild/__init__.py b/pkgs/by-name/ni/nixos-rebuild-ng/src/nixos_rebuild/__init__.py index 057be3017a63..49ba193a03ad 100644 --- a/pkgs/by-name/ni/nixos-rebuild-ng/src/nixos_rebuild/__init__.py +++ b/pkgs/by-name/ni/nixos-rebuild-ng/src/nixos_rebuild/__init__.py @@ -16,6 +16,12 @@ from .utils import Args, LogFormatter logger = logging.getLogger() logger.setLevel(logging.INFO) +# Build-time flags +# Strings to avoid breaking standalone (e.g.: `python -m nixos_rebuild`) usage +EXECUTABLE = "@executable@" +WITH_REEXEC = "@withReexec@" +WITH_SHELL_FILES = "@withShellFiles@" + def get_parser() -> tuple[argparse.ArgumentParser, dict[str, argparse.ArgumentParser]]: common_flags = argparse.ArgumentParser(add_help=False) @@ -181,8 +187,8 @@ def parse_args( } if args.help or args.action is None: - if "@withShellFiles@" == "true": # type: ignore - r = run(["man", "8", "@executable@"], check=False) + if WITH_SHELL_FILES == "true": + r = run(["man", "8", EXECUTABLE], check=False) parser.exit(r.returncode) else: parser.print_help() @@ -260,10 +266,9 @@ def reexec( logger.warning("could not find a newer version of nixos-rebuild") if drv: - new = drv / "bin/@executable@" + new = drv / f"bin/{EXECUTABLE}" current = Path(argv[0]) - # Disable re-exec during development - if current.name != "__main__.py" and new != current: + if new != current: logging.debug( "detected newer version of script, re-exec'ing, current=%s, new=%s", argv[0], @@ -298,7 +303,7 @@ def execute(argv: list[str]) -> None: # Re-exec to a newer version of the script before building to ensure we get # the latest fixes if ( - "@withReexec@" == "true" # type: ignore + WITH_REEXEC == "true" and can_run and not args.fast and not os.environ.get("_NIXOS_REBUILD_REEXEC")