Inventory: extend model by deployment info

This commit is contained in:
Johannes Kirschbauer
2024-07-16 16:15:56 +02:00
parent ac95878ead
commit 7e21428548
4 changed files with 60 additions and 12 deletions

View File

@@ -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;
}

View File

@@ -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