clan-app: Add password input

This commit is contained in:
Qubasa
2025-09-02 13:37:12 +02:00
parent 0ac6d7be87
commit 53ce3cf53d
4 changed files with 46 additions and 5 deletions

View File

@@ -1,5 +1,6 @@
import json
import logging
import os
from dataclasses import dataclass
from enum import Enum
from pathlib import Path
@@ -91,6 +92,15 @@ def run_machine_hardware_info(
str(opts.backend.config_path(machine)),
]
environ = os.environ.copy()
if target_host.password:
cmd += [
"--env-password",
"--ssh-option",
"IdentitiesOnly=yes",
]
environ["SSHPASS"] = target_host.password
if target_host.private_key:
cmd += ["--ssh-option", f"IdentityFile={target_host.private_key}"]
@@ -113,7 +123,9 @@ def run_machine_hardware_info(
run(
cmd,
RunOpts(log=Log.BOTH, prefix=machine.name, needs_user_terminal=True),
RunOpts(
log=Log.BOTH, prefix=machine.name, needs_user_terminal=True, env=environ
),
)
print(f"Successfully generated: {hw_file}")

View File

@@ -122,9 +122,6 @@ def run_machine_install(opts: InstallOptions, target_host: Remote) -> None:
phases=["partitioning"],
)
if target_host.password:
os.environ["SSHPASS"] = target_host.password
cmd = [
"nixos-anywhere",
"--flake",
@@ -161,12 +158,14 @@ def run_machine_install(opts: InstallOptions, target_host: Remote) -> None:
],
)
environ = os.environ.copy()
if target_host.password:
cmd += [
"--env-password",
"--ssh-option",
"IdentitiesOnly=yes",
]
environ["SSHPASS"] = target_host.password
# Always set a nixos-anywhere private key to prevent failures when running
# 'clan install --phases kexec' followed by 'clan install --phases disko,install,reboot'.
@@ -226,7 +225,12 @@ def run_machine_install(opts: InstallOptions, target_host: Remote) -> None:
notify_install_step(notification)
run(
[*cmd, "--phases", phase],
RunOpts(log=Log.BOTH, prefix=machine.name, needs_user_terminal=True),
RunOpts(
log=Log.BOTH,
prefix=machine.name,
needs_user_terminal=True,
env=environ,
),
)
if opts.phases: