cli: don't depend on the entire clan-core

This commit is contained in:
Michael Hoang
2025-04-25 11:11:51 +10:00
parent c347badd7f
commit c73652a401
5 changed files with 54 additions and 78 deletions

View File

@@ -47,18 +47,27 @@ def find_toplevel(top_level_files: list[str]) -> Path | None:
class TemplateType(Enum): class TemplateType(Enum):
CLAN = "clan" CLAN = "clan"
DISK = "disk" DISK = "disk"
MACHINE = "machine"
def clan_templates(template_type: TemplateType) -> Path: def clan_templates(template_type: TemplateType | None = None) -> Path:
template_path = ( template_path = module_root().parent.parent.parent / "templates"
module_root().parent.parent.parent / "templates" / template_type.value
) if template_type is not None:
template_path /= template_type.value
if template_path.exists(): if template_path.exists():
return template_path return template_path
template_path = module_root() / "templates" / template_type.value
template_path = module_root() / "templates"
if template_type is not None:
template_path /= template_type.value
if not template_path.exists(): if not template_path.exists():
msg = f"BUG! clan core not found at {template_path}. This is an issue with packaging the cli" msg = f"BUG! clan core not found at {template_path}. This is an issue with packaging the cli"
raise ClanError(msg) raise ClanError(msg)
return template_path return template_path

View File

@@ -1,10 +1,10 @@
import logging import logging
import os
from dataclasses import dataclass, field from dataclasses import dataclass, field
from pathlib import Path from pathlib import Path
from typing import Any, Literal, NewType, TypedDict, cast from typing import Any, Literal, NewType, TypedDict, cast
from clan_cli.cmd import run from clan_cli.cmd import run
from clan_cli.dirs import clan_templates
from clan_cli.errors import ClanCmdError, ClanError from clan_cli.errors import ClanCmdError, ClanError
from clan_cli.flake import Flake from clan_cli.flake import Flake
@@ -83,13 +83,8 @@ def get_clan_nix_attrset(clan_dir: Flake | None = None) -> ClanExports:
Get the clan nix attrset from a flake, with fallback structure applied. Get the clan nix attrset from a flake, with fallback structure applied.
Path inside the attrsets have NOT YET been realized in the nix store. Path inside the attrsets have NOT YET been realized in the nix store.
""" """
# Check if the clan directory is provided, otherwise use the environment variable
if not clan_dir: if not clan_dir:
clan_core_path = os.environ.get("CLAN_CORE_PATH") clan_dir = Flake(str(clan_templates()))
if not clan_core_path:
msg = "Environment var CLAN_CORE_PATH is not set, this shouldn't happen"
raise ClanError(msg)
clan_dir = Flake(clan_core_path)
log.debug(f"Evaluating flake {clan_dir} for Clan attrsets") log.debug(f"Evaluating flake {clan_dir} for Clan attrsets")
@@ -231,11 +226,7 @@ def get_template(
""" """
if not clan_dir: if not clan_dir:
clan_core_path = os.environ.get("CLAN_CORE_PATH") clan_dir = Flake(str(clan_templates()))
if not clan_core_path:
msg = "Environment var CLAN_CORE_PATH is not set, this shouldn't happen"
raise ClanError(msg)
clan_dir = Flake(clan_core_path)
log.info(f"Get template in {clan_dir}") log.info(f"Get template in {clan_dir}")

View File

@@ -115,11 +115,6 @@ pythonRuntime.pkgs.buildPythonApplication {
":" ":"
(lib.makeBinPath (lib.attrValues bundledRuntimeDependenciesMap)) (lib.makeBinPath (lib.attrValues bundledRuntimeDependenciesMap))
# We need this for templates to work
"--set"
"CLAN_CORE_PATH"
clan-core-path
"--set" "--set"
"CLAN_PROVIDED_PACKAGES" "CLAN_PROVIDED_PACKAGES"
(lib.concatStringsSep ":" (lib.attrNames bundledRuntimeDependenciesMap)) (lib.concatStringsSep ":" (lib.attrNames bundledRuntimeDependenciesMap))

View File

@@ -1,43 +1,7 @@
{ self, inputs, ... }: { self, inputs, ... }:
{ {
clan.templates = { clan = {
disko = { inherit (((import ./flake.nix).outputs { }).clan) templates;
single-disk = {
description = "A simple ext4 disk with a single partition";
path = ./disk/single-disk;
};
};
machine = {
flash-installer = {
description = "Initialize a new flash-installer machine";
path = ./machine/flash-installer;
};
new-machine = {
description = "Initialize a new machine";
path = ./machine/new-machine;
};
};
clan = {
default = {
description = "Initialize a new clan flake";
path = ./clan/new-clan;
};
minimal = {
description = "for clans managed via (G)UI";
path = ./clan/minimal;
};
flake-parts = {
description = "Flake-parts";
path = ./clan/flake-parts;
};
minimal-flake-parts = {
description = "Minimal flake-parts clan template";
path = ./clan/minimal-flake-parts;
};
};
}; };
flake = { flake = {

View File

@@ -2,26 +2,43 @@
outputs = outputs =
{ ... }: { ... }:
{ {
templates = { clan.templates = {
default = { disko = {
description = "Initialize a new clan flake"; single-disk = {
path = ./clan/new-clan; description = "A simple ext4 disk with a single partition";
path = ./disk/single-disk;
};
}; };
minimal = {
description = "for clans managed via (G)UI"; machine = {
path = ./clan/minimal; flash-installer = {
description = "Initialize a new flash-installer machine";
path = ./machine/flash-installer;
};
new-machine = {
description = "Initialize a new machine";
path = ./machine/new-machine;
};
}; };
flake-parts = {
description = "Flake-parts"; clan = {
path = ./clan/flake-parts; default = {
}; description = "Initialize a new clan flake";
minimal-flake-parts = { path = ./clan/new-clan;
description = "Minimal flake-parts clan template"; };
path = ./clan/minimal-flake-parts; minimal = {
}; description = "for clans managed via (G)UI";
machineTemplates = { path = ./clan/minimal;
description = "Machine templates"; };
path = ./machine; flake-parts = {
description = "Flake-parts";
path = ./clan/flake-parts;
};
minimal-flake-parts = {
description = "Minimal flake-parts clan template";
path = ./clan/minimal-flake-parts;
};
}; };
}; };
}; };