nixos-rebuild-ng: move _get_hostname to Flake

This commit is contained in:
Thiago Kenji Okada
2026-02-23 21:17:06 +00:00
parent 20a16e7265
commit 4a20ecbfd7
@@ -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: