diff --git a/flake.nix b/flake.nix index 3371775..6a3a797 100644 --- a/flake.nix +++ b/flake.nix @@ -41,6 +41,33 @@ ./modules 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 = path: attrNames (attrsets.filterAttrs (name: type: type == "directory") (readDir path)); get_info = @@ -51,12 +78,16 @@ let filePath = path + "/${name}/info.nix"; 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) ); listInfoToAttrs = infos: add: listToAttrs (map (info: lib.nameValuePair info.name (info // add)) infos); + attrsToNixosSystem = path: all_hosts: hosts: mapAttrs ( @@ -72,6 +103,7 @@ ++ baseModules; } ) (attrsets.filterAttrs (name: info: !(info.isDebian or false)) hosts); + attrs_vm_info = listInfoToAttrs (get_info ./hosts/vm) { isVm = true; }; attrs_physique_info = listInfoToAttrs (get_info ./hosts/physiques) { isVm = false; }; attrs_all_info = attrs_physique_info // attrs_vm_info; diff --git a/hosts/physiques/zamok/info.nix b/hosts/physiques/zamok/info.nix index ce45c1b..3237c2d 100644 --- a/hosts/physiques/zamok/info.nix +++ b/hosts/physiques/zamok/info.nix @@ -15,7 +15,7 @@ arceus = 4; }; }; - + ilo = { id = 54; switch.salameche = 14;