From 1a766a34471508d6ad3e1a26fee5b8de64733a71 Mon Sep 17 00:00:00 2001 From: Sacha Korban Date: Fri, 29 Aug 2025 18:27:03 +1000 Subject: [PATCH 1/2] fix: check if phases are non-default when running --- pkgs/clan-cli/clan_lib/machines/install.py | 42 +++++++++++----------- 1 file changed, 22 insertions(+), 20 deletions(-) diff --git a/pkgs/clan-cli/clan_lib/machines/install.py b/pkgs/clan-cli/clan_lib/machines/install.py index b67014bb0..b2b571e8a 100644 --- a/pkgs/clan-cli/clan_lib/machines/install.py +++ b/pkgs/clan-cli/clan_lib/machines/install.py @@ -214,26 +214,28 @@ def run_machine_install(opts: InstallOptions, target_host: Remote) -> None: cmd, ) - notify_install_step("nixos-anywhere") - run( - [*cmd, "--phases", "kexec"], - RunOpts(log=Log.BOTH, prefix=machine.name, needs_user_terminal=True), - ) - notify_install_step("formatting") - run( - [*cmd, "--phases", "disko"], - RunOpts(log=Log.BOTH, prefix=machine.name, needs_user_terminal=True), - ) - notify_install_step("installing") - run( - [*cmd, "--phases", "install"], - RunOpts(log=Log.BOTH, prefix=machine.name, needs_user_terminal=True), - ) - notify_install_step("rebooting") - run( - [*cmd, "--phases", "reboot"], - RunOpts(log=Log.BOTH, prefix=machine.name, needs_user_terminal=True), - ) + install_steps = { + "kexec": "nixos-anywhere", + "disko": "formatting", + "install": "installing", + "reboot": "rebooting", + } + + def run_phase(phase: str) -> None: + notification = install_steps.get(phase, "nixos-anywhere") + notify_install_step(notification) + run( + [*cmd, "--phases", phase], + RunOpts(log=Log.BOTH, prefix=machine.name, needs_user_terminal=True), + ) + + if opts.phases: + phases = [phase.strip() for phase in opts.phases.split(",")] + for phase in phases: + run_phase(phase) + else: + for phase in ["kexec", "disko", "install", "reboot"]: + run_phase(phase) if opts.persist_state: inventory_store = InventoryStore(machine.flake) From c34a21a3bbb0675162ddb15d15d0716aef04fc3d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Thalheim?= Date: Fri, 29 Aug 2025 17:45:16 +0200 Subject: [PATCH 2/2] install: make Step a String enum --- pkgs/clan-cli/clan_lib/machines/install.py | 30 +++++++++++----------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/pkgs/clan-cli/clan_lib/machines/install.py b/pkgs/clan-cli/clan_lib/machines/install.py index b2b571e8a..231e13337 100644 --- a/pkgs/clan-cli/clan_lib/machines/install.py +++ b/pkgs/clan-cli/clan_lib/machines/install.py @@ -1,6 +1,7 @@ import logging import os from dataclasses import dataclass +from enum import Enum from pathlib import Path from tempfile import TemporaryDirectory from time import time @@ -25,14 +26,13 @@ log = logging.getLogger(__name__) BuildOn = Literal["auto", "local", "remote"] -Step = Literal[ - "generators", - "upload-secrets", - "nixos-anywhere", - "formatting", - "rebooting", - "installing", -] +class Step(str, Enum): + GENERATORS = "generators" + UPLOAD_SECRETS = "upload-secrets" + NIXOS_ANYWHERE = "nixos-anywhere" + FORMATTING = "formatting" + REBOOTING = "rebooting" + INSTALLING = "installing" def notify_install_step(current: Step) -> None: @@ -93,7 +93,7 @@ def run_machine_install(opts: InstallOptions, target_host: Remote) -> None: ) # Notify the UI about what we are doing - notify_install_step("generators") + notify_install_step(Step.GENERATORS) generate_facts([machine]) run_generators([machine], generators=None, full_closure=False) @@ -106,7 +106,7 @@ def run_machine_install(opts: InstallOptions, target_host: Remote) -> None: upload_dir.mkdir(parents=True) # Notify the UI about what we are doing - notify_install_step("upload-secrets") + notify_install_step(Step.UPLOAD_SECRETS) machine.secret_facts_store.upload(upload_dir) machine.secret_vars_store.populate_dir( machine.name, @@ -215,14 +215,14 @@ def run_machine_install(opts: InstallOptions, target_host: Remote) -> None: ) install_steps = { - "kexec": "nixos-anywhere", - "disko": "formatting", - "install": "installing", - "reboot": "rebooting", + "kexec": Step.NIXOS_ANYWHERE, + "disko": Step.FORMATTING, + "install": Step.INSTALLING, + "reboot": Step.REBOOTING, } def run_phase(phase: str) -> None: - notification = install_steps.get(phase, "nixos-anywhere") + notification = install_steps.get(phase, Step.NIXOS_ANYWHERE) notify_install_step(notification) run( [*cmd, "--phases", phase],