Merge pull request 'cli/install: add option to specify alternative kexec url' (#659) from Mic92-wayland-update into main
All checks were successful
assets1 / test (push) Successful in 22s
checks / test (push) Successful in 29s
checks-impure / test (push) Successful in 1m2s

This commit is contained in:
clan-bot 2023-12-26 13:40:29 +00:00
commit 4d8c20f284

View File

@ -1,5 +1,6 @@
import argparse
import subprocess
from dataclasses import dataclass
from pathlib import Path
from tempfile import TemporaryDirectory
@ -8,7 +9,7 @@ from ..nix import nix_shell
from ..secrets.generate import generate_secrets
def install_nixos(machine: Machine) -> None:
def install_nixos(machine: Machine, kexec: str | None = None) -> None:
h = machine.host
target_host = f"{h.user or 'root'}@{h.host}"
@ -26,32 +27,55 @@ def install_nixos(machine: Machine) -> None:
upload_dir.mkdir(parents=True)
machine.run_upload_secrets(upload_dir)
cmd = [
"nixos-anywhere",
"-f",
f"{machine.flake_dir}#{flake_attr}",
"-t",
"--no-reboot",
"--extra-files",
str(tmpdir),
]
if kexec:
cmd += ["--kexec", kexec]
cmd.append(target_host)
subprocess.run(
nix_shell(
["nixpkgs#nixos-anywhere"],
[
"nixos-anywhere",
"-f",
f"{machine.flake_dir}#{flake_attr}",
"-t",
"--no-reboot",
"--extra-files",
str(tmpdir),
target_host,
],
cmd,
),
check=True,
)
def install_command(args: argparse.Namespace) -> None:
machine = Machine(args.machine, flake_dir=args.flake)
machine.deployment_address = args.target_host
@dataclass
class InstallOptions:
flake: Path
machine: str
target_host: str
kexec: str | None
install_nixos(machine)
def install_command(args: argparse.Namespace) -> None:
opts = InstallOptions(
flake=args.flake,
machine=args.machine,
target_host=args.target_host,
kexec=args.kexec,
)
machine = Machine(opts.machine, flake_dir=opts.flake)
machine.deployment_address = opts.target_host
install_nixos(machine, kexec=opts.kexec)
def register_install_parser(parser: argparse.ArgumentParser) -> None:
parser.add_argument(
"--kexec",
type=str,
help="use another kexec tarball to bootstrap NixOS",
)
parser.add_argument(
"machine",
type=str,