2023-07-26 12:34:39 +00:00
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
from pathlib import Path
|
|
|
|
|
2023-07-28 10:12:37 +00:00
|
|
|
from .errors import ClanError
|
|
|
|
|
2023-07-26 12:34:39 +00:00
|
|
|
|
|
|
|
def get_clan_flake_toplevel() -> Path:
|
|
|
|
"""Returns the path to the toplevel of the clan flake"""
|
2023-07-28 10:12:37 +00:00
|
|
|
for project_file in [".clan-flake", ".git", ".hg", ".svn", "flake.nix"]:
|
|
|
|
initial_path = Path(os.getcwd())
|
|
|
|
path = Path(initial_path)
|
2023-07-28 10:35:41 +00:00
|
|
|
while path.parent != path:
|
2023-07-26 12:34:39 +00:00
|
|
|
if (path / project_file).exists():
|
|
|
|
return path
|
2023-07-28 10:12:37 +00:00
|
|
|
path = path.parent
|
|
|
|
raise ClanError("Could not find clan flake toplevel directory")
|
2023-07-26 12:34:39 +00:00
|
|
|
|
|
|
|
|
2023-07-29 12:21:28 +00:00
|
|
|
def user_config_dir() -> Path:
|
2023-07-26 12:34:39 +00:00
|
|
|
if sys.platform == "win32":
|
2023-07-29 12:21:28 +00:00
|
|
|
return Path(os.getenv("APPDATA", os.path.expanduser("~\\AppData\\Roaming\\")))
|
2023-07-26 12:34:39 +00:00
|
|
|
elif sys.platform == "darwin":
|
|
|
|
return Path(os.path.expanduser("~/Library/Application Support/"))
|
|
|
|
else:
|
2023-07-29 12:21:28 +00:00
|
|
|
return Path(os.getenv("XDG_CONFIG_HOME", os.path.expanduser("~/.config")))
|
2023-08-26 09:23:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
def module_root() -> Path:
|
|
|
|
return Path(__file__).parent
|
|
|
|
|
|
|
|
|
2023-09-06 15:29:49 +00:00
|
|
|
def nixpkgs_flake() -> Path:
|
|
|
|
return (module_root() / "nixpkgs").resolve()
|
2023-08-26 09:23:15 +00:00
|
|
|
|
|
|
|
|
2023-09-06 15:29:49 +00:00
|
|
|
def nixpkgs_source() -> Path:
|
|
|
|
return (module_root() / "nixpkgs" / "path").resolve()
|
2023-08-26 09:23:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
def unfree_nixpkgs() -> Path:
|
|
|
|
return module_root() / "nixpkgs" / "unfree"
|