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 2f95d2edf2
commit 87e3e59ba0
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):
CLAN = "clan"
DISK = "disk"
MACHINE = "machine"
def clan_templates(template_type: TemplateType) -> Path:
template_path = (
module_root().parent.parent.parent / "templates" / template_type.value
)
def clan_templates(template_type: TemplateType | None = None) -> Path:
template_path = module_root().parent.parent.parent / "templates"
if template_type is not None:
template_path /= template_type.value
if template_path.exists():
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():
msg = f"BUG! clan core not found at {template_path}. This is an issue with packaging the cli"
raise ClanError(msg)
return template_path

View File

@@ -1,10 +1,10 @@
import logging
import os
from dataclasses import dataclass, field
from pathlib import Path
from typing import Any, Literal, NewType, TypedDict, cast
from clan_cli.cmd import run
from clan_cli.dirs import clan_templates
from clan_cli.errors import ClanCmdError, ClanError
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.
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:
clan_core_path = os.environ.get("CLAN_CORE_PATH")
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)
clan_dir = Flake(str(clan_templates()))
log.debug(f"Evaluating flake {clan_dir} for Clan attrsets")
@@ -231,11 +226,7 @@ def get_template(
"""
if not clan_dir:
clan_core_path = os.environ.get("CLAN_CORE_PATH")
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)
clan_dir = Flake(str(clan_templates()))
log.info(f"Get template in {clan_dir}")

View File

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

View File

@@ -1,43 +1,7 @@
{ self, inputs, ... }:
{
clan.templates = {
disko = {
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;
};
};
inherit (((import ./flake.nix).outputs { }).clan) templates;
};
flake = {

View File

@@ -2,7 +2,27 @@
outputs =
{ ... }:
{
templates = {
clan.templates = {
disko = {
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;
@@ -19,9 +39,6 @@
description = "Minimal flake-parts clan template";
path = ./clan/minimal-flake-parts;
};
machineTemplates = {
description = "Machine templates";
path = ./machine;
};
};
};