nixos-rebuild-ng: add missing FLAKE_FLAGS in nix eval calls (#489864)

This commit is contained in:
Thiago Kenji Okada
2026-02-16 14:21:54 +00:00
committed by GitHub
6 changed files with 33 additions and 20 deletions
@@ -201,7 +201,7 @@ def get_parser() -> tuple[argparse.ArgumentParser, dict[str, argparse.ArgumentPa
"--diff",
action="store_true",
help="prints out the diff between the current system "
"and the newly built one using nix store diff-closures"
"and the newly built one using nix store diff-closures",
)
main_parser.add_argument("action", choices=Action.values(), nargs="?")
@@ -1,7 +1,7 @@
import sys
import json
import logging
import os
import sys
import textwrap
import uuid
from concurrent.futures import ThreadPoolExecutor
@@ -314,6 +314,7 @@ def get_build_image_name_flake(
r = run_wrapper(
[
"nix",
*FLAKE_FLAGS,
"eval",
"--json",
flake.to_attr(
@@ -365,6 +366,7 @@ def get_build_image_variants_flake(
r = run_wrapper(
[
"nix",
*FLAKE_FLAGS,
"eval",
"--json",
flake.to_attr("config.system.build.images"),
@@ -538,12 +540,13 @@ def list_generations(profile: Profile) -> list[GenerationJson]:
reverse=True,
)
def diff_closures(current_config: Path, new_config: Path, target_host: Remote | None = None):
print(
f"<<< {current_config}\n"
f">>> {new_config}",
file=sys.stderr
)
def diff_closures(
current_config: Path,
new_config: Path,
target_host: Remote | None = None,
) -> None:
print(f"<<< {current_config}\n>>> {new_config}", file=sys.stderr)
run_wrapper(
[
"nix",
@@ -554,7 +557,7 @@ def diff_closures(current_config: Path, new_config: Path, target_host: Remote |
new_config,
],
remote=target_host,
stdout=sys.stderr
stdout=sys.stderr,
)
@@ -8,7 +8,7 @@ import subprocess
from collections.abc import Sequence
from dataclasses import dataclass
from ipaddress import AddressValueError, IPv6Address
from typing import Final, Self, TypedDict, Unpack
from typing import Final, Self, TextIO, TypedDict, Unpack
from . import tmpdir
@@ -85,8 +85,8 @@ class Remote:
# Not exhaustive, but we can always extend it later.
class RunKwargs(TypedDict, total=False):
capture_output: bool
stderr: int | None
stdout: int | None
stderr: int | TextIO | None
stdout: int | TextIO | None
def cleanup_ssh() -> None:
@@ -324,9 +324,15 @@ def build_and_activate_system(
current_config = Path("/run/current-system")
if args.diff:
if current_config.exists():
nix.diff_closures(current_config=current_config.readlink(), new_config=path_to_config, target_host=target_host)
nix.diff_closures(
current_config=current_config.readlink(),
new_config=path_to_config,
target_host=target_host,
)
else:
logger.warning(f"missing '{str(current_config)}', skipping configuration diff...")
logger.warning(
f"missing '{current_config!s}', skipping configuration diff..."
)
_activate_system(
path_to_config=path_to_config,
@@ -386,6 +386,8 @@ def test_execute_nix_build_image_flake(mock_run: Mock, tmp_path: Path) -> None:
call(
[
"nix",
"--extra-experimental-features",
"nix-command flakes",
"eval",
"--json",
'/path/to/config#nixosConfigurations."hostname".config.system.build.images',
@@ -412,6 +414,8 @@ def test_execute_nix_build_image_flake(mock_run: Mock, tmp_path: Path) -> None:
call(
[
"nix",
"--extra-experimental-features",
"nix-command flakes",
"eval",
"--json",
'/path/to/config#nixosConfigurations."hostname".config.system.build.images.azure.passthru.filePath',
@@ -394,6 +394,8 @@ def test_get_build_image_variants_flake(mock_run: Mock) -> None:
mock_run.assert_called_with(
[
"nix",
"--extra-experimental-features",
"nix-command flakes",
"eval",
"--json",
"/flake.nix#myAttr.config.system.build.images",
@@ -554,11 +556,9 @@ def test_list_generations(mock_get_generations: Mock, tmp_path: Path) -> None:
@patch(get_qualified_name(n.run_wrapper, n), autospec=True)
def test_diff_closures(mock_run: Mock) -> None:
assert n.diff_closures(
Path("/run/current-system"),
Path("/nix/var/nix/profiles/system"),
None
) == None
n.diff_closures(
Path("/run/current-system"), Path("/nix/var/nix/profiles/system"), None
)
mock_run.assert_called_with(
[
"nix",
@@ -570,7 +570,7 @@ def test_diff_closures(mock_run: Mock) -> None:
Path("/nix/var/nix/profiles/system"),
],
remote=None,
stdout=sys.stderr
stdout=sys.stderr,
)