machines: add endpoint machines/{name}/ verify
This commit is contained in:
@@ -28,10 +28,7 @@ def map_type(type: str) -> Any:
|
||||
"16 bit unsigned integer; between 0 and 65535 (both inclusive)",
|
||||
]:
|
||||
return int
|
||||
elif type == "string":
|
||||
return str
|
||||
# lib.type.passwdEntry
|
||||
elif type == "string, not containing newlines or colons":
|
||||
elif type.startswith("string"):
|
||||
return str
|
||||
elif type.startswith("null or "):
|
||||
subtype = type.removeprefix("null or ")
|
||||
|
||||
@@ -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():
|
||||
|
||||
Reference in New Issue
Block a user