80 lines
2.3 KiB
Nix
80 lines
2.3 KiB
Nix
{ config, lib, ... }:
|
|
|
|
let
|
|
inherit (lib) mkOption types;
|
|
cfg = config.pepe.core.network;
|
|
in
|
|
{
|
|
options.pepe.core.network = {
|
|
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" "vpn" ];
|
|
description = "The type of interface (lan, wan, or vpn).";
|
|
};
|
|
|
|
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.";
|
|
};
|
|
|
|
interfacesByType = mkOption {
|
|
type = types.attrsOf (types.listOf types.str);
|
|
default = {};
|
|
description = "Interfaces grouped by type (lan, wan, vpn) for easy access.";
|
|
internal = true;
|
|
};
|
|
|
|
interfaceTypes = mkOption {
|
|
type = types.attrsOf types.str;
|
|
default = {
|
|
lan = "lan";
|
|
wan = "wan";
|
|
vpn = "vpn";
|
|
};
|
|
description = "Interface type identifiers for easy reference.";
|
|
};
|
|
|
|
};
|
|
|
|
config = {
|
|
# Create lists of interfaces by type for easy access elsewhere
|
|
pepe.core.network.interfacesByType = {
|
|
lan = lib.attrNames (lib.filterAttrs (_: iface: iface.type == "lan") cfg.interfaces);
|
|
wan = lib.attrNames (lib.filterAttrs (_: iface: iface.type == "wan") cfg.interfaces);
|
|
vpn = lib.attrNames (lib.filterAttrs (_: iface: iface.type == "vpn") cfg.interfaces);
|
|
};
|
|
|
|
# We don't need the groups anymore as we're using interfacesByType directly
|
|
};
|
|
}
|