{ config, lib, ... }: let inherit (lib) mkOption types; cfg = config.pepe.core.network; in { options.pepe.core.network = { interfaceTypes = { lan = mkOption { type = types.str; default = "lan"; description = "Key for LAN interface"; }; wan = mkOption { type = types.str; default = "wan"; description = "Key for WAN interface"; }; vpn = mkOption { type = types.str; default = "tailscale"; description = "Key for VPN interface"; }; }; interfaces = mkOption { type = types.attrsOf (types.submodule { options = { interface = mkOption { type = types.str; description = "The network interface name."; }; type = mkOption { type = types.enum [ "lan" "wan" "tailscale" ]; description = "The type of interface (lan, wan, or vpn/tailscale)."; }; net = mkOption { type = types.str; description = "The network address in CIDR format."; }; devices = mkOption { type = types.attrsOf (types.submodule { options = { address = mkOption { type = types.str; description = "The IP address of the device."; }; hostname = mkOption { type = types.str; description = "The hostname of the device."; }; }; }); default = { }; description = "An attribute set of devices with their configurations."; }; }; }); default = { }; description = "An attribute set of networks with their configurations."; }; }; config = { # Create lists of interfaces by type for easy access elsewhere pepe.core.network.interfacesByType = { lan = lib.filterAttrs (_: iface: iface.type == cfg.interfaceTypes.lan) cfg.interfaces; wan = lib.filterAttrs (_: iface: iface.type == cfg.interfaceTypes.wan) cfg.interfaces; vpn = lib.filterAttrs (_: iface: iface.type == cfg.interfaceTypes.vpn) cfg.interfaces; }; }; }