nixos/modules/core/network.nix
2025-04-26 17:09:32 +01:00

60 lines
1.7 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.";
};
};
config = {
# Create lists of interfaces by type for easy access elsewhere
cfg.interfacesByType = {
lan = lib.filterAttrs (_: iface: iface.type == "lan") cfg.interfaces;
wan = lib.filterAttrs (_: iface: iface.type == "wan") cfg.interfaces;
vpn = lib.filterAttrs (_: iface: iface.type == "vpn") cfg.interfaces;
};
};
}