diff --git a/pkgs/clan-cli/clan_cli/__init__.py b/pkgs/clan-cli/clan_cli/__init__.py index 7e1b92800..b6c60ffd9 100644 --- a/pkgs/clan-cli/clan_cli/__init__.py +++ b/pkgs/clan-cli/clan_cli/__init__.py @@ -19,7 +19,7 @@ from . import ( vms, ) from .custom_logger import setup_logging -from .dirs import get_clan_flake_toplevel +from .dirs import get_clan_flake_toplevel_or_env from .errors import ClanCmdError, ClanError from .profiler import profile from .ssh import cli as ssh_cli @@ -77,8 +77,8 @@ def create_parser(prog: str | None = None) -> argparse.ArgumentParser: parser.add_argument( "--flake", - help="path to the flake where the clan resides in, can be a remote flake or local", - default=get_clan_flake_toplevel(), + help="path to the flake where the clan resides in, can be a remote flake or local, can be set through the [CLAN_DIR] environment variable", + default=get_clan_flake_toplevel_or_env(), type=flake_path, ) diff --git a/pkgs/clan-cli/clan_cli/dirs.py b/pkgs/clan-cli/clan_cli/dirs.py index abcf83255..9b687aa43 100644 --- a/pkgs/clan-cli/clan_cli/dirs.py +++ b/pkgs/clan-cli/clan_cli/dirs.py @@ -7,6 +7,12 @@ from pathlib import Path log = logging.getLogger(__name__) +def get_clan_flake_toplevel_or_env() -> Path | None: + if clan_dir := os.environ.get("CLAN_DIR"): + return Path(clan_dir) + return get_clan_flake_toplevel() + + def get_clan_flake_toplevel() -> Path | None: return find_toplevel([".clan-flake", ".git", ".hg", ".svn", "flake.nix"])