Make clean router service
This commit is contained in:
parent
508b86c9cc
commit
1628359fbd
1 changed files with 75 additions and 24 deletions
|
@ -1,32 +1,83 @@
|
||||||
{
|
{ config, lib, pkgs, ... }:
|
||||||
# To get the MAC address of each card, use this command: cat /sys/class/net/*device_name*/address
|
|
||||||
# Make sure to use the lower-case hex values in your udev rules. It does not like upper-case.
|
|
||||||
wanInterface, wirelessInterfaces, lanInterfaces,
|
|
||||||
internalRouterIP,
|
|
||||||
internalPrefixLength? 24,
|
|
||||||
internalBridgeInterfaceName? "lan"
|
|
||||||
}:
|
|
||||||
|
|
||||||
let pkgs = import <nixpkgs> { };
|
with lib;
|
||||||
|
|
||||||
|
let cfg = config.services.router;
|
||||||
in {
|
in {
|
||||||
|
options.services.router = {
|
||||||
|
enable = mkEnableOption "router service";
|
||||||
|
|
||||||
|
wanInterface = mkOption {
|
||||||
|
type = types.str;
|
||||||
|
example = "enp0";
|
||||||
|
description = ''
|
||||||
|
WAN interface name.
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
|
wirelessInterfaces = mkOption {
|
||||||
|
type = types.listOf types.str;
|
||||||
|
example = [ "wlp1" "wlp2" ];
|
||||||
|
default = [ ];
|
||||||
|
description = ''
|
||||||
|
Wireless interfaces names.
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
|
lanInterfaces = mkOption {
|
||||||
|
type = types.listOf types.str;
|
||||||
|
example = [ "enp1" "enp2" ];
|
||||||
|
default = [ ];
|
||||||
|
description = ''
|
||||||
|
LAN interfaces names.
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
|
internalRouterIP = mkOption {
|
||||||
|
type = types.str;
|
||||||
|
example = "192.168.0.1";
|
||||||
|
description = ''
|
||||||
|
Internal IP of router.
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
|
internalPrefixLength = mkOption {
|
||||||
|
type = types.addCheck types.int (n: n >= 0 && n <= 32);
|
||||||
|
default = 24;
|
||||||
|
description = ''
|
||||||
|
Subnet mask of the network, specified as the number of
|
||||||
|
bits in the prefix (<literal>24</literal>).
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
|
internalBridgeInterfaceName = mkOption {
|
||||||
|
type = types.str;
|
||||||
|
default = "lan";
|
||||||
|
description = ''
|
||||||
|
Name of the virtual internal interface.
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
config = mkIf cfg.enable {
|
||||||
networking = {
|
networking = {
|
||||||
enableIPv6 = false; # TODO
|
enableIPv6 = false; # TODO
|
||||||
nat = {
|
nat = {
|
||||||
enable = true;
|
enable = true;
|
||||||
externalInterface = wanInterface;
|
externalInterface = cfg.wanInterface;
|
||||||
internalInterfaces = [ internalBridgeInterfaceName ];
|
internalInterfaces = [ cfg.internalBridgeInterfaceName ];
|
||||||
};
|
};
|
||||||
|
|
||||||
bridges.lan.interfaces = lanInterfaces ++ wirelessInterfaces;
|
bridges.lan.interfaces = cfg.lanInterfaces ++ cfg.wirelessInterfaces;
|
||||||
interfaces.lan = {
|
interfaces.lan = {
|
||||||
ipv4 = {
|
ipv4 = {
|
||||||
addresses = [{
|
addresses = [{
|
||||||
address = internalRouterIP;
|
address = cfg.internalRouterIP;
|
||||||
prefixLength = internalPrefixLength;
|
prefixLength = cfg.internalPrefixLength;
|
||||||
}];
|
}];
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
firewall.trustedInterfaces = [ internalBridgeInterfaceName ];
|
firewall.trustedInterfaces = [ cfg.internalBridgeInterfaceName ];
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue