Revert "nixos-rebuild-ng: silence reexec messages"
This reverts commit 4935f5f09b.
This commit is contained in:
@@ -13,9 +13,7 @@ from .models import Action, BuildAttr, Flake, ImageVariants, NRError, Profile
|
||||
from .process import Remote, cleanup_ssh
|
||||
from .utils import Args, LogFormatter, tabulate
|
||||
|
||||
NIXOS_REBUILD_ATTR: Final = "config.system.build.nixos-rebuild"
|
||||
|
||||
logger: Final = logging.getLogger(__name__)
|
||||
logger: Final = logging.getLogger()
|
||||
logger.setLevel(logging.INFO)
|
||||
|
||||
|
||||
@@ -278,28 +276,26 @@ def reexec(
|
||||
flake_build_flags: Args,
|
||||
) -> None:
|
||||
drv = None
|
||||
attr = "config.system.build.nixos-rebuild"
|
||||
try:
|
||||
# Parsing the args here but ignore ask_sudo_password since it is not
|
||||
# needed and we would end up asking sudo password twice
|
||||
if flake := Flake.from_arg(args.flake, Remote.from_arg(args.target_host, None)):
|
||||
drv = nix.build_flake(
|
||||
NIXOS_REBUILD_ATTR,
|
||||
attr,
|
||||
flake,
|
||||
flake_build_flags | {"no_link": True},
|
||||
quiet=True,
|
||||
)
|
||||
else:
|
||||
build_attr = BuildAttr.from_arg(args.attr, args.file)
|
||||
drv = nix.build(
|
||||
NIXOS_REBUILD_ATTR,
|
||||
attr,
|
||||
build_attr,
|
||||
build_flags | {"no_out_link": True},
|
||||
quiet=True,
|
||||
)
|
||||
except CalledProcessError:
|
||||
logger.warning(
|
||||
"could not build a newer version of nixos-rebuild, using current version",
|
||||
exc_info=logger.isEnabledFor(logging.DEBUG),
|
||||
"could not build a newer version of nixos-rebuild, using current version"
|
||||
)
|
||||
|
||||
if drv:
|
||||
@@ -323,9 +319,9 @@ def reexec(
|
||||
# - Exec format error (e.g.: another OS/CPU arch)
|
||||
logger.warning(
|
||||
"could not re-exec in a newer version of nixos-rebuild, "
|
||||
+ "using current version",
|
||||
exc_info=logger.isEnabledFor(logging.DEBUG),
|
||||
+ "using current version"
|
||||
)
|
||||
logger.debug("re-exec exception", exc_info=True)
|
||||
# We already run clean-up, let's re-exec in the current version
|
||||
# to avoid issues
|
||||
os.execve(current, argv, os.environ | {"_NIXOS_REBUILD_REEXEC": "1"})
|
||||
|
||||
@@ -51,7 +51,6 @@ def build(
|
||||
attr: str,
|
||||
build_attr: BuildAttr,
|
||||
build_flags: Args | None = None,
|
||||
quiet: bool = False,
|
||||
) -> Path:
|
||||
"""Build NixOS attribute using classic Nix.
|
||||
|
||||
@@ -64,7 +63,7 @@ def build(
|
||||
build_attr.to_attr(attr),
|
||||
*dict_to_flags(build_flags),
|
||||
]
|
||||
r = run_wrapper(run_args, stdout=PIPE, stderr=PIPE if quiet else None)
|
||||
r = run_wrapper(run_args, stdout=PIPE)
|
||||
return Path(r.stdout.strip())
|
||||
|
||||
|
||||
@@ -72,7 +71,6 @@ def build_flake(
|
||||
attr: str,
|
||||
flake: Flake,
|
||||
flake_build_flags: Args | None = None,
|
||||
quiet: bool = False,
|
||||
) -> Path:
|
||||
"""Build NixOS attribute using Flakes.
|
||||
|
||||
@@ -86,7 +84,7 @@ def build_flake(
|
||||
flake.to_attr(attr),
|
||||
*dict_to_flags(flake_build_flags),
|
||||
]
|
||||
r = run_wrapper(run_args, stdout=PIPE, stderr=PIPE if quiet else None)
|
||||
r = run_wrapper(run_args, stdout=PIPE)
|
||||
return Path(r.stdout.strip())
|
||||
|
||||
|
||||
|
||||
@@ -140,10 +140,9 @@ def test_reexec(mock_build: Mock, mock_execve: Mock, monkeypatch: MonkeyPatch) -
|
||||
mock_build.assert_has_calls(
|
||||
[
|
||||
call(
|
||||
nr.NIXOS_REBUILD_ATTR,
|
||||
"config.system.build.nixos-rebuild",
|
||||
nr.models.BuildAttr(ANY, ANY),
|
||||
{"build": True, "no_out_link": True},
|
||||
quiet=True,
|
||||
)
|
||||
]
|
||||
)
|
||||
@@ -188,7 +187,6 @@ def test_reexec_flake(
|
||||
"config.system.build.nixos-rebuild",
|
||||
nr.models.Flake(ANY, ANY),
|
||||
{"flake": True, "no_link": True},
|
||||
quiet=True,
|
||||
)
|
||||
# do not exec if there is no new version
|
||||
mock_execve.assert_not_called()
|
||||
@@ -268,7 +266,6 @@ def test_execute_nix_boot(mock_run: Mock, tmp_path: Path) -> None:
|
||||
],
|
||||
check=True,
|
||||
stdout=PIPE,
|
||||
stderr=None,
|
||||
**DEFAULT_RUN_KWARGS,
|
||||
),
|
||||
call(
|
||||
@@ -343,7 +340,6 @@ def test_execute_nix_build_vm(mock_run: Mock, tmp_path: Path) -> None:
|
||||
],
|
||||
check=True,
|
||||
stdout=PIPE,
|
||||
stderr=None,
|
||||
**DEFAULT_RUN_KWARGS,
|
||||
)
|
||||
]
|
||||
@@ -408,7 +404,6 @@ def test_execute_nix_build_image_flake(mock_run: Mock, tmp_path: Path) -> None:
|
||||
],
|
||||
check=True,
|
||||
stdout=PIPE,
|
||||
stderr=None,
|
||||
**DEFAULT_RUN_KWARGS,
|
||||
),
|
||||
call(
|
||||
@@ -476,7 +471,6 @@ def test_execute_nix_switch_flake(mock_run: Mock, tmp_path: Path) -> None:
|
||||
],
|
||||
check=True,
|
||||
stdout=PIPE,
|
||||
stderr=None,
|
||||
**DEFAULT_RUN_KWARGS,
|
||||
),
|
||||
call(
|
||||
@@ -767,7 +761,6 @@ def test_execute_nix_switch_flake_target_host(
|
||||
],
|
||||
check=True,
|
||||
stdout=PIPE,
|
||||
stderr=None,
|
||||
**DEFAULT_RUN_KWARGS,
|
||||
),
|
||||
call(
|
||||
@@ -1035,7 +1028,6 @@ def test_execute_build(mock_run: Mock, tmp_path: Path) -> None:
|
||||
],
|
||||
check=True,
|
||||
stdout=PIPE,
|
||||
stderr=None,
|
||||
**DEFAULT_RUN_KWARGS,
|
||||
)
|
||||
]
|
||||
@@ -1075,7 +1067,6 @@ def test_execute_test_flake(mock_run: Mock, tmp_path: Path) -> None:
|
||||
],
|
||||
check=True,
|
||||
stdout=PIPE,
|
||||
stderr=None,
|
||||
**DEFAULT_RUN_KWARGS,
|
||||
),
|
||||
call(
|
||||
|
||||
@@ -36,18 +36,14 @@ def test_build(mock_run: Mock) -> None:
|
||||
"foo",
|
||||
],
|
||||
stdout=PIPE,
|
||||
stderr=None,
|
||||
)
|
||||
|
||||
assert n.build(
|
||||
"config.system.build.attr",
|
||||
m.BuildAttr(Path("file"), "preAttr"),
|
||||
quiet=True,
|
||||
"config.system.build.attr", m.BuildAttr(Path("file"), "preAttr")
|
||||
) == Path("/path/to/file")
|
||||
mock_run.assert_called_with(
|
||||
["nix-build", Path("file"), "--attr", "preAttr.config.system.build.attr"],
|
||||
stdout=PIPE,
|
||||
stderr=PIPE,
|
||||
)
|
||||
|
||||
|
||||
@@ -78,26 +74,6 @@ def test_build_flake(mock_run: Mock, monkeypatch: MonkeyPatch, tmpdir: Path) ->
|
||||
"foo",
|
||||
],
|
||||
stdout=PIPE,
|
||||
stderr=None,
|
||||
)
|
||||
|
||||
assert n.build_flake(
|
||||
"config.system.build.toplevel",
|
||||
flake,
|
||||
None,
|
||||
quiet=True,
|
||||
) == Path("/path/to/file")
|
||||
mock_run.assert_called_with(
|
||||
[
|
||||
"nix",
|
||||
"--extra-experimental-features",
|
||||
"nix-command flakes",
|
||||
"build",
|
||||
"--print-out-paths",
|
||||
'.#nixosConfigurations."hostname".config.system.build.toplevel',
|
||||
],
|
||||
stdout=PIPE,
|
||||
stderr=PIPE,
|
||||
)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user