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.api import API
|
||||||
from clan_cli.cmd import CmdOut, run
|
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.errors import ClanError
|
||||||
from clan_cli.inventory import Inventory, init_inventory
|
from clan_cli.inventory import Inventory, init_inventory
|
||||||
from clan_cli.nix import nix_command, nix_shell
|
from clan_cli.nix import nix_command, nix_shell
|
||||||
@@ -38,7 +38,7 @@ def git_command(directory: Path, *args: str) -> list[str]:
|
|||||||
@API.register
|
@API.register
|
||||||
def create_clan(options: CreateOptions) -> CreateClanResponse:
|
def create_clan(options: CreateOptions) -> CreateClanResponse:
|
||||||
directory = Path(options.directory).resolve()
|
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():
|
if not directory.exists():
|
||||||
directory.mkdir()
|
directory.mkdir()
|
||||||
else:
|
else:
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import logging
|
|||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
import urllib
|
import urllib
|
||||||
|
from enum import Enum
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
from clan_cli.clan_uri import FlakeId
|
from clan_cli.clan_uri import FlakeId
|
||||||
@@ -45,11 +46,17 @@ def find_toplevel(top_level_files: list[str]) -> Path | None:
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
def clan_templates() -> Path:
|
class TemplateType(Enum):
|
||||||
template_path = module_root().parent.parent.parent / "templates"
|
CLAN = "clan"
|
||||||
|
|
||||||
|
|
||||||
|
def clan_templates(template_type: TemplateType) -> Path:
|
||||||
|
template_path = (
|
||||||
|
module_root().parent.parent.parent / "templates" / template_type.value
|
||||||
|
)
|
||||||
if template_path.exists():
|
if template_path.exists():
|
||||||
return template_path
|
return template_path
|
||||||
template_path = module_root() / "templates"
|
template_path = module_root() / "templates" / 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)
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ from clan_cli.clan.create import git_command
|
|||||||
from clan_cli.clan_uri import FlakeId
|
from clan_cli.clan_uri import FlakeId
|
||||||
from clan_cli.cmd import Log, run
|
from clan_cli.cmd import Log, run
|
||||||
from clan_cli.completions import add_dynamic_completer, complete_tags
|
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.errors import ClanError
|
||||||
from clan_cli.inventory import Machine as InventoryMachine
|
from clan_cli.inventory import Machine as InventoryMachine
|
||||||
from clan_cli.inventory import (
|
from clan_cli.inventory import (
|
||||||
@@ -56,7 +56,7 @@ def create_machine(opts: CreateOptions) -> None:
|
|||||||
raise ClanError(msg, description=description)
|
raise ClanError(msg, description=description)
|
||||||
|
|
||||||
if not opts.template_src:
|
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:
|
if not opts.template_name:
|
||||||
opts.template_name = "new-machine"
|
opts.template_name = "new-machine"
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ from pathlib import Path
|
|||||||
from typing import Any, NamedTuple
|
from typing import Any, NamedTuple
|
||||||
|
|
||||||
import pytest
|
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 clan_cli.locked_open import locked_open
|
||||||
from fixture_error import FixtureError
|
from fixture_error import FixtureError
|
||||||
from root import CLAN_CORE
|
from root import CLAN_CORE
|
||||||
@@ -213,7 +213,7 @@ def minimal_flake_template() -> Iterator[ClanFlake]:
|
|||||||
mp.setenv("HOME", home)
|
mp.setenv("HOME", home)
|
||||||
flake = ClanFlake(
|
flake = ClanFlake(
|
||||||
temporary_home=Path(home),
|
temporary_home=Path(home),
|
||||||
flake_template=CLAN_CORE / "templates" / "minimal",
|
flake_template=clan_templates(TemplateType.CLAN) / "minimal",
|
||||||
)
|
)
|
||||||
flake.init_from_template()
|
flake.init_from_template()
|
||||||
yield flake
|
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 = {
|
templates = {
|
||||||
default = {
|
default = {
|
||||||
description = "Initialize a new clan flake";
|
description = "Initialize a new clan flake";
|
||||||
path = ./new-clan;
|
path = ./clan/new-clan;
|
||||||
};
|
};
|
||||||
minimal = {
|
minimal = {
|
||||||
description = "for clans managed via (G)UI";
|
description = "for clans managed via (G)UI";
|
||||||
path = ./minimal;
|
path = ./clan/minimal;
|
||||||
};
|
};
|
||||||
flake-parts = {
|
flake-parts = {
|
||||||
description = "Flake-parts";
|
description = "Flake-parts";
|
||||||
path = ./flake-parts;
|
path = ./clan/flake-parts;
|
||||||
};
|
};
|
||||||
minimal-flake-parts = {
|
minimal-flake-parts = {
|
||||||
description = "Minimal flake-parts clan template";
|
description = "Minimal flake-parts clan template";
|
||||||
path = ./minimal-flake-parts;
|
path = ./clan/minimal-flake-parts;
|
||||||
};
|
};
|
||||||
machineTemplates = {
|
machineTemplates = {
|
||||||
description = "Machine templates";
|
description = "Machine templates";
|
||||||
path = ./machineTemplates;
|
path = ./clan/machineTemplates;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user