From 25875422f2160823874aa345d29e6eecfb9fa815 Mon Sep 17 00:00:00 2001 From: Johannes Kirschbauer Date: Mon, 9 Jun 2025 20:30:20 +0200 Subject: [PATCH 1/3] chore(api/create_clan): remove unused reponse class --- pkgs/clan-cli/clan_lib/clan/create.py | 33 +++++++-------------------- 1 file changed, 8 insertions(+), 25 deletions(-) diff --git a/pkgs/clan-cli/clan_lib/clan/create.py b/pkgs/clan-cli/clan_lib/clan/create.py index d9be66f06..fa104c562 100644 --- a/pkgs/clan-cli/clan_lib/clan/create.py +++ b/pkgs/clan-cli/clan_lib/clan/create.py @@ -3,7 +3,7 @@ from dataclasses import dataclass from pathlib import Path from clan_lib.api import API -from clan_lib.cmd import CmdOut, RunOpts, run +from clan_lib.cmd import RunOpts, run from clan_lib.errors import ClanError from clan_lib.flake import Flake from clan_lib.nix import nix_command, nix_metadata, nix_shell @@ -18,15 +18,6 @@ from clan_lib.templates import ( log = logging.getLogger(__name__) -@dataclass -class CreateClanResponse: - flake_update: CmdOut | None = None - git_init: CmdOut | None = None - git_add: CmdOut | None = None - git_config_username: CmdOut | None = None - git_config_email: CmdOut | None = None - - @dataclass class CreateOptions: dest: Path @@ -43,7 +34,7 @@ def git_command(directory: Path, *args: str) -> list[str]: @API.register -def create_clan(opts: CreateOptions) -> CreateClanResponse: +def create_clan(opts: CreateOptions) -> None: dest = opts.dest.resolve() if opts.src_flake is not None: @@ -75,36 +66,28 @@ def create_clan(opts: CreateOptions) -> CreateClanResponse: copy_from_nixstore(src, dest) - response = CreateClanResponse() - if opts.setup_git: - response.git_init = run(git_command(dest, "init")) - response.git_add = run(git_command(dest, "add", ".")) + run(git_command(dest, "init")) + run(git_command(dest, "add", ".")) # check if username is set has_username = run( git_command(dest, "config", "user.name"), RunOpts(check=False) ) - response.git_config_username = None if has_username.returncode != 0: - response.git_config_username = run( - git_command(dest, "config", "user.name", "clan-tool") - ) + run(git_command(dest, "config", "user.name", "clan-tool")) has_username = run( git_command(dest, "config", "user.email"), RunOpts(check=False) ) if has_username.returncode != 0: - response.git_config_email = run( - git_command(dest, "config", "user.email", "clan@example.com") - ) + run(git_command(dest, "config", "user.email", "clan@example.com")) if opts.update_clan: - flake_update = run(nix_command(["flake", "update"]), RunOpts(cwd=dest)) - response.flake_update = flake_update + run(nix_command(["flake", "update"]), RunOpts(cwd=dest)) if opts.initial: inventory_store = InventoryStore(flake=Flake(str(opts.dest))) inventory_store.write(opts.initial, message="Init inventory") - return response + return From 03a24122277fde997dcf1ba3c0e151dded8e9e20 Mon Sep 17 00:00:00 2001 From: Johannes Kirschbauer Date: Mon, 9 Jun 2025 20:33:17 +0200 Subject: [PATCH 2/3] chore(inspect): use simple list_machines --- pkgs/clan-cli/clan_cli/clan/inspect.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkgs/clan-cli/clan_cli/clan/inspect.py b/pkgs/clan-cli/clan_cli/clan/inspect.py index 89ffc13b3..830b06128 100644 --- a/pkgs/clan-cli/clan_cli/clan/inspect.py +++ b/pkgs/clan-cli/clan_cli/clan/inspect.py @@ -7,6 +7,7 @@ from clan_lib.cmd import run from clan_lib.dirs import machine_gcroot from clan_lib.errors import ClanError from clan_lib.flake import Flake +from clan_lib.machines.actions import list_machines from clan_lib.machines.machines import Machine from clan_lib.nix import ( nix_add_to_gcroots, @@ -16,7 +17,6 @@ from clan_lib.nix import ( nix_metadata, ) -from clan_cli.machines.list import list_full_machines from clan_cli.vms.inspect import VmConfig, inspect_vm @@ -58,7 +58,7 @@ def inspect_flake(flake_url: str | Path, machine_name: str) -> FlakeConfig: system = config["system"] # Check if the machine exists - machines: dict[str, Machine] = list_full_machines(Flake(str(flake_url))) + machines = list_machines(Flake(str(flake_url))) if machine_name not in machines: msg = f"Machine {machine_name} not found in {flake_url}. Available machines: {', '.join(machines)}" raise ClanError(msg) From 8360ee58b5fcf87998e0c217f9270dbfabc37c83 Mon Sep 17 00:00:00 2001 From: Johannes Kirschbauer Date: Mon, 9 Jun 2025 20:40:20 +0200 Subject: [PATCH 3/3] chore(flake): move 'inputs-from' into templates handling --- pkgs/clan-cli/clan_lib/flake/flake.py | 4 ---- pkgs/clan-cli/clan_lib/templates/__init__.py | 21 ++++++++++++++++---- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/pkgs/clan-cli/clan_lib/flake/flake.py b/pkgs/clan-cli/clan_lib/flake/flake.py index 20675ab6f..a2dd85cf8 100644 --- a/pkgs/clan-cli/clan_lib/flake/flake.py +++ b/pkgs/clan-cli/clan_lib/flake/flake.py @@ -568,7 +568,6 @@ class Flake: """ identifier: str - inputs_from: str | None = None hash: str | None = None store_path: str | None = None @@ -634,9 +633,6 @@ class Flake: self.identifier, ] - if self.inputs_from: - cmd += ["--inputs-from", self.inputs_from] - flake_prefetch = run(nix_command(cmd)) flake_metadata = json.loads(flake_prefetch.stdout) self.store_path = flake_metadata["storePath"] diff --git a/pkgs/clan-cli/clan_lib/templates/__init__.py b/pkgs/clan-cli/clan_lib/templates/__init__.py index ca4ef673c..6e880ec7a 100644 --- a/pkgs/clan-cli/clan_lib/templates/__init__.py +++ b/pkgs/clan-cli/clan_lib/templates/__init__.py @@ -7,6 +7,9 @@ from clan_lib.cmd import run from clan_lib.dirs import clan_templates from clan_lib.errors import ClanCmdError, ClanError from clan_lib.flake import Flake +from clan_lib.nix import ( + nix_command, +) log = logging.getLogger(__name__) @@ -202,16 +205,26 @@ def list_templates( return result -def realize_nix_path(clan_dir: Flake, nix_path: str) -> None: +def realize_nix_path(flake: Flake, nix_store_path: str) -> None: """ Downloads / realizes a nix path into the nix store """ - if Path(nix_path).exists(): + if Path(nix_store_path).exists(): return - flake = Flake(identifier=nix_path, inputs_from=clan_dir.identifier) - flake.invalidate_cache() + cmd = [ + "flake", + "prefetch", + "--inputs-from", + flake.identifier, + "--option", + "flake-registry", + "", + nix_store_path, + ] + + run(nix_command(cmd)) def get_template(