clan-cli: Simplify hostPlatform and just use 'system'
This commit is contained in:
@@ -1,47 +0,0 @@
|
||||
from dataclasses import dataclass, fields
|
||||
from typing import Any
|
||||
|
||||
|
||||
@dataclass
|
||||
class HostPlatform:
|
||||
config: str
|
||||
darwinArch: str
|
||||
darwinMinVersion: str
|
||||
darwinSdkVersion: str
|
||||
is32bit: bool
|
||||
is64bit: bool
|
||||
isx86_64: bool
|
||||
isAarch: bool
|
||||
isDarwin: bool
|
||||
isFreeBSD: bool
|
||||
isLinux: bool
|
||||
isMacOS: bool
|
||||
isWindows: bool
|
||||
isAndroid: bool
|
||||
linuxArch: str
|
||||
qemuArch: str
|
||||
system: str
|
||||
ubootArch: str
|
||||
|
||||
# ruff: noqa: N815
|
||||
|
||||
@staticmethod
|
||||
def from_dict(data: dict[str, Any]) -> "HostPlatform":
|
||||
"""
|
||||
Factory method that creates an instance of HostPlatform from a dictionary.
|
||||
Extra fields in the dictionary are ignored.
|
||||
|
||||
Args:
|
||||
data (dict): A dictionary containing values for initializing HostPlatform.
|
||||
|
||||
Returns:
|
||||
HostPlatform: An instance of the HostPlatform class.
|
||||
"""
|
||||
# Dynamically extract field names from the dataclass
|
||||
valid_keys = {field.name for field in fields(HostPlatform)}
|
||||
|
||||
# Filter the dictionary to only include items with keys that are valid
|
||||
filtered_data = {k: v for k, v in data.items() if k in valid_keys}
|
||||
|
||||
# Pass the filtered data to the HostPlatform constructor
|
||||
return HostPlatform(**filtered_data)
|
||||
@@ -12,7 +12,6 @@ from clan_cli.cmd import run_no_stdout
|
||||
from clan_cli.errors import ClanError
|
||||
from clan_cli.facts import public_modules as facts_public_modules
|
||||
from clan_cli.facts import secret_modules as facts_secret_modules
|
||||
from clan_cli.machines import host_platform
|
||||
from clan_cli.nix import nix_build, nix_config, nix_eval, nix_metadata
|
||||
from clan_cli.ssh import Host, HostKeyCheck, parse_deployment_address
|
||||
from clan_cli.vars.public_modules import FactStoreBase
|
||||
@@ -48,16 +47,13 @@ class Machine:
|
||||
return str(self)
|
||||
|
||||
@property
|
||||
def host_platform(self) -> host_platform.HostPlatform:
|
||||
def system(self) -> str:
|
||||
# We filter out function attributes because they are not serializable.
|
||||
attr = f"""
|
||||
(let
|
||||
machine = ((builtins.getFlake "{self.flake}").nixosConfigurations.{self.name});
|
||||
lib = machine.lib;
|
||||
removeFunctionAttrs = attrset:
|
||||
lib.filterAttrs (name: value: lib.isFunction value == false && name != "parsed") attrset;
|
||||
in
|
||||
{{ x = removeFunctionAttrs machine.pkgs.stdenv.hostPlatform; }}).x
|
||||
{{ x = machine.pkgs.stdenv.hostPlatform.system; }}).x
|
||||
"""
|
||||
if attr in self._eval_cache:
|
||||
output = self._eval_cache[attr]
|
||||
@@ -67,14 +63,14 @@ class Machine:
|
||||
).stdout.strip()
|
||||
self._eval_cache[attr] = output
|
||||
value = json.loads(output)
|
||||
return host_platform.HostPlatform.from_dict(value)
|
||||
return value
|
||||
|
||||
@property
|
||||
def can_build_locally(self) -> bool:
|
||||
# TODO: We could also use the function pkgs.stdenv.hostPlatform.canExecute
|
||||
# but this is good enough for now.
|
||||
output = nix_config()
|
||||
return self.host_platform.system == output["system"]
|
||||
return self.system == output["system"]
|
||||
|
||||
@property
|
||||
def deployment(self) -> dict:
|
||||
|
||||
Reference in New Issue
Block a user