cli/install: add option to specify alternative kexec url
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
import argparse
|
import argparse
|
||||||
import subprocess
|
import subprocess
|
||||||
|
from dataclasses import dataclass
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from tempfile import TemporaryDirectory
|
from tempfile import TemporaryDirectory
|
||||||
|
|
||||||
@@ -8,7 +9,7 @@ from ..nix import nix_shell
|
|||||||
from ..secrets.generate import generate_secrets
|
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
|
h = machine.host
|
||||||
target_host = f"{h.user or 'root'}@{h.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)
|
upload_dir.mkdir(parents=True)
|
||||||
machine.run_upload_secrets(upload_dir)
|
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(
|
subprocess.run(
|
||||||
nix_shell(
|
nix_shell(
|
||||||
["nixpkgs#nixos-anywhere"],
|
["nixpkgs#nixos-anywhere"],
|
||||||
[
|
cmd,
|
||||||
"nixos-anywhere",
|
|
||||||
"-f",
|
|
||||||
f"{machine.flake_dir}#{flake_attr}",
|
|
||||||
"-t",
|
|
||||||
"--no-reboot",
|
|
||||||
"--extra-files",
|
|
||||||
str(tmpdir),
|
|
||||||
target_host,
|
|
||||||
],
|
|
||||||
),
|
),
|
||||||
check=True,
|
check=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def install_command(args: argparse.Namespace) -> None:
|
@dataclass
|
||||||
machine = Machine(args.machine, flake_dir=args.flake)
|
class InstallOptions:
|
||||||
machine.deployment_address = args.target_host
|
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:
|
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(
|
parser.add_argument(
|
||||||
"machine",
|
"machine",
|
||||||
type=str,
|
type=str,
|
||||||
|
|||||||
Reference in New Issue
Block a user