api.inventory.modules: filter out /nix/store paths

This commit is contained in:
Johannes Kirschbauer
2024-12-04 09:16:50 +01:00
parent 8da4fceb24
commit fb6fa46a3b

View File

@@ -129,6 +129,19 @@ def set_inventory(
"""
inventory_file = get_path(flake_dir)
# Filter out modules not set via UI.
# It is not possible to set modules from "/nix/store" via the UI
modules = {}
filtered_modules = lambda m: {
key: value for key, value in m.items() if "/nix/store" not in value
}
if isinstance(inventory, dict):
modules = filtered_modules(inventory.get("modules", {})) # type: ignore
inventory["modules"] = modules
else:
modules = filtered_modules(inventory.modules) # type: ignore
inventory.modules = modules
with inventory_file.open("w") as f:
if isinstance(inventory, Inventory):
json.dump(dataclass_to_dict(inventory), f, indent=2)