Merge pull request 'fix: check if phases are non-default when installing' (#5024) from sachk/clan-core:main into main
Reviewed-on: https://git.clan.lol/clan/clan-core/pulls/5024
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
|
from enum import Enum
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from tempfile import TemporaryDirectory
|
from tempfile import TemporaryDirectory
|
||||||
from time import time
|
from time import time
|
||||||
@@ -25,14 +26,13 @@ log = logging.getLogger(__name__)
|
|||||||
BuildOn = Literal["auto", "local", "remote"]
|
BuildOn = Literal["auto", "local", "remote"]
|
||||||
|
|
||||||
|
|
||||||
Step = Literal[
|
class Step(str, Enum):
|
||||||
"generators",
|
GENERATORS = "generators"
|
||||||
"upload-secrets",
|
UPLOAD_SECRETS = "upload-secrets"
|
||||||
"nixos-anywhere",
|
NIXOS_ANYWHERE = "nixos-anywhere"
|
||||||
"formatting",
|
FORMATTING = "formatting"
|
||||||
"rebooting",
|
REBOOTING = "rebooting"
|
||||||
"installing",
|
INSTALLING = "installing"
|
||||||
]
|
|
||||||
|
|
||||||
|
|
||||||
def notify_install_step(current: Step) -> None:
|
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 the UI about what we are doing
|
||||||
notify_install_step("generators")
|
notify_install_step(Step.GENERATORS)
|
||||||
generate_facts([machine])
|
generate_facts([machine])
|
||||||
run_generators([machine], generators=None, full_closure=False)
|
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)
|
upload_dir.mkdir(parents=True)
|
||||||
|
|
||||||
# Notify the UI about what we are doing
|
# 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_facts_store.upload(upload_dir)
|
||||||
machine.secret_vars_store.populate_dir(
|
machine.secret_vars_store.populate_dir(
|
||||||
machine.name,
|
machine.name,
|
||||||
@@ -214,26 +214,28 @@ def run_machine_install(opts: InstallOptions, target_host: Remote) -> None:
|
|||||||
cmd,
|
cmd,
|
||||||
)
|
)
|
||||||
|
|
||||||
notify_install_step("nixos-anywhere")
|
install_steps = {
|
||||||
run(
|
"kexec": Step.NIXOS_ANYWHERE,
|
||||||
[*cmd, "--phases", "kexec"],
|
"disko": Step.FORMATTING,
|
||||||
RunOpts(log=Log.BOTH, prefix=machine.name, needs_user_terminal=True),
|
"install": Step.INSTALLING,
|
||||||
)
|
"reboot": Step.REBOOTING,
|
||||||
notify_install_step("formatting")
|
}
|
||||||
run(
|
|
||||||
[*cmd, "--phases", "disko"],
|
def run_phase(phase: str) -> None:
|
||||||
RunOpts(log=Log.BOTH, prefix=machine.name, needs_user_terminal=True),
|
notification = install_steps.get(phase, Step.NIXOS_ANYWHERE)
|
||||||
)
|
notify_install_step(notification)
|
||||||
notify_install_step("installing")
|
run(
|
||||||
run(
|
[*cmd, "--phases", phase],
|
||||||
[*cmd, "--phases", "install"],
|
RunOpts(log=Log.BOTH, prefix=machine.name, needs_user_terminal=True),
|
||||||
RunOpts(log=Log.BOTH, prefix=machine.name, needs_user_terminal=True),
|
)
|
||||||
)
|
|
||||||
notify_install_step("rebooting")
|
if opts.phases:
|
||||||
run(
|
phases = [phase.strip() for phase in opts.phases.split(",")]
|
||||||
[*cmd, "--phases", "reboot"],
|
for phase in phases:
|
||||||
RunOpts(log=Log.BOTH, prefix=machine.name, needs_user_terminal=True),
|
run_phase(phase)
|
||||||
)
|
else:
|
||||||
|
for phase in ["kexec", "disko", "install", "reboot"]:
|
||||||
|
run_phase(phase)
|
||||||
|
|
||||||
if opts.persist_state:
|
if opts.persist_state:
|
||||||
inventory_store = InventoryStore(machine.flake)
|
inventory_store = InventoryStore(machine.flake)
|
||||||
|
|||||||
Reference in New Issue
Block a user