Inventory: extend model by deployment info
This commit is contained in:
parent
ac95878ead
commit
7e21428548
@ -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": {
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user