refactor: replace eval_nix/build_nix with machine.select()
- Remove nix(), eval_nix(), and build_nix() methods from Machine class - Add select() method that handles machine-specific attribute prefixes - Update all usages to use machine.select() directly - Handle Path conversion and tmp_store logic at call sites - This simplifies the Machine API and prepares for deployment.json removal
This commit is contained in:
@@ -992,7 +992,7 @@ def test_dynamic_invalidation(
|
||||
# before generating, dependent generator validation should be empty; see bogus hardware-configuration.nix above
|
||||
# we have to avoid `*.files.value` in this initial select because the generators haven't been run yet
|
||||
# Generators 0: The initial generators before any 'vars generate'
|
||||
generators_0 = machine.eval_nix(f"{gen_prefix}.*.{{validationHash}}")
|
||||
generators_0 = machine.select(f"{gen_prefix}.*.{{validationHash}}")
|
||||
assert generators_0["dependent_generator"]["validationHash"] is None
|
||||
|
||||
# generate both my_generator and (the dependent) dependent_generator
|
||||
@@ -1001,7 +1001,7 @@ def test_dynamic_invalidation(
|
||||
|
||||
# after generating once, dependent generator validation should be set
|
||||
# Generators_1: The generators after the first 'vars generate'
|
||||
generators_1 = machine.eval_nix(gen_prefix)
|
||||
generators_1 = machine.select(gen_prefix)
|
||||
assert generators_1["dependent_generator"]["validationHash"] is not None
|
||||
|
||||
# @tangential: after generating once, neither generator should want to run again because `clan vars generate` should have re-evaluated the dependent generator's validationHash after executing the parent generator but before executing the dependent generator
|
||||
@@ -1014,7 +1014,7 @@ def test_dynamic_invalidation(
|
||||
cli.run(["vars", "generate", "--flake", str(flake.path), machine.name])
|
||||
clan_flake.invalidate_cache()
|
||||
# Generators_2: The generators after the second 'vars generate'
|
||||
generators_2 = machine.eval_nix(gen_prefix)
|
||||
generators_2 = machine.select(gen_prefix)
|
||||
assert (
|
||||
generators_1["dependent_generator"]["validationHash"]
|
||||
== generators_2["dependent_generator"]["validationHash"]
|
||||
|
||||
@@ -72,14 +72,20 @@ class Generator:
|
||||
|
||||
def final_script(self) -> Path:
|
||||
assert self._machine is not None
|
||||
final_script = self._machine.build_nix(
|
||||
f'config.clan.core.vars.generators."{self.name}".finalScript'
|
||||
from clan_lib.nix import nix_test_store
|
||||
|
||||
output = Path(
|
||||
self._machine.select(
|
||||
f'config.clan.core.vars.generators."{self.name}".finalScript'
|
||||
)
|
||||
)
|
||||
return final_script
|
||||
if tmp_store := nix_test_store():
|
||||
output = tmp_store.joinpath(*output.parts[1:])
|
||||
return output
|
||||
|
||||
def validation(self) -> str | None:
|
||||
assert self._machine is not None
|
||||
return self._machine.eval_nix(
|
||||
return self._machine.select(
|
||||
f'config.clan.core.vars.generators."{self.name}".validationHash'
|
||||
)
|
||||
|
||||
|
||||
@@ -33,7 +33,7 @@ class SecretStore(StoreBase):
|
||||
|
||||
@property
|
||||
def _store_backend(self) -> str:
|
||||
backend = self.machine.eval_nix("config.clan.core.vars.settings.passBackend")
|
||||
backend = self.machine.select("config.clan.core.vars.settings.passBackend")
|
||||
return backend
|
||||
|
||||
@property
|
||||
|
||||
@@ -55,7 +55,7 @@ class VmConfig:
|
||||
|
||||
|
||||
def inspect_vm(machine: Machine) -> VmConfig:
|
||||
data = machine.eval_nix("config.clan.core.vm.inspect")
|
||||
data = machine.select("config.clan.core.vm.inspect")
|
||||
# HACK!
|
||||
data["flake_url"] = dataclasses.asdict(machine.flake)
|
||||
return VmConfig.from_json(data)
|
||||
|
||||
@@ -49,16 +49,24 @@ def facts_to_nixos_config(facts: dict[str, dict[str, bytes]]) -> dict:
|
||||
|
||||
|
||||
# TODO move this to the Machines class
|
||||
def build_vm(machine: Machine, tmpdir: Path) -> dict[str, str]:
|
||||
def build_vm(
|
||||
machine: Machine, tmpdir: Path, nix_options: list[str] | None = None
|
||||
) -> dict[str, str]:
|
||||
# TODO pass prompt here for the GTK gui
|
||||
|
||||
if nix_options is None:
|
||||
nix_options = []
|
||||
secrets_dir = get_secrets(machine, tmpdir)
|
||||
|
||||
public_facts = machine.public_facts_store.get_all()
|
||||
from clan_lib.nix import nix_test_store
|
||||
|
||||
nixos_config_file = machine.build_nix(
|
||||
"config.system.clan.vm.create", extra_config=facts_to_nixos_config(public_facts)
|
||||
output = Path(
|
||||
machine.select(
|
||||
"config.system.clan.vm.create",
|
||||
)
|
||||
)
|
||||
if tmp_store := nix_test_store():
|
||||
output = tmp_store.joinpath(*output.parts[1:])
|
||||
nixos_config_file = output
|
||||
try:
|
||||
vm_data = json.loads(Path(nixos_config_file).read_text())
|
||||
vm_data["secrets_dir"] = str(secrets_dir)
|
||||
|
||||
Reference in New Issue
Block a user