Merge pull request 'cli/install: add option to specify alternative kexec url' (#659) from Mic92-wayland-update into main
This commit is contained in:
commit
4d8c20f284
@ -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,10 +27,7 @@ def install_nixos(machine: Machine) -> None:
|
||||
upload_dir.mkdir(parents=True)
|
||||
machine.run_upload_secrets(upload_dir)
|
||||
|
||||
subprocess.run(
|
||||
nix_shell(
|
||||
["nixpkgs#nixos-anywhere"],
|
||||
[
|
||||
cmd = [
|
||||
"nixos-anywhere",
|
||||
"-f",
|
||||
f"{machine.flake_dir}#{flake_attr}",
|
||||
@ -37,21 +35,47 @@ def install_nixos(machine: Machine) -> None:
|
||||
"--no-reboot",
|
||||
"--extra-files",
|
||||
str(tmpdir),
|
||||
target_host,
|
||||
],
|
||||
]
|
||||
if kexec:
|
||||
cmd += ["--kexec", kexec]
|
||||
cmd.append(target_host)
|
||||
|
||||
subprocess.run(
|
||||
nix_shell(
|
||||
["nixpkgs#nixos-anywhere"],
|
||||
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