Added new type FlakeName

This commit is contained in:
2023-10-14 15:17:58 +02:00
parent 718f647774
commit 6def19b4c8
17 changed files with 97 additions and 72 deletions

View File

@@ -11,6 +11,7 @@ from typing import Any, Optional, Tuple, get_origin
from clan_cli.dirs import machine_settings_file, specific_flake_dir
from clan_cli.errors import ClanError
from clan_cli.flakes.types import FlakeName
from clan_cli.git import commit_file
from clan_cli.nix import nix_eval
@@ -107,7 +108,7 @@ def cast(value: Any, type: Any, opt_description: str) -> Any:
def options_for_machine(
flake_name: str, machine_name: str, show_trace: bool = False
flake_name: FlakeName, machine_name: str, show_trace: bool = False
) -> dict:
clan_dir = specific_flake_dir(flake_name)
flags = []
@@ -130,7 +131,7 @@ def options_for_machine(
def read_machine_option_value(
flake_name: str, machine_name: str, option: str, show_trace: bool = False
flake_name: FlakeName, machine_name: str, option: str, show_trace: bool = False
) -> str:
clan_dir = specific_flake_dir(flake_name)
# use nix eval to read from .#nixosConfigurations.default.config.{option}
@@ -243,7 +244,7 @@ def find_option(
def set_option(
flake_name: str,
flake_name: FlakeName,
option: str,
value: Any,
options: dict,

View File

@@ -14,8 +14,10 @@ from clan_cli.dirs import (
from clan_cli.git import commit_file, find_git_repo_root
from clan_cli.nix import nix_eval
from ..flakes.types import FlakeName
def config_for_machine(flake_name: str, machine_name: str) -> dict:
def config_for_machine(flake_name: FlakeName, machine_name: str) -> dict:
# read the config from a json file located at {flake}/machines/{machine_name}/settings.json
if not specific_machine_dir(flake_name, machine_name).exists():
raise HTTPException(
@@ -29,7 +31,9 @@ def config_for_machine(flake_name: str, machine_name: str) -> dict:
return json.load(f)
def set_config_for_machine(flake_name: str, machine_name: str, config: dict) -> None:
def set_config_for_machine(
flake_name: FlakeName, machine_name: str, config: dict
) -> None:
# write the config to a json file located at {flake}/machines/{machine_name}/settings.json
if not specific_machine_dir(flake_name, machine_name).exists():
raise HTTPException(
@@ -46,7 +50,7 @@ def set_config_for_machine(flake_name: str, machine_name: str, config: dict) ->
commit_file(settings_path, repo_dir)
def schema_for_machine(flake_name: str, machine_name: str) -> dict:
def schema_for_machine(flake_name: FlakeName, machine_name: str) -> dict:
flake = specific_flake_dir(flake_name)
# use nix eval to lib.evalModules .#nixosModules.machine-{machine_name}