cli: default template url should come from the package itself rather than our gitea
This allow easier testing and also forks.
This commit is contained in:
@@ -9,12 +9,10 @@ from clan_cli.arg_actions import AppendOptionAction
|
|||||||
from clan_cli.inventory import Meta, load_inventory, save_inventory
|
from clan_cli.inventory import Meta, load_inventory, save_inventory
|
||||||
|
|
||||||
from ..cmd import CmdOut, run
|
from ..cmd import CmdOut, run
|
||||||
|
from ..dirs import clan_templates
|
||||||
from ..errors import ClanError
|
from ..errors import ClanError
|
||||||
from ..nix import nix_command, nix_shell
|
from ..nix import nix_command, nix_shell
|
||||||
|
|
||||||
default_template_url: str = "git+https://git.clan.lol/clan/clan-core"
|
|
||||||
minimal_template_url: str = "git+https://git.clan.lol/clan/clan-core#templates.minimal"
|
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class CreateClanResponse:
|
class CreateClanResponse:
|
||||||
@@ -33,7 +31,7 @@ class CreateOptions:
|
|||||||
# Metadata can be shown with `clan show`
|
# Metadata can be shown with `clan show`
|
||||||
meta: Meta | None = None
|
meta: Meta | None = None
|
||||||
# URL to the template to use. Defaults to the "minimal" template
|
# URL to the template to use. Defaults to the "minimal" template
|
||||||
template_url: str = minimal_template_url
|
template: str = "minimal"
|
||||||
|
|
||||||
|
|
||||||
def git_command(directory: Path, *args: str) -> list[str]:
|
def git_command(directory: Path, *args: str) -> list[str]:
|
||||||
@@ -43,7 +41,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 = options.template_url
|
template_url = f"{clan_templates()}#{options.template}"
|
||||||
if not directory.exists():
|
if not directory.exists():
|
||||||
directory.mkdir()
|
directory.mkdir()
|
||||||
else:
|
else:
|
||||||
@@ -112,10 +110,11 @@ def create_clan(options: CreateOptions) -> CreateClanResponse:
|
|||||||
|
|
||||||
def register_create_parser(parser: argparse.ArgumentParser) -> None:
|
def register_create_parser(parser: argparse.ArgumentParser) -> None:
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"--url",
|
"--template",
|
||||||
type=str,
|
type=str,
|
||||||
help="url to the clan template",
|
choices=["default", "minimal"],
|
||||||
default=default_template_url,
|
help="Clan template name",
|
||||||
|
default="default",
|
||||||
)
|
)
|
||||||
|
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
@@ -135,7 +134,7 @@ def register_create_parser(parser: argparse.ArgumentParser) -> None:
|
|||||||
create_clan(
|
create_clan(
|
||||||
CreateOptions(
|
CreateOptions(
|
||||||
directory=args.path,
|
directory=args.path,
|
||||||
template_url=args.url,
|
template=args.template,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -4,6 +4,8 @@ import sys
|
|||||||
import urllib
|
import urllib
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
|
from .errors import ClanError
|
||||||
|
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
@@ -41,6 +43,18 @@ def find_toplevel(top_level_files: list[str]) -> Path | None:
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
def clan_templates() -> Path:
|
||||||
|
template_path = module_root().parent.parent / "templates"
|
||||||
|
if template_path.exists():
|
||||||
|
return template_path
|
||||||
|
else:
|
||||||
|
template_path = module_root() / "templates"
|
||||||
|
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
|
||||||
|
|
||||||
|
|
||||||
def user_config_dir() -> Path:
|
def user_config_dir() -> Path:
|
||||||
if sys.platform == "win32":
|
if sys.platform == "win32":
|
||||||
return Path(os.getenv("APPDATA", os.path.expanduser("~\\AppData\\Roaming\\")))
|
return Path(os.getenv("APPDATA", os.path.expanduser("~\\AppData\\Roaming\\")))
|
||||||
|
|||||||
@@ -63,6 +63,7 @@ let
|
|||||||
rm $out/clan_cli/config/jsonschema
|
rm $out/clan_cli/config/jsonschema
|
||||||
ln -sf ${nixpkgs'} $out/clan_cli/nixpkgs
|
ln -sf ${nixpkgs'} $out/clan_cli/nixpkgs
|
||||||
cp -r ${../../lib/jsonschema} $out/clan_cli/config/jsonschema
|
cp -r ${../../lib/jsonschema} $out/clan_cli/config/jsonschema
|
||||||
|
cp -r ${../../templates} $out/clan_cli/templates
|
||||||
|
|
||||||
${classgen}/bin/classgen ${inventory-schema}/schema.json $out/clan_cli/inventory/classes.py
|
${classgen}/bin/classgen ${inventory-schema}/schema.json $out/clan_cli/inventory/classes.py
|
||||||
'';
|
'';
|
||||||
|
|||||||
@@ -18,7 +18,14 @@ Repository = "https://git.clan.lol/clan/clan-core"
|
|||||||
exclude = ["clan_cli.nixpkgs*", "result"]
|
exclude = ["clan_cli.nixpkgs*", "result"]
|
||||||
|
|
||||||
[tool.setuptools.package-data]
|
[tool.setuptools.package-data]
|
||||||
clan_cli = ["py.typed", "config/jsonschema/*", "webui/assets/**/*", "vms/mimetypes/**/*", "**/allowed-programs.json"]
|
clan_cli = [
|
||||||
|
"**/allowed-programs.json",
|
||||||
|
"config/jsonschema/*",
|
||||||
|
"py.typed",
|
||||||
|
"templates/**/*",
|
||||||
|
"vms/mimetypes/**/*",
|
||||||
|
"webui/assets/**/*",
|
||||||
|
]
|
||||||
|
|
||||||
[tool.pytest.ini_options]
|
[tool.pytest.ini_options]
|
||||||
testpaths = "tests"
|
testpaths = "tests"
|
||||||
|
|||||||
@@ -1,35 +1,26 @@
|
|||||||
{ self, inputs, ... }:
|
{ self, inputs, ... }:
|
||||||
{
|
{
|
||||||
flake.templates = {
|
flake = (import ./flake.nix).outputs {} // {
|
||||||
new-clan = {
|
checks.x86_64-linux.template-minimal =
|
||||||
description = "Initialize a new clan flake";
|
let
|
||||||
path = ./new-clan;
|
path = self.templates.minimal.path;
|
||||||
};
|
initialized = inputs.nixpkgs.legacyPackages.x86_64-linux.runCommand "minimal-clan-flake" { } ''
|
||||||
default = self.templates.new-clan;
|
mkdir $out
|
||||||
minimal = {
|
cp -r ${path}/* $out
|
||||||
description = "for clans managed via (G)UI";
|
mkdir -p $out/machines/foo
|
||||||
path = ./minimal;
|
echo '{ "nixpkgs": { "hostPlatform": "x86_64-linux" } }' > $out/machines/foo/settings.json
|
||||||
};
|
'';
|
||||||
};
|
evaled = (import "${initialized}/flake.nix").outputs {
|
||||||
flake.checks.x86_64-linux.template-minimal =
|
self = evaled // {
|
||||||
let
|
outPath = initialized;
|
||||||
path = self.templates.minimal.path;
|
};
|
||||||
initialized = inputs.nixpkgs.legacyPackages.x86_64-linux.runCommand "minimal-clan-flake" { } ''
|
clan-core = self;
|
||||||
mkdir $out
|
|
||||||
cp -r ${path}/* $out
|
|
||||||
mkdir -p $out/machines/foo
|
|
||||||
echo '{ "nixpkgs": { "hostPlatform": "x86_64-linux" } }' > $out/machines/foo/settings.json
|
|
||||||
'';
|
|
||||||
evaled = (import "${initialized}/flake.nix").outputs {
|
|
||||||
self = evaled // {
|
|
||||||
outPath = initialized;
|
|
||||||
};
|
};
|
||||||
clan-core = self;
|
in
|
||||||
|
{
|
||||||
|
type = "derivation";
|
||||||
|
name = "minimal-clan-flake-check";
|
||||||
|
inherit (evaled.nixosConfigurations.foo.config.system.build.vm) drvPath outPath;
|
||||||
};
|
};
|
||||||
in
|
};
|
||||||
{
|
|
||||||
type = "derivation";
|
|
||||||
name = "minimal-clan-flake-check";
|
|
||||||
inherit (evaled.nixosConfigurations.foo.config.system.build.vm) drvPath outPath;
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|||||||
16
templates/flake.nix
Normal file
16
templates/flake.nix
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
{
|
||||||
|
outputs =
|
||||||
|
{ ... }:
|
||||||
|
{
|
||||||
|
templates = {
|
||||||
|
default = {
|
||||||
|
description = "Initialize a new clan flake";
|
||||||
|
path = ./new-clan;
|
||||||
|
};
|
||||||
|
minimal = {
|
||||||
|
description = "for clans managed via (G)UI";
|
||||||
|
path = ./minimal;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user