From fefefa84eaf909cef4044e91399ecb93c7712d11 Mon Sep 17 00:00:00 2001 From: Pyjacpp Date: Sun, 6 Sep 2026 14:47:13 +0200 Subject: [PATCH] cleanup hosts-v2 --- flake.nix | 35 ++++++++++++---------------------- modules/crans/default.nix | 40 +++++++++++++++++++++++++++++++++++++-- modules/crans/extra.nix | 32 ------------------------------- 3 files changed, 50 insertions(+), 57 deletions(-) delete mode 100644 modules/crans/extra.nix diff --git a/flake.nix b/flake.nix index e4af1b4..d928964 100644 --- a/flake.nix +++ b/flake.nix @@ -26,12 +26,15 @@ agenix, ... }: + let + lib = nixpkgs.lib; + in flake-parts.lib.mkFlake { inherit inputs; } { imports = [ inputs.treefmt-nix.flakeModule ]; systems = [ "x86_64-linux" ]; - flake = with nixpkgs.lib; { + flake = with lib; { nixosConfigurations = let baseModules = [ @@ -40,35 +43,20 @@ ]; get_hosts_names = path: attrNames (attrsets.filterAttrs (name: type: type == "directory") (readDir path)); - hostVM = get_hosts_names ./hosts/vm; - hostPhysique = get_hosts_names ./hosts/physiques; get_info = - path: lists: + path: filter (x: x != null) ( map ( name: let filePath = path + "/${name}/info.nix"; in - if builtins.pathExists filePath then - { - crans = import filePath; - } - else - warn "${toString filePath} not found" null - ) lists + if builtins.pathExists filePath then import filePath else warn "${toString filePath} not found" null + ) (get_hosts_names path) ); - hosts_vm_info = get_info ./hosts/vm hostVM; - hosts_physique_info = get_info ./hosts/physiques hostPhysique; listInfoToAttrs = - path: infos: - listToAttrs ( - map (info: { - name = info.crans.name; - value = info; - }) infos - ); + infos: add: listToAttrs (map (info: lib.nameValuePair info.name (info // add)) infos); attrsToNixosSystem = path: all_hosts: hosts: mapAttrs ( @@ -79,16 +67,17 @@ }; modules = [ (path + "/${name}") - info + ({ ... }: { config.crans = info; }) ] ++ baseModules; } ) hosts; - attrs_vm_info = listInfoToAttrs ./hosts/vm hosts_vm_info; - attrs_physique_info = listInfoToAttrs ./hosts/physiques hosts_physique_info; + 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; in (attrsToNixosSystem ./hosts/vm attrs_all_info attrs_vm_info) + // (attrsToNixosSystem ./hosts/physiques attrs_all_info attrs_physique_info) // { cransIso = nixosSystem { system = "x86_64-linux"; diff --git a/modules/crans/default.nix b/modules/crans/default.nix index ff29544..d55cf8a 100644 --- a/modules/crans/default.nix +++ b/modules/crans/default.nix @@ -3,12 +3,16 @@ let cfg = config.crans; - inherit (lib) mkEnableOption mkIf; + inherit (lib) + mkEnableOption + mkOption + types + mkIf + ; in { imports = [ ./age.nix - ./extra.nix ./grub.nix ./home.nix ./locale.nix @@ -26,6 +30,38 @@ in options.crans = { enable = mkEnableOption "Configuration commune à toutes les machines du Crans"; + + name = mkOption { + type = types.str; + example = "vm-test"; + description = "Nom de la machine"; + }; + + isVm = mkOption { + type = types.bool; + description = "Est-ce une machine virtuelle ?"; + }; + + description = mkOption { + type = types.str; + example = "VM de test"; + description = "Description de la machine"; + }; + + id = mkOption { + type = types.int; + example = 135; + description = '' + ID de la machine : + - < 100 machine physique + - >= 100 VM ( id de la VM dans proxmox ) + ''; + }; + + public-ssh = mkOption { + type = types.str; + description = "Clé ssh public de la machine"; + }; }; config = mkIf cfg.enable { diff --git a/modules/crans/extra.nix b/modules/crans/extra.nix deleted file mode 100644 index e782292..0000000 --- a/modules/crans/extra.nix +++ /dev/null @@ -1,32 +0,0 @@ -{ lib, ... }: -with lib; -{ - options.crans = { - name = mkOption { - type = types.str; - example = "vm-test"; - description = "Nom de la machine"; - }; - - description = mkOption { - type = types.str; - example = "VM de test"; - description = "Description de la machine"; - }; - - id = mkOption { - type = types.int; - example = 135; - description = """ - ID de la machine : - - < 100 machine physique - - >= 100 VM ( id de la VM dans proxmox ) - """; - }; - - public-ssh = mkOption { - type = types.str; - description = "Clé ssh public de la machine"; - }; - }; -}