From ed643e3829334f868f3fe109d607cf23c1c81519 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Thalheim?= Date: Tue, 26 Dec 2023 14:36:51 +0100 Subject: [PATCH] cli/install: add option to specify alternative kexec url --- pkgs/clan-cli/clan_cli/machines/install.py | 54 ++++++++++++++++------ 1 file changed, 39 insertions(+), 15 deletions(-) diff --git a/pkgs/clan-cli/clan_cli/machines/install.py b/pkgs/clan-cli/clan_cli/machines/install.py index 75559618..b871c679 100644 --- a/pkgs/clan-cli/clan_cli/machines/install.py +++ b/pkgs/clan-cli/clan_cli/machines/install.py @@ -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,