machines: add endpoint machines/{name}/ verify

This commit is contained in:
DavHau
2023-10-24 16:30:58 +01:00
parent 3288185f66
commit f1e7495806
5 changed files with 71 additions and 12 deletions

View File

@@ -12,6 +12,32 @@ from clan_cli.machines.folders import machine_folder, machine_settings_file
from clan_cli.nix import nix_eval
def verify_machine_config(
machine_name: str, flake: Optional[Path] = None
) -> tuple[bool, Optional[str]]:
"""
Verify that the machine evaluates successfully
Returns a tuple of (success, error_message)
"""
if flake is None:
flake = get_clan_flake_toplevel()
proc = subprocess.run(
nix_eval(
flags=[
"--impure",
"--show-trace",
f".#nixosConfigurations.{machine_name}.config.system.build.toplevel.outPath",
],
),
capture_output=True,
text=True,
cwd=flake,
)
if proc.returncode != 0:
return False, proc.stderr
return True, None
def config_for_machine(machine_name: str) -> dict:
# read the config from a json file located at {flake}/machines/{machine_name}/settings.json
if not machine_folder(machine_name).exists():