From 4a20ecbfd75518fd5e96f588b67517a0ab469d5c Mon Sep 17 00:00:00 2001 From: Thiago Kenji Okada Date: Mon, 23 Feb 2026 09:20:40 +0000 Subject: [PATCH] nixos-rebuild-ng: move _get_hostname to Flake --- .../src/nixos_rebuild/models.py | 32 +++++++++---------- 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/pkgs/by-name/ni/nixos-rebuild-ng/src/nixos_rebuild/models.py b/pkgs/by-name/ni/nixos-rebuild-ng/src/nixos_rebuild/models.py index f8c20878f5e1..7fb37e8f97a9 100644 --- a/pkgs/by-name/ni/nixos-rebuild-ng/src/nixos_rebuild/models.py +++ b/pkgs/by-name/ni/nixos-rebuild-ng/src/nixos_rebuild/models.py @@ -63,20 +63,6 @@ class BuildAttr: return cls(Path(file or "default.nix"), attr) -def _get_hostname(target_host: Remote | None) -> str | None: - if target_host: - try: - return run_wrapper( - ["uname", "-n"], - capture_output=True, - remote=target_host, - ).stdout.strip() - except (AttributeError, subprocess.CalledProcessError): - return None - else: - return platform.node() - - @dataclass(frozen=True) class Flake: path: str @@ -95,9 +81,7 @@ class Flake: m = cls._re.match(flake_str) assert m is not None, f"got no matches for {flake_str}" attr = m.group("attr") - nixos_attr = ( - f'nixosConfigurations."{attr or _get_hostname(target_host) or "default"}"' - ) + nixos_attr = f'nixosConfigurations."{attr or cls._get_hostname(target_host) or "default"}"' path = m.group("path") return cls(path, nixos_attr) @@ -126,6 +110,20 @@ class Flake: except FileNotFoundError: return self.path + @staticmethod + def _get_hostname(target_host: Remote | None) -> str | None: + if target_host: + try: + return run_wrapper( + ["uname", "-n"], + capture_output=True, + remote=target_host, + ).stdout.strip() + except (AttributeError, subprocess.CalledProcessError): + return None + else: + return platform.node() + @dataclass(frozen=True) class Generation: