From f7b39fc941919c6e4d8b61ca8a26667508bff3e0 Mon Sep 17 00:00:00 2001 From: Johannes Kirschbauer Date: Sat, 12 Jul 2025 14:11:43 +0200 Subject: [PATCH 1/4] cli/create: add interactive name method --- pkgs/clan-cli/clan_cli/clan/create.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/pkgs/clan-cli/clan_cli/clan/create.py b/pkgs/clan-cli/clan_cli/clan/create.py index 8d8cf2def..ea63c7cc0 100644 --- a/pkgs/clan-cli/clan_cli/clan/create.py +++ b/pkgs/clan-cli/clan_cli/clan/create.py @@ -4,6 +4,7 @@ import logging from pathlib import Path from clan_lib.clan.create import CreateOptions, create_clan +from clan_lib.errors import ClanError log = logging.getLogger(__name__) @@ -28,8 +29,8 @@ def register_create_parser(parser: argparse.ArgumentParser) -> None: parser.add_argument( "path", type=Path, + nargs="?", help="Path where to write the clan template to", - default=Path(), ) parser.add_argument( @@ -40,6 +41,15 @@ def register_create_parser(parser: argparse.ArgumentParser) -> None: ) def create_flake_command(args: argparse.Namespace) -> None: + # Ask for a path interactively if none provided + if args.path is None: + user_input = input("Enter a name for the new clan: ").strip() + if not user_input: + msg = "Error: name is required." + raise ClanError(msg) + + args.path = Path(user_input) + create_clan( CreateOptions( dest=args.path, From 81419cfb71d16fd28cc306172348ce747d60404b Mon Sep 17 00:00:00 2001 From: Johannes Kirschbauer Date: Sat, 12 Jul 2025 14:49:27 +0200 Subject: [PATCH 2/4] templates: add example how to add inventory.machines --- templates/clan/default/clan.nix | 5 +++++ templates/clan/flake-parts/clan.nix | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/templates/clan/default/clan.nix b/templates/clan/default/clan.nix index f18dd7a8a..9ac930a7e 100644 --- a/templates/clan/default/clan.nix +++ b/templates/clan/default/clan.nix @@ -2,6 +2,11 @@ # Ensure this is unique among all clans you want to use. meta.name = "__CHANGE_ME__"; + inventory.machines = { + # Define machines here. + # jon = { }; + }; + # Docs: See https://docs.clan.lol/reference/clanServices inventory.instances = { diff --git a/templates/clan/flake-parts/clan.nix b/templates/clan/flake-parts/clan.nix index f18dd7a8a..9ac930a7e 100644 --- a/templates/clan/flake-parts/clan.nix +++ b/templates/clan/flake-parts/clan.nix @@ -2,6 +2,11 @@ # Ensure this is unique among all clans you want to use. meta.name = "__CHANGE_ME__"; + inventory.machines = { + # Define machines here. + # jon = { }; + }; + # Docs: See https://docs.clan.lol/reference/clanServices inventory.instances = { From c1bad93d36a52875666debb14c913449e374c398 Mon Sep 17 00:00:00 2001 From: Johannes Kirschbauer Date: Sat, 12 Jul 2025 14:55:59 +0200 Subject: [PATCH 3/4] templates/copy: fix use shutil to copy hidden dot files --- pkgs/clan-cli/clan_lib/templates/filesystem.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pkgs/clan-cli/clan_lib/templates/filesystem.py b/pkgs/clan-cli/clan_lib/templates/filesystem.py index aa2779f21..1b3187cbc 100644 --- a/pkgs/clan-cli/clan_lib/templates/filesystem.py +++ b/pkgs/clan-cli/clan_lib/templates/filesystem.py @@ -1,3 +1,4 @@ +import shutil from pathlib import Path from clan_lib.flake import Flake @@ -35,7 +36,7 @@ def copy_from_nixstore(src: Path, dest: Path) -> None: Uses `cp -r` to recursively copy the directory. Ensures the destination directory is writable by the user. """ - run(["cp", "-r", str(src / "."), str(dest)]) # Copy contents of src to dest + shutil.copytree(src, dest, dirs_exist_ok=True, symlinks=True) run( ["chmod", "-R", "u+w", str(dest)] ) # Ensure the destination is writable by the user From 135df0dbe6a8b41cf09f16cd759ba60e8e6b0f5b Mon Sep 17 00:00:00 2001 From: Johannes Kirschbauer Date: Sat, 12 Jul 2025 15:03:37 +0200 Subject: [PATCH 4/4] clan/create: rename path to name argument --- pkgs/clan-cli/clan_cli/clan/create.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/pkgs/clan-cli/clan_cli/clan/create.py b/pkgs/clan-cli/clan_cli/clan/create.py index ea63c7cc0..c4beeccd5 100644 --- a/pkgs/clan-cli/clan_cli/clan/create.py +++ b/pkgs/clan-cli/clan_cli/clan/create.py @@ -27,10 +27,10 @@ def register_create_parser(parser: argparse.ArgumentParser) -> None: ) parser.add_argument( - "path", - type=Path, + "name", + type=str, nargs="?", - help="Path where to write the clan template to", + help="Name of the clan to create. If not provided, will prompt for a name.", ) parser.add_argument( @@ -42,17 +42,17 @@ def register_create_parser(parser: argparse.ArgumentParser) -> None: def create_flake_command(args: argparse.Namespace) -> None: # Ask for a path interactively if none provided - if args.path is None: + if args.name is None: user_input = input("Enter a name for the new clan: ").strip() if not user_input: msg = "Error: name is required." raise ClanError(msg) - args.path = Path(user_input) + args.name = Path(user_input) create_clan( CreateOptions( - dest=args.path, + dest=Path(args.name), template=args.template, setup_git=not args.no_git, src_flake=args.flake,