diff --git a/modules/crans/networking.nix b/modules/crans/networking.nix index a376fb2..46e3b17 100644 --- a/modules/crans/networking.nix +++ b/modules/crans/networking.nix @@ -72,18 +72,21 @@ in }; config = mkIf cfg.enable { - networking = - { - useDHCP = false; - firewall.enable = lib.mkDefault false; - nameservers = [ "172.16.10.128" ]; - } - // - # Configuration du VLAN adm - ( - if cfg.adm.enable then - { - interfaces."${cfg.adm.interface}" = { + networking = { + useDHCP = false; + firewall.enable = lib.mkDefault false; + nameservers = [ "172.16.10.128" ]; + + interfaces = + lib.attrsets.mapAttrs' + (interface: conf: { + name = cfg."${interface}".interface; + value = conf; + }) + ( + lib.attrsets.filterAttrs (interface: _: cfg."${interface}".enable) { + # Configuration du VLAN adm + adm = { ipv4.addresses = [ { address = "172.16.10.1${cfg.id}"; @@ -98,18 +101,9 @@ in } ]; }; - } - else - { } - ) - // - # Configuration du VLAN srv - ( - if cfg.srv.enable then - { - firewall.enable = true; - interfaces."${cfg.srv.interface}" = { + # Configuration du VLAN srv + srv = { ipv4 = { addresses = [ { @@ -141,17 +135,9 @@ in ]; }; }; - } - else - { } - ) - // - # Configuration du VLAN srv-nat - ( - if cfg.srvNat.enable then - { - interfaces."${cfg.srvNat.interface}" = { + # Configuration du VLAN srv-nat + srvNat = { ipv4 = { addresses = [ { @@ -184,16 +170,9 @@ in ]; }; }; - } - else - { } - ) - // - # Configuration du VLAN san - ( - if cfg.san.enable then - { - interfaces."${cfg.san.interface}" = { + + # Configuration du VLAN san + san = { ipv4.addresses = [ { address = "172.16.4.1${cfg.id}"; @@ -209,8 +188,7 @@ in ]; }; } - else - { } - ); + ); + }; }; }