home/nixos/networking.nix

23 lines
780 B
Nix
Raw Normal View History

2023-10-21 12:56:02 +02:00
{
pkgs,
2023-10-21 12:56:02 +02:00
eth-interface ? "eth0",
static-ip ? false, # false, or IPv4 address as string
default-gateway ? "192.168.1.1",
2023-10-21 12:56:02 +02:00
}:
let static-ip-conf = if static-ip != false then {
networking.defaultGateway = { address = default-gateway; interface = eth-interface; };
networking.useDHCP = false;
networking.interfaces.${eth-interface}.ipv4.addresses = [ {
2023-10-21 12:56:02 +02:00
address = static-ip;
prefixLength = 24;
} ];
networking.networkmanager.unmanaged = [eth-interface];
} else {};
in pkgs.lib.attrsets.recursiveUpdate static-ip-conf
{
networking.networkmanager.enable = true;
networking.nameservers = [ "8.8.8.8" ];
networking.resolvconf.enable = true;
networking.resolvconf.dnsExtensionMechanism = false; # edns seems to be fucky with this enabled
2023-10-21 12:56:02 +02:00
}