Unverified Commit 2be2a373 authored by Thiago Kenji Okada's avatar Thiago Kenji Okada Committed by GitHub
Browse files

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

parents 7fc61407 be9bcfc8
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -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="?")

+11 −8
Original line number Diff line number Diff line
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,
    )


+3 −3
Original line number Diff line number Diff line
@@ -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:
+8 −2
Original line number Diff line number Diff line
@@ -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,
+4 −0
Original line number Diff line number Diff line
@@ -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',
Loading