Merge pull request 'Templates: move all clan templates into subfolder 'clan'' (#2514) from hsjobeki/clan-core:hsjobeki-main into main
Reviewed-on: https://git.clan.lol/clan/clan-core/pulls/2514
This commit is contained in:
@@ -6,7 +6,7 @@ from pathlib import Path
|
||||
|
||||
from clan_cli.api import API
|
||||
from clan_cli.cmd import CmdOut, run
|
||||
from clan_cli.dirs import clan_templates
|
||||
from clan_cli.dirs import TemplateType, clan_templates
|
||||
from clan_cli.errors import ClanError
|
||||
from clan_cli.inventory import Inventory, init_inventory
|
||||
from clan_cli.nix import nix_command, nix_shell
|
||||
@@ -38,7 +38,7 @@ def git_command(directory: Path, *args: str) -> list[str]:
|
||||
@API.register
|
||||
def create_clan(options: CreateOptions) -> CreateClanResponse:
|
||||
directory = Path(options.directory).resolve()
|
||||
template_url = f"{clan_templates()}#{options.template}"
|
||||
template_url = f"{clan_templates(TemplateType.CLAN)}#{options.template}"
|
||||
if not directory.exists():
|
||||
directory.mkdir()
|
||||
else:
|
||||
|
||||
@@ -2,6 +2,7 @@ import logging
|
||||
import os
|
||||
import sys
|
||||
import urllib
|
||||
from enum import Enum
|
||||
from pathlib import Path
|
||||
|
||||
from clan_cli.clan_uri import FlakeId
|
||||
@@ -45,11 +46,17 @@ def find_toplevel(top_level_files: list[str]) -> Path | None:
|
||||
return None
|
||||
|
||||
|
||||
def clan_templates() -> Path:
|
||||
template_path = module_root().parent.parent.parent / "templates"
|
||||
class TemplateType(Enum):
|
||||
CLAN = "clan"
|
||||
|
||||
|
||||
def clan_templates(template_type: TemplateType) -> Path:
|
||||
template_path = (
|
||||
module_root().parent.parent.parent / "templates" / template_type.value
|
||||
)
|
||||
if template_path.exists():
|
||||
return template_path
|
||||
template_path = module_root() / "templates"
|
||||
template_path = module_root() / "templates" / 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)
|
||||
|
||||
@@ -11,7 +11,7 @@ from clan_cli.clan.create import git_command
|
||||
from clan_cli.clan_uri import FlakeId
|
||||
from clan_cli.cmd import Log, run
|
||||
from clan_cli.completions import add_dynamic_completer, complete_tags
|
||||
from clan_cli.dirs import clan_templates, get_clan_flake_toplevel_or_env
|
||||
from clan_cli.dirs import TemplateType, clan_templates, get_clan_flake_toplevel_or_env
|
||||
from clan_cli.errors import ClanError
|
||||
from clan_cli.inventory import Machine as InventoryMachine
|
||||
from clan_cli.inventory import (
|
||||
@@ -56,7 +56,7 @@ def create_machine(opts: CreateOptions) -> None:
|
||||
raise ClanError(msg, description=description)
|
||||
|
||||
if not opts.template_src:
|
||||
opts.template_src = FlakeId(str(clan_templates()))
|
||||
opts.template_src = FlakeId(str(clan_templates(TemplateType.CLAN)))
|
||||
|
||||
if not opts.template_name:
|
||||
opts.template_name = "new-machine"
|
||||
|
||||
@@ -10,7 +10,7 @@ from pathlib import Path
|
||||
from typing import Any, NamedTuple
|
||||
|
||||
import pytest
|
||||
from clan_cli.dirs import nixpkgs_source
|
||||
from clan_cli.dirs import TemplateType, clan_templates, nixpkgs_source
|
||||
from clan_cli.locked_open import locked_open
|
||||
from fixture_error import FixtureError
|
||||
from root import CLAN_CORE
|
||||
@@ -213,7 +213,7 @@ def minimal_flake_template() -> Iterator[ClanFlake]:
|
||||
mp.setenv("HOME", home)
|
||||
flake = ClanFlake(
|
||||
temporary_home=Path(home),
|
||||
flake_template=CLAN_CORE / "templates" / "minimal",
|
||||
flake_template=clan_templates(TemplateType.CLAN) / "minimal",
|
||||
)
|
||||
flake.init_from_template()
|
||||
yield flake
|
||||
|
||||
39
templates/disk/single-disk.nix
Normal file
39
templates/disk/single-disk.nix
Normal file
@@ -0,0 +1,39 @@
|
||||
{
|
||||
disko.devices = {
|
||||
disk = {
|
||||
main = {
|
||||
device = "{{mainDisk}}";
|
||||
type = "disk";
|
||||
content = {
|
||||
type = "gpt";
|
||||
partitions = {
|
||||
ESP = {
|
||||
type = "EF00";
|
||||
size = "500M";
|
||||
content = {
|
||||
type = "filesystem";
|
||||
format = "vfat";
|
||||
mountpoint = "/boot";
|
||||
mountOptions = [ "umask=0077" ];
|
||||
};
|
||||
};
|
||||
root = {
|
||||
size = "100%";
|
||||
content = {
|
||||
type = "filesystem";
|
||||
format = "ext4";
|
||||
mountpoint = "/";
|
||||
};
|
||||
};
|
||||
swap = {
|
||||
size = "{{swapSize}}";
|
||||
content = {
|
||||
type = "swap";
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
||||
@@ -5,23 +5,23 @@
|
||||
templates = {
|
||||
default = {
|
||||
description = "Initialize a new clan flake";
|
||||
path = ./new-clan;
|
||||
path = ./clan/new-clan;
|
||||
};
|
||||
minimal = {
|
||||
description = "for clans managed via (G)UI";
|
||||
path = ./minimal;
|
||||
path = ./clan/minimal;
|
||||
};
|
||||
flake-parts = {
|
||||
description = "Flake-parts";
|
||||
path = ./flake-parts;
|
||||
path = ./clan/flake-parts;
|
||||
};
|
||||
minimal-flake-parts = {
|
||||
description = "Minimal flake-parts clan template";
|
||||
path = ./minimal-flake-parts;
|
||||
path = ./clan/minimal-flake-parts;
|
||||
};
|
||||
machineTemplates = {
|
||||
description = "Machine templates";
|
||||
path = ./machineTemplates;
|
||||
path = ./clan/machineTemplates;
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user