Verification info.nix

hosts-v2
Pyjacpp 2026-09-15 17:28:51 +02:00
parent 602971a10a
commit bf2cd34569
No known key found for this signature in database
GPG Key ID: ED479A5A26930939
2 changed files with 34 additions and 2 deletions

View File

@ -41,6 +41,33 @@
./modules ./modules
agenix.nixosModules.default agenix.nixosModules.default
]; ];
infoRequired = {
name = lib.isString;
description = lib.isString;
id = lib.isInt;
};
verifyAttrs =
info:
let
missing = lib.filter (n: !(info ? ${n})) (map (i: i.name) (lib.attrsToList infoRequired));
wrongType = lib.filter (n: info ? ${n.name} && !(n.value info.${n.name})) (
lib.attrsToList infoRequired
);
in
(lib.warnIf (
lib.length missing > 0
) "${info.name}/info.nix : les attributs « ${lib.join ", " missing} » sont manquants")
(lib.warnIf (lib.length wrongType > 0)
"${info.name}/info.nix : les attributs « ${
lib.join ", " (map (i: i.name) wrongType)
} » sont mal typés"
)
(lib.warnIfNot (
(info.isDebian or false) || info ? enable
) "${info.name}/info.nix : cette machine nix ne définit pas l’attribut enable")
info;
get_hosts_names = get_hosts_names =
path: attrNames (attrsets.filterAttrs (name: type: type == "directory") (readDir path)); path: attrNames (attrsets.filterAttrs (name: type: type == "directory") (readDir path));
get_info = get_info =
@ -51,12 +78,16 @@
let let
filePath = path + "/${name}/info.nix"; filePath = path + "/${name}/info.nix";
in in
if builtins.pathExists filePath then import filePath else warn "${toString filePath} not found" null if builtins.pathExists filePath then
verifyAttrs (import filePath)
else
warn "${toString filePath} not found" null
) (get_hosts_names path) ) (get_hosts_names path)
); );
listInfoToAttrs = listInfoToAttrs =
infos: add: listToAttrs (map (info: lib.nameValuePair info.name (info // add)) infos); infos: add: listToAttrs (map (info: lib.nameValuePair info.name (info // add)) infos);
attrsToNixosSystem = attrsToNixosSystem =
path: all_hosts: hosts: path: all_hosts: hosts:
mapAttrs ( mapAttrs (
@ -72,6 +103,7 @@
++ baseModules; ++ baseModules;
} }
) (attrsets.filterAttrs (name: info: !(info.isDebian or false)) hosts); ) (attrsets.filterAttrs (name: info: !(info.isDebian or false)) hosts);
attrs_vm_info = listInfoToAttrs (get_info ./hosts/vm) { isVm = true; }; attrs_vm_info = listInfoToAttrs (get_info ./hosts/vm) { isVm = true; };
attrs_physique_info = listInfoToAttrs (get_info ./hosts/physiques) { isVm = false; }; attrs_physique_info = listInfoToAttrs (get_info ./hosts/physiques) { isVm = false; };
attrs_all_info = attrs_physique_info // attrs_vm_info; attrs_all_info = attrs_physique_info // attrs_vm_info;

View File

@ -15,7 +15,7 @@
arceus = 4; arceus = 4;
}; };
}; };
ilo = { ilo = {
id = 54; id = 54;
switch.salameche = 14; switch.salameche = 14;