diff --git a/inventory.json b/inventory.json index 3929343b5..fae406ab1 100644 --- a/inventory.json +++ b/inventory.json @@ -8,7 +8,10 @@ "system": "x86_64-linux", "description": "A nice thing", "icon": "./path/to/icon.png", - "tags": ["1", "2", "3"] + "tags": ["1", "2", "3"], + "deploymentInfo": { + "targetHost": "root@remote.com" + } } }, "services": { diff --git a/lib/build-clan/default.nix b/lib/build-clan/default.nix index 7b6e4969e..2b1921734 100644 --- a/lib/build-clan/default.nix +++ b/lib/build-clan/default.nix @@ -30,6 +30,15 @@ let # - Machines that exist in the machines directory # Checks on the module level: # - Each service role must reference a valid machine after all machines are merged + + clanToInventory = + config: + { clanPath, inventoryPath }: + let + v = lib.attrByPath clanPath null config; + in + lib.optionalAttrs (v != null) (lib.setAttrByPath inventoryPath v); + mergedInventory = (lib.evalModules { modules = [ @@ -63,23 +72,36 @@ let "name" ] name config ); - tags = lib.attrByPath [ + } + # tags + // (clanToInventory config { + clanPath = [ "clan" "tags" - ] [ ] config; - - system = lib.attrByPath [ + ]; + inventoryPath = [ "tags" ]; + }) + # system + // (clanToInventory config { + clanPath = [ "nixpkgs" "hostSystem" - ] null config; - - deploymentInfo.targetHost = lib.attrByPath [ + ]; + inventoryPath = [ "system" ]; + }) + # deploymentInfo.targetHost + // (clanToInventory config { + clanPath = [ "clan" "core" "networking" "targetHost" - ] null config; - } + ]; + inventoryPath = [ + "deploymentInfo" + "targetHost" + ]; + }) ) machines; } diff --git a/lib/inventory/build-inventory/default.nix b/lib/inventory/build-inventory/default.nix index 413c79766..9b1e3f3e5 100644 --- a/lib/inventory/build-inventory/default.nix +++ b/lib/inventory/build-inventory/default.nix @@ -148,6 +148,9 @@ let (lib.optionalAttrs (machineConfig.system or null != null) { config.nixpkgs.hostPlatform = machineConfig.system; }) + (lib.optionalAttrs (machineConfig.deploymentInfo.targetHost or null != null) { + config.clan.core.networking.targetHost = machineConfig.deploymentInfo.targetHost; + }) ] ) inventory.machines or { }; in diff --git a/pkgs/clan-cli/clan_cli/inventory/__init__.py b/pkgs/clan-cli/clan_cli/inventory/__init__.py index 00fb00972..bb621e1d5 100644 --- a/pkgs/clan-cli/clan_cli/inventory/__init__.py +++ b/pkgs/clan-cli/clan_cli/inventory/__init__.py @@ -35,6 +35,15 @@ def dataclass_to_dict(obj: Any) -> Any: return obj +@dataclass +class DeploymentInfo: + """ + Deployment information for a machine. + """ + + target_host: str | None = None + + @dataclass class Machine: """ @@ -49,14 +58,25 @@ class Machine: """ name: str - system: Literal["x86_64-linux"] | str | None = None description: str | None = None icon: str | None = None tags: list[str] = field(default_factory=list) + system: Literal["x86_64-linux"] | str | None = None + + deployment_info: DeploymentInfo | None = None @staticmethod def from_dict(d: dict[str, Any]) -> "Machine": - return Machine(**d) + return Machine( + name=d["name"], + description=d.get("description", None), + icon=d.get("icon", None), + tags=d.get("tags", []), + system=d.get("system", None), + deployment_info=DeploymentInfo( + target_host=d.get("deploymentInfo", {}).get("targetHost", None) + ), + ) @dataclass