Unverified Commit 738ff237 authored by Sefa Eyeoglu's avatar Sefa Eyeoglu Committed by GitHub
Browse files

nixos-rebuild-ng: do not parse the path part from Flake as a Path (#445188)

parents 11a1659e 6b3743ea
Loading
Loading
Loading
Loading
+6 −3
Original line number Diff line number Diff line
@@ -134,14 +134,17 @@ python3Packages.buildPythonApplication rec {
        # NOTE: this is a passthru test rather than a build-time test because we
        # want to keep the build closures small
        linters = runCommand "${pname}-linters" { nativeBuildInputs = [ python-with-pkgs ]; } ''
          export MYPY_CACHE_DIR="$(mktemp -d)"
          export RUFF_CACHE_DIR="$(mktemp -d)"

          pushd ${src}
          echo -e "\x1b[32m## run mypy\x1b[0m"
          mypy ${src}
          mypy .
          echo -e "\x1b[32m## run ruff\x1b[0m"
          ruff check ${src}
          ruff check .
          echo -e "\x1b[32m## run ruff format\x1b[0m"
          ruff format --check ${src}
          ruff format --check .
          popd

          touch $out
        '';
+1 −0
Original line number Diff line number Diff line
# mypy: disable-error-code=comparison-overlap
from typing import Final

# Build-time flags
+10 −11
Original line number Diff line number Diff line
@@ -8,7 +8,7 @@ from typing import Any, ClassVar, Self, TypedDict, override

from .process import Remote, run_wrapper

type ImageVariants = list[str]
type ImageVariants = dict[str, str]


class NixOSRebuildError(Exception):
@@ -77,7 +77,7 @@ def _get_hostname(target_host: Remote | None) -> str | None:

@dataclass(frozen=True)
class Flake:
    path: Path | str
    path: str
    attr: str
    _re: ClassVar = re.compile(r"^(?P<path>[^\#]*)\#?(?P<attr>[^\#\"]*)$")

@@ -86,10 +86,6 @@ class Flake:

    @override
    def __str__(self) -> str:
        if isinstance(self.path, Path):
            # https://github.com/NixOS/nixpkgs/issues/433726
            return f"{self.path.absolute()}#{self.attr}"
        else:
        return f"{self.path}#{self.attr}"

    @classmethod
@@ -101,10 +97,7 @@ class Flake:
            f'nixosConfigurations."{attr or _get_hostname(target_host) or "default"}"'
        )
        path = m.group("path")
        if ":" in path:
        return cls(path, nixos_attr)
        else:
            return cls(Path(path), nixos_attr)

    @classmethod
    def from_arg(cls, flake_arg: Any, target_host: Remote | None) -> Self | None:  # noqa: ANN401
@@ -125,6 +118,12 @@ class Flake:
                else:
                    return None

    def resolve_path_if_exists(self) -> str:
        try:
            return str(Path(self.path).resolve(strict=True))
        except FileNotFoundError:
            return self.path


@dataclass(frozen=True)
class Generation:
+1 −1
Original line number Diff line number Diff line
@@ -545,7 +545,7 @@ def repl_flake(flake: Flake, flake_flags: Args | None = None) -> None:
        files(__package__).joinpath(FLAKE_REPL_TEMPLATE).read_text()
    ).substitute(
        flake=flake,
        flake_path=flake.path.resolve() if isinstance(flake.path, Path) else flake.path,
        flake_path=flake.resolve_path_if_exists(),
        flake_attr=flake.attr,
        bold="\033[1m",
        blue="\033[34;1m",
+1 −1
Original line number Diff line number Diff line
@@ -14,7 +14,7 @@ class LogFormatter(logging.Formatter):
    }

    @override
    def format(self, record: logging.LogRecord) -> str:
    def format(self, record: logging.LogRecord) -> Any:
        record.levelname = record.levelname.lower()
        formatter = self.formatters.get(record.levelno, self.formatters["DEFAULT"])
        return formatter.format(record)
Loading