diff --git a/pkgs/clan-cli/clan_cli/__init__.py b/pkgs/clan-cli/clan_cli/__init__.py index c27b90c7..aafef986 100644 --- a/pkgs/clan-cli/clan_cli/__init__.py +++ b/pkgs/clan-cli/clan_cli/__init__.py @@ -6,7 +6,18 @@ from pathlib import Path from types import ModuleType from typing import Any -from . import backups, config, facts, flakes, flash, history, machines, secrets, vms +from . import ( + backups, + config, + facts, + flakes, + flash, + flatpak, + history, + machines, + secrets, + vms, +) from .custom_logger import setup_logging from .dirs import get_clan_flake_toplevel from .errors import ClanCmdError, ClanError @@ -129,6 +140,8 @@ def main() -> None: if args.debug: setup_logging(logging.DEBUG, root_log_name=__name__.split(".")[0]) log.debug("Debug log activated") + if flatpak.is_flatpak(): + log.debug("Running inside a flatpak sandbox") else: setup_logging(logging.INFO, root_log_name=__name__.split(".")[0]) diff --git a/pkgs/clan-cli/clan_cli/flatpak.py b/pkgs/clan-cli/clan_cli/flatpak.py new file mode 100644 index 00000000..d9a563fa --- /dev/null +++ b/pkgs/clan-cli/clan_cli/flatpak.py @@ -0,0 +1,16 @@ +import os + + +def is_flatpak() -> bool: + """Check if the current process is running inside a flatpak sandbox.""" + # FLATPAK_ID environment variable check + flatpak_env = "FLATPAK_ID" in os.environ + + flatpak_file = False + try: + with open("/.flatpak-info"): + flatpak_file = True + except FileNotFoundError: + pass + + return flatpak_env and flatpak_file