Inventory: extend model by deployment info
This commit is contained in:
@@ -8,7 +8,10 @@
|
|||||||
"system": "x86_64-linux",
|
"system": "x86_64-linux",
|
||||||
"description": "A nice thing",
|
"description": "A nice thing",
|
||||||
"icon": "./path/to/icon.png",
|
"icon": "./path/to/icon.png",
|
||||||
"tags": ["1", "2", "3"]
|
"tags": ["1", "2", "3"],
|
||||||
|
"deploymentInfo": {
|
||||||
|
"targetHost": "root@remote.com"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"services": {
|
"services": {
|
||||||
|
|||||||
@@ -30,6 +30,15 @@ let
|
|||||||
# - Machines that exist in the machines directory
|
# - Machines that exist in the machines directory
|
||||||
# Checks on the module level:
|
# Checks on the module level:
|
||||||
# - Each service role must reference a valid machine after all machines are merged
|
# - 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 =
|
mergedInventory =
|
||||||
(lib.evalModules {
|
(lib.evalModules {
|
||||||
modules = [
|
modules = [
|
||||||
@@ -63,23 +72,36 @@ let
|
|||||||
"name"
|
"name"
|
||||||
] name config
|
] name config
|
||||||
);
|
);
|
||||||
tags = lib.attrByPath [
|
}
|
||||||
|
# tags
|
||||||
|
// (clanToInventory config {
|
||||||
|
clanPath = [
|
||||||
"clan"
|
"clan"
|
||||||
"tags"
|
"tags"
|
||||||
] [ ] config;
|
];
|
||||||
|
inventoryPath = [ "tags" ];
|
||||||
system = lib.attrByPath [
|
})
|
||||||
|
# system
|
||||||
|
// (clanToInventory config {
|
||||||
|
clanPath = [
|
||||||
"nixpkgs"
|
"nixpkgs"
|
||||||
"hostSystem"
|
"hostSystem"
|
||||||
] null config;
|
];
|
||||||
|
inventoryPath = [ "system" ];
|
||||||
deploymentInfo.targetHost = lib.attrByPath [
|
})
|
||||||
|
# deploymentInfo.targetHost
|
||||||
|
// (clanToInventory config {
|
||||||
|
clanPath = [
|
||||||
"clan"
|
"clan"
|
||||||
"core"
|
"core"
|
||||||
"networking"
|
"networking"
|
||||||
"targetHost"
|
"targetHost"
|
||||||
] null config;
|
];
|
||||||
}
|
inventoryPath = [
|
||||||
|
"deploymentInfo"
|
||||||
|
"targetHost"
|
||||||
|
];
|
||||||
|
})
|
||||||
) machines;
|
) machines;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -148,6 +148,9 @@ let
|
|||||||
(lib.optionalAttrs (machineConfig.system or null != null) {
|
(lib.optionalAttrs (machineConfig.system or null != null) {
|
||||||
config.nixpkgs.hostPlatform = machineConfig.system;
|
config.nixpkgs.hostPlatform = machineConfig.system;
|
||||||
})
|
})
|
||||||
|
(lib.optionalAttrs (machineConfig.deploymentInfo.targetHost or null != null) {
|
||||||
|
config.clan.core.networking.targetHost = machineConfig.deploymentInfo.targetHost;
|
||||||
|
})
|
||||||
]
|
]
|
||||||
) inventory.machines or { };
|
) inventory.machines or { };
|
||||||
in
|
in
|
||||||
|
|||||||
@@ -35,6 +35,15 @@ def dataclass_to_dict(obj: Any) -> Any:
|
|||||||
return obj
|
return obj
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass
|
||||||
|
class DeploymentInfo:
|
||||||
|
"""
|
||||||
|
Deployment information for a machine.
|
||||||
|
"""
|
||||||
|
|
||||||
|
target_host: str | None = None
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class Machine:
|
class Machine:
|
||||||
"""
|
"""
|
||||||
@@ -49,14 +58,25 @@ class Machine:
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
name: str
|
name: str
|
||||||
system: Literal["x86_64-linux"] | str | None = None
|
|
||||||
description: str | None = None
|
description: str | None = None
|
||||||
icon: str | None = None
|
icon: str | None = None
|
||||||
tags: list[str] = field(default_factory=list)
|
tags: list[str] = field(default_factory=list)
|
||||||
|
system: Literal["x86_64-linux"] | str | None = None
|
||||||
|
|
||||||
|
deployment_info: DeploymentInfo | None = None
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def from_dict(d: dict[str, Any]) -> "Machine":
|
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
|
@dataclass
|
||||||
|
|||||||
Reference in New Issue
Block a user