clan-cli: Add --wifi option to set wifi credentials. clan-app: Add wifi settings form to flash view
This commit is contained in:
@@ -24,11 +24,18 @@ from .nix import nix_build, nix_shell
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
@dataclass
|
||||
class WifiConfig:
|
||||
ssid: str
|
||||
password: str
|
||||
|
||||
|
||||
@dataclass
|
||||
class SystemConfig:
|
||||
language: str | None = field(default=None)
|
||||
keymap: str | None = field(default=None)
|
||||
ssh_keys_path: list[str] | None = field(default=None)
|
||||
wifi_settings: list[WifiConfig] | None = field(default=None)
|
||||
|
||||
|
||||
@API.register
|
||||
@@ -91,6 +98,12 @@ def flash_machine(
|
||||
) -> None:
|
||||
system_config_nix: dict[str, Any] = {}
|
||||
|
||||
if system_config.wifi_settings:
|
||||
wifi_settings = {}
|
||||
for wifi in system_config.wifi_settings:
|
||||
wifi_settings[wifi.ssid] = {"password": wifi.password}
|
||||
system_config_nix["clan"] = {"iwd": {"networks": wifi_settings}}
|
||||
|
||||
if system_config.language:
|
||||
if system_config.language not in list_possible_languages():
|
||||
raise ClanError(
|
||||
@@ -214,6 +227,7 @@ def flash_command(args: argparse.Namespace) -> None:
|
||||
language=args.language,
|
||||
keymap=args.keymap,
|
||||
ssh_keys_path=args.ssh_pubkey,
|
||||
wifi_settings=None,
|
||||
),
|
||||
write_efi_boot_entries=args.write_efi_boot_entries,
|
||||
nix_options=args.option,
|
||||
@@ -229,6 +243,12 @@ def flash_command(args: argparse.Namespace) -> None:
|
||||
print(keymap)
|
||||
return
|
||||
|
||||
if args.wifi:
|
||||
opts.system_config.wifi_settings = [
|
||||
WifiConfig(ssid=ssid, password=password)
|
||||
for ssid, password in args.wifi.items()
|
||||
]
|
||||
|
||||
machine = Machine(opts.machine, flake=opts.flake)
|
||||
if opts.confirm and not opts.dry_run:
|
||||
disk_str = ", ".join(f"{name}={device}" for name, device in opts.disks.items())
|
||||
@@ -277,6 +297,15 @@ def register_parser(parser: argparse.ArgumentParser) -> None:
|
||||
Mount is useful for updating an existing system without losing data.
|
||||
"""
|
||||
)
|
||||
parser.add_argument(
|
||||
"--wifi",
|
||||
type=str,
|
||||
nargs=2,
|
||||
metavar=("ssid", "password"),
|
||||
action=AppendDiskAction,
|
||||
help="wifi network to connect to",
|
||||
default={},
|
||||
)
|
||||
parser.add_argument(
|
||||
"--mode",
|
||||
type=str,
|
||||
|
||||
Reference in New Issue
Block a user