Compare commits
1 Commits
try-fix-fl
...
pr-4283-ge
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
84a21d1bab |
@@ -59,7 +59,7 @@
|
||||
name = "flash";
|
||||
nodes.target = {
|
||||
virtualisation.emptyDiskImages = [ 4096 ];
|
||||
virtualisation.memorySize = 4096;
|
||||
virtualisation.memorySize = 3000;
|
||||
environment.systemPackages = [ self.packages.${pkgs.system}.clan-cli ];
|
||||
environment.etc."install-closure".source = "${closureInfo}/store-paths";
|
||||
|
||||
|
||||
@@ -62,19 +62,18 @@ class Generator:
|
||||
def generators_from_flake(
|
||||
cls: type["Generator"], machine_name: str, flake: "Flake"
|
||||
) -> list["Generator"]:
|
||||
config = nix_config()
|
||||
system = config["system"]
|
||||
|
||||
# Get all generator metadata in one select (safe fields only)
|
||||
generators_data = flake.select(
|
||||
f'clanInternals.machines."{system}"."{machine_name}".config.clan.core.vars.generators.*.{{share,dependencies,migrateFact,prompts}}'
|
||||
generators_data = flake.select_machine(
|
||||
machine_name,
|
||||
"config.clan.core.vars.generators.*.{share,dependencies,migrateFact,prompts}",
|
||||
)
|
||||
if not generators_data:
|
||||
return []
|
||||
|
||||
# Get all file metadata in one select
|
||||
files_data = flake.select(
|
||||
f'clanInternals.machines."{system}"."{machine_name}".config.clan.core.vars.generators.*.files.*.{{secret,deploy,owner,group,mode,neededFor}}'
|
||||
files_data = flake.select_machine(
|
||||
machine_name,
|
||||
"config.clan.core.vars.generators.*.files.*.{secret,deploy,owner,group,mode,neededFor}",
|
||||
)
|
||||
|
||||
generators = []
|
||||
|
||||
@@ -119,9 +119,11 @@ def run_machine_update(
|
||||
with ExitStack() as stack:
|
||||
target_host = stack.enter_context(target_host.ssh_control_master())
|
||||
|
||||
if build_host:
|
||||
if build_host is not None:
|
||||
build_host = stack.enter_context(build_host.ssh_control_master())
|
||||
|
||||
host = build_host or target_host
|
||||
|
||||
sudo_host = stack.enter_context(target_host.become_root())
|
||||
|
||||
generate_facts([machine], service=None, regenerate=False)
|
||||
@@ -130,10 +132,7 @@ def run_machine_update(
|
||||
upload_secrets(machine, sudo_host)
|
||||
upload_secret_vars(machine, sudo_host)
|
||||
|
||||
if build_host:
|
||||
path = upload_sources(machine, build_host)
|
||||
else:
|
||||
path = upload_sources(machine, target_host)
|
||||
path = upload_sources(machine, sudo_host)
|
||||
|
||||
nix_options = machine.flake.nix_options if machine.flake.nix_options else []
|
||||
|
||||
@@ -175,13 +174,11 @@ def run_machine_update(
|
||||
*nix_options,
|
||||
]
|
||||
|
||||
if become_root and not build_host:
|
||||
target_host = sudo_host
|
||||
if become_root:
|
||||
host = sudo_host
|
||||
|
||||
deploy_host = build_host if build_host else target_host
|
||||
|
||||
remote_env = deploy_host.nix_ssh_env(control_master=False)
|
||||
ret = deploy_host.run(
|
||||
remote_env = host.nix_ssh_env(control_master=False)
|
||||
ret = host.run(
|
||||
switch_cmd,
|
||||
RunOpts(
|
||||
check=False,
|
||||
@@ -208,7 +205,7 @@ def run_machine_update(
|
||||
machine.info(
|
||||
"Mobile machine detected, applying workaround deployment method"
|
||||
)
|
||||
ret = deploy_host.run(
|
||||
ret = host.run(
|
||||
["nixos--rebuild", "test", *nix_options] if is_mobile else switch_cmd,
|
||||
RunOpts(
|
||||
log=Log.BOTH,
|
||||
|
||||
@@ -44,6 +44,41 @@ def get_machine_names(repo_root: Path, check_attr: str, system: str) -> list[str
|
||||
return json.loads(out.stdout.strip())
|
||||
|
||||
|
||||
class TestFlake(Flake):
|
||||
"""
|
||||
Flake class which is able to deal with not having an actual flake.
|
||||
All nix build and eval calls will be forwarded to:
|
||||
clan-core#checks.<system>.<test_name>
|
||||
"""
|
||||
|
||||
def __init__(self, check_attr: str, *args: Any, **kwargs: Any) -> None:
|
||||
"""
|
||||
Initialize the TestFlake with the check attribute.
|
||||
"""
|
||||
super().__init__(*args, **kwargs)
|
||||
self.check_attr = check_attr
|
||||
|
||||
def select_machine(self, machine_name: str, selector: str) -> Any:
|
||||
"""
|
||||
Select a nix attribute for a specific machine.
|
||||
|
||||
Args:
|
||||
machine_name: The name of the machine
|
||||
selector: The attribute selector string relative to the machine config
|
||||
apply: Optional function to apply to the result
|
||||
"""
|
||||
from clan_lib.nix import nix_config
|
||||
|
||||
config = nix_config()
|
||||
system = config["system"]
|
||||
test_system = system
|
||||
if system.endswith("-darwin"):
|
||||
test_system = system.rstrip("darwin") + "linux"
|
||||
|
||||
full_selector = f'checks."{test_system}".{self.check_attr}.machinesCross.{system}."{machine_name}".{selector}'
|
||||
return self.select(full_selector)
|
||||
|
||||
|
||||
class TestMachine(Machine):
|
||||
"""
|
||||
Machine class which is able to deal with not having an actual flake.
|
||||
@@ -151,7 +186,7 @@ def main() -> None:
|
||||
if system.endswith("-darwin"):
|
||||
test_system = system.rstrip("darwin") + "linux"
|
||||
|
||||
flake = Flake(str(opts.repo_root))
|
||||
flake = TestFlake(opts.check_attr, str(opts.repo_root))
|
||||
machine_names = get_machine_names(
|
||||
opts.repo_root,
|
||||
opts.check_attr,
|
||||
@@ -164,6 +199,9 @@ def main() -> None:
|
||||
]
|
||||
)
|
||||
|
||||
# This hack is necessary because the sops store uses flake.path to find the machine keys
|
||||
flake._path = opts.test_dir # noqa: SLF001
|
||||
|
||||
machines = [
|
||||
TestMachine(name, flake, test_dir, opts.check_attr) for name in machine_names
|
||||
]
|
||||
|
||||
Reference in New Issue
Block a user