This commit is contained in:
Jakub Kropáček 2025-01-07 16:16:58 +01:00
parent 22e5ffb4b4
commit be8f8fbbf9

View file

@ -18,6 +18,35 @@ def _validate_ip(ip: str) -> bool:
except ValueError:
return False
def _check_ssh_connection(ip: str) -> bool:
try:
check_output(['ssh', f'root@{ip}', 'echo', 'Connected'])
return True
except Exception:
return False
def bootstrap_machine(ip: str):
check_output(
[
'nix',
'run',
'github:nix-community/nixos-anywhere',
'--',
'--flake',
'".#bootstrap"',
'--target-host',
f'root@{ip}',
'--build-on-remote'
]
)
def get_ssh_key(ip: str) -> str:
"""
This function uses machines ssh-keyscan to get the ssh key and then get the ed25519 key
"""
def get_machine_config(machine_name: str) -> dict:
output = check_output(['nix', 'eval', '--json', f'.#nixosConfigurations.{machine_name}.config.kropcloud'])
return json.loads(output)
@ -41,12 +70,15 @@ def main() -> int:
# We are bootstraping the machine first because we need their ssh keys
bootstrap_machine()
# while not check_ssh_connection():
# time.sleep(5)
while not _check_ssh_connection():
time.sleep(5)
# # connect and get ssh keys
# ssh_key = get_ssh_key()
ssh_key = get_ssh_key()
# Add the ssh key to keys in secrets/secrets.nix
# and rekey the secrets
# install_machine()