Commit 4a20ecbf authored by Thiago Kenji Okada's avatar Thiago Kenji Okada
Browse files

nixos-rebuild-ng: move _get_hostname to Flake

parent 20a16e72
Loading
Loading
Loading
Loading
+15 −17
Original line number Diff line number Diff line
@@ -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: