Files
clan-core/pkgs/clan-cli/clan_cli/clan_modules.py
2023-11-15 16:23:28 +01:00

37 lines
852 B
Python

import json
import subprocess
from pathlib import Path
from typing import Optional
from clan_cli.nix import nix_eval
def get_clan_module_names(
flake_dir: Path,
) -> tuple[list[str], Optional[str]]:
"""
Get the list of clan modules from the clan-core flake input
"""
proc = subprocess.run(
nix_eval(
[
"--impure",
"--show-trace",
"--expr",
f"""
let
flake = builtins.getFlake (toString {flake_dir});
in
builtins.attrNames flake.inputs.clan-core.clanModules
""",
],
),
capture_output=True,
text=True,
cwd=flake_dir,
)
if proc.returncode != 0:
return [], proc.stderr
module_names = json.loads(proc.stdout)
return module_names, None