clan-lib: Move nix_options from Machine class to Flake class

This commit is contained in:
Qubasa
2025-06-23 13:46:10 +02:00
parent d3d2cb8723
commit d14a5d34fd
11 changed files with 57 additions and 54 deletions

View File

@@ -17,9 +17,7 @@ from clan_lib.nix_models.clan import InventoryMachine
log = logging.getLogger(__name__)
def list_full_machines(
flake: Flake, nix_options: list[str] | None = None
) -> dict[str, Machine]:
def list_full_machines(flake: Flake) -> dict[str, Machine]:
"""
Like `list_machines`, but returns a full 'machine' instance for each machine.
"""
@@ -27,9 +25,6 @@ def list_full_machines(
res: dict[str, Machine] = {}
if nix_options is None:
nix_options = []
for inv_machine in machines.values():
name = inv_machine.get("name")
# Technically, this should not happen, but we are defensive here.
@@ -37,11 +32,7 @@ def list_full_machines(
msg = "InternalError: Machine name is required. But got a machine without a name."
raise ClanError(msg)
machine = Machine(
name=name,
flake=flake,
nix_options=nix_options,
)
machine = Machine(name=name, flake=flake)
res[machine.name] = machine
return res

View File

@@ -2,7 +2,7 @@ import importlib
import json
import logging
import re
from dataclasses import dataclass, field
from dataclasses import dataclass
from functools import cached_property
from pathlib import Path
from typing import TYPE_CHECKING, Any, Literal
@@ -30,8 +30,6 @@ class Machine:
name: str
flake: Flake
nix_options: list[str] = field(default_factory=list)
def get_inv_machine(self) -> "InventoryMachine":
return get_machine(self.flake, self.name)
@@ -177,8 +175,7 @@ class Machine:
system = config["system"]
return self.flake.select(
f'clanInternals.machines."{system}"."{self.name}".{attr}',
nix_options=nix_options,
f'clanInternals.machines."{system}"."{self.name}".{attr}'
)
def eval_nix(

View File

@@ -124,6 +124,8 @@ def deploy_machine(
path = upload_sources(machine, sudo_host)
nix_options = machine.flake.nix_options if machine.flake.nix_options else []
nix_options = [
"--show-trace",
"--option",
@@ -133,7 +135,7 @@ def deploy_machine(
"accept-flake-config",
"true",
"-L",
*machine.nix_options,
*nix_options,
"--flake",
f"{path}#{machine.name}",
]