clan: improve machine completions
In recent nix versions the `nix flake show` command busts the eval cache, which made the function that used to be faster, slower. On benchmarks the completion was around 180-200ms.
This commit is contained in:
parent
5024973896
commit
49e67ac46c
|
@ -44,23 +44,23 @@ def complete_machines(
|
||||||
|
|
||||||
def run_cmd() -> None:
|
def run_cmd() -> None:
|
||||||
try:
|
try:
|
||||||
# In my tests this was consistently faster than:
|
|
||||||
# nix eval .#nixosConfigurations --apply builtins.attrNames
|
|
||||||
cmd = ["nix", "flake", "show", "--system", "no-eval", "--json"]
|
|
||||||
if (clan_dir_result := clan_dir(None)) is not None:
|
if (clan_dir_result := clan_dir(None)) is not None:
|
||||||
cmd.append(clan_dir_result)
|
flake = clan_dir_result
|
||||||
result = subprocess.run(
|
else:
|
||||||
cmd,
|
flake = "."
|
||||||
check=True,
|
services_result = json.loads(
|
||||||
capture_output=True,
|
run(
|
||||||
text=True,
|
nix_eval(
|
||||||
|
flags=[
|
||||||
|
f"{flake}#nixosConfigurations",
|
||||||
|
"--apply",
|
||||||
|
"builtins.attrNames",
|
||||||
|
],
|
||||||
|
),
|
||||||
|
).stdout.strip()
|
||||||
)
|
)
|
||||||
|
|
||||||
data = json.loads(result.stdout)
|
machines.extend(services_result)
|
||||||
try:
|
|
||||||
machines.extend(data.get("nixosConfigurations").keys())
|
|
||||||
except KeyError:
|
|
||||||
pass
|
|
||||||
except subprocess.CalledProcessError:
|
except subprocess.CalledProcessError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user