forked from clan/clan-core
cli/install: add option to specify alternative kexec url
This commit is contained in:
parent
55f91079c7
commit
ed643e3829
@ -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,
|
||||
|
Loading…
Reference in New Issue
Block a user