nixos-servers/nix/modules/networking/default.nix

85 lines
1.8 KiB
Nix
Raw Normal View History

2024-01-28 10:48:13 +00:00
{ lib, config, machine, ... }:
let cfg = config.lab.networking;
in {
options.lab.networking = {
2024-01-31 20:58:23 +00:00
dmz = {
allowConnectivity = lib.mkOption {
default = false;
type = lib.types.bool;
description = ''
Whether to allow networking on the DMZ bridge interface.
'';
};
2024-01-31 20:58:23 +00:00
bridgeName = lib.mkOption {
default = "bridgedmz";
type = lib.types.str;
description = ''
The name of the DMZ bridge.
'';
};
};
2024-02-27 22:28:52 +00:00
staticNetworking = lib.mkOption {
default = false;
type = lib.types.bool;
description = ''
Whether this machine has static networking configuration applied.
Routing is prepopulated, but IP addresses have to be set.
'';
};
staticIPv4 = lib.mkOption {
type = lib.types.str;
description = ''
Static IPv4 address for the machine.
'';
};
staticIPv6 = lib.mkOption {
type = lib.types.str;
description = ''
2024-02-27 22:28:52 +00:00
Static IPv6 address for the machine.
'';
};
2023-12-30 14:20:16 +00:00
};
config = {
networking = {
domain = "dmz";
2024-01-31 20:58:23 +00:00
nftables.enable = true;
2024-02-27 22:28:52 +00:00
useDHCP = false;
2024-01-28 10:48:13 +00:00
firewall = {
2024-01-31 20:58:23 +00:00
enable = true;
checkReversePath = false;
};
};
2024-02-27 22:28:52 +00:00
systemd.network = {
enable = true;
2023-12-30 14:20:16 +00:00
2024-02-27 22:28:52 +00:00
networks = lib.attrsets.mergeAttrsList [
2024-04-13 13:43:01 +00:00
(lib.optionalAttrs (! machine.isRaspberryPi) {
2024-02-27 22:28:52 +00:00
"30-main-nic" = {
matchConfig.Name = "en*";
2023-12-30 14:20:16 +00:00
2024-02-27 22:28:52 +00:00
networkConfig = {
DHCP = "yes";
};
};
2024-02-27 22:28:52 +00:00
})
(lib.optionalAttrs machine.isRaspberryPi {
"30-main-nic" = {
matchConfig.Name = "end*";
networkConfig = {
IPv6AcceptRA = true;
DHCP = "yes";
};
};
})
];
2023-12-30 14:20:16 +00:00
};
};
}