mirror of
https://github.com/NixOS/nixpkgs.git
synced 2025-02-08 21:24:03 +00:00
nixos-rebuild-ng: make build-time flags globals
This commit is contained in:
parent
d4c1d6c482
commit
14ab7a484d
@ -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")
|
||||
|
Loading…
Reference in New Issue
Block a user