Merge pull request 'Chore(complete_machines): simplify by using inventoryStore' (#3929) from hsjobeki/cleanups into main
Reviewed-on: https://git.clan.lol/clan/clan-core/pulls/3929
This commit is contained in:
@@ -194,7 +194,8 @@ in
|
||||
visible = false;
|
||||
# ClanInternals
|
||||
type = types.submodule {
|
||||
freeformType = types.attrsOf types.raw;
|
||||
# Uncomment this if you want to add more stuff while debugging
|
||||
# freeformType = types.attrsOf types.raw;
|
||||
options = {
|
||||
# Those options are interfaced by the CLI
|
||||
# We don't specify the type here, for better performance.
|
||||
|
||||
@@ -242,14 +242,14 @@ in
|
||||
|
||||
clanInternals = {
|
||||
inherit inventoryClass;
|
||||
# TODO: remove this after a month or so
|
||||
# This is here for backwards compatibility for older CLI versions
|
||||
inventory = config.inventory;
|
||||
|
||||
# TODO: unify this interface
|
||||
# We should have only clan.modules. (consistent with clan.templates)
|
||||
inherit (clan-core) clanModules;
|
||||
|
||||
templates = config.templates;
|
||||
|
||||
secrets = config.secrets;
|
||||
|
||||
# machine specifics
|
||||
|
||||
@@ -49,19 +49,10 @@ def complete_machines(
|
||||
flake = clan_dir_result
|
||||
else:
|
||||
flake = "."
|
||||
services_result = json.loads(
|
||||
run(
|
||||
nix_eval(
|
||||
flags=[
|
||||
f"{flake}#clanInternals.machines.x86_64-linux",
|
||||
"--apply",
|
||||
"builtins.attrNames",
|
||||
],
|
||||
),
|
||||
).stdout.strip()
|
||||
)
|
||||
|
||||
machines.extend(services_result)
|
||||
inventory = InventoryStore(Flake(str(flake))).read()
|
||||
machines.extend(inventory.get("machines", {}).keys())
|
||||
|
||||
except subprocess.CalledProcessError:
|
||||
pass
|
||||
|
||||
|
||||
@@ -792,62 +792,6 @@ class Flake:
|
||||
if self.flake_cache_path:
|
||||
self._cache.save_to_file(self.flake_cache_path)
|
||||
|
||||
def uncached_nix_eval_with_args(
|
||||
self,
|
||||
attr_path: str,
|
||||
f_args: dict[str, str],
|
||||
nix_options: list[str] | None = None,
|
||||
) -> str:
|
||||
"""
|
||||
Calls a nix function with the provided arguments 'f_args'
|
||||
The argument must be an attribute set.
|
||||
|
||||
Args:
|
||||
attr_path (str): The attribute path to the nix function
|
||||
f_args (dict[str, nix_expr]): A python dictionary mapping from the name of the argument to a raw nix expression.
|
||||
|
||||
Example
|
||||
|
||||
flake.uncached_nix_eval_with_args(
|
||||
"clanInternals.evalServiceSchema",
|
||||
{ "moduleSpec": "{ name = \"hello-world\"; input = null; }" }
|
||||
)
|
||||
> '{ ...JSONSchema... }'
|
||||
|
||||
"""
|
||||
from clan_lib.cmd import Log, RunOpts, run
|
||||
from clan_lib.nix import (
|
||||
nix_eval,
|
||||
nix_test_store,
|
||||
)
|
||||
|
||||
# Always prefetch, so we don't get any stale information
|
||||
self.prefetch()
|
||||
|
||||
if nix_options is None:
|
||||
nix_options = []
|
||||
|
||||
arg_expr = "{"
|
||||
for arg_name, arg_value in f_args.items():
|
||||
arg_expr += f" {arg_name} = {arg_value}; "
|
||||
arg_expr += "}"
|
||||
|
||||
nix_code = f"""
|
||||
let
|
||||
flake = builtins.getFlake "path:{self.store_path}?narHash={self.hash}";
|
||||
in
|
||||
flake.{attr_path} {arg_expr}
|
||||
"""
|
||||
if tmp_store := nix_test_store():
|
||||
nix_options += ["--store", str(tmp_store)]
|
||||
nix_options.append("--impure")
|
||||
|
||||
output = run(
|
||||
nix_eval(["--expr", nix_code, *nix_options]), RunOpts(log=Log.NONE)
|
||||
).stdout.strip()
|
||||
|
||||
return output
|
||||
|
||||
def precache(
|
||||
self,
|
||||
selectors: list[str],
|
||||
|
||||
Reference in New Issue
Block a user