machines build_machine_data: raise ClanError on error

This commit is contained in:
lassulus 2023-12-16 20:58:35 +01:00
parent 902ccbc90b
commit 56dafff109

View File

@ -4,6 +4,7 @@ import subprocess
import sys import sys
from pathlib import Path from pathlib import Path
from ..errors import ClanError
from ..nix import nix_build, nix_config, nix_eval from ..nix import nix_build, nix_config, nix_eval
from ..ssh import Host, parse_deployment_address from ..ssh import Host, parse_deployment_address
@ -12,17 +13,22 @@ def build_machine_data(machine_name: str, clan_dir: Path) -> dict:
config = nix_config() config = nix_config()
system = config["system"] system = config["system"]
outpath = subprocess.run( proc = subprocess.run(
nix_build( nix_build(
[ [
f'path:{clan_dir}#clanInternals.machines."{system}"."{machine_name}".config.system.clan.deployment.file' f'{clan_dir}#clanInternals.machines."{system}"."{machine_name}".config.system.clan.deployment.file'
] ]
), ),
stdout=subprocess.PIPE, stdout=subprocess.PIPE,
check=True, check=True,
text=True, text=True,
).stdout.strip() )
return json.loads(Path(outpath).read_text())
if proc.returncode != 0:
ClanError("failed to build machine data")
exit(1)
return json.loads(Path(proc.stdout.strip()).read_text())
class Machine: class Machine: