clan_lib: add inventory json argument

This commit is contained in:
Johannes Kirschbauer
2025-09-18 16:27:05 +02:00
parent c9ab0a42ac
commit 0fef161391

View File

@@ -28,6 +28,10 @@ def offline_template(tmp_path_factory: Any, offline_session_flake_hook: Any) ->
with (clan_json_file).open("w") as f:
f.write(r"""{ }""")
inventory_json_file = dst_dir / "inventory.json"
with (inventory_json_file).open("w") as f:
f.write(r"""{ }""")
# expensive call ~6 seconds
# Run in session scope to avoid repeated calls
offline_session_flake_hook(dst_dir)
@@ -56,7 +60,11 @@ def clan_flake(
tmp_path: Path,
patch_clan_template: Any, # noqa: ARG001
) -> Callable[[Clan | None, str | None], Flake]:
def factory(clan: Clan | None = None, raw: str | None = None) -> Flake:
def factory(
clan: Clan | None = None,
raw: str | None = None,
mutable_inventory_json: str | None = None,
) -> Flake:
# TODO: Make more options configurable
if clan is None and raw is None:
msg = "Either 'clan' or 'raw' must be provided to create a Flake."
@@ -78,6 +86,10 @@ def clan_flake(
with (dest / "clan.nix").open("w") as f:
f.write(raw)
if mutable_inventory_json is not None:
with (dest / "inventory.json").open("w") as f:
f.write(json.dumps(mutable_inventory_json))
return Flake(str(dest))
return factory