101 lines
2.1 KiB
Nix
101 lines
2.1 KiB
Nix
# Module: base/network-static.nix
|
|
# This module statically configures networking
|
|
# on a host for both IPv4 and IPv6
|
|
{
|
|
config,
|
|
lib,
|
|
pkgs,
|
|
pkgsUnstable,
|
|
inputs,
|
|
options,
|
|
...
|
|
}:
|
|
|
|
with lib;
|
|
|
|
let
|
|
cfg = config.network-static;
|
|
|
|
defaultDNSServers = [
|
|
"1.1.1.1#cloudflare-dns.com"
|
|
"2606:4700:4700::1111#cloudflare-dns.com"
|
|
];
|
|
|
|
defaultTimeServers = [ "time.cloudflare.com" ];
|
|
in
|
|
{
|
|
options.network-static = {
|
|
enable = mkEnableOption "Enables networking config for Hetzner";
|
|
|
|
hardwareAddress = mkOption {
|
|
type = types.str;
|
|
default = "";
|
|
description = "MAC address of primary ethernet interface";
|
|
example = "11:22:33:44:55:66";
|
|
};
|
|
|
|
staticAddresses = mkOption {
|
|
type = types.listOf types.str;
|
|
default = [ ];
|
|
description = "Static addresses list in CIDR notation";
|
|
example = [
|
|
"192.168.1.2/24"
|
|
"fe80::1/64"
|
|
];
|
|
};
|
|
|
|
staticRoutes = mkOption {
|
|
type = types.listOf types.attrs;
|
|
description = "System DNS servers";
|
|
example = [
|
|
{
|
|
Gateway = "172.31.1.1";
|
|
GatewayOnLink = true;
|
|
}
|
|
{
|
|
Gateway = "fe80::1";
|
|
}
|
|
];
|
|
};
|
|
|
|
dnsServers = mkOption {
|
|
type = types.listOf types.str;
|
|
default = defaultDNSServers;
|
|
description = "System DNS servers";
|
|
example = [ "1.1.1.1" ];
|
|
};
|
|
|
|
timeServers = mkOption {
|
|
type = types.listOf types.str;
|
|
default = defaultTimeServers;
|
|
description = "System time servers";
|
|
example = [ "time.cloudflare.com" ];
|
|
};
|
|
};
|
|
|
|
config = mkIf cfg.enable {
|
|
networking = {
|
|
useNetworkd = true;
|
|
usePredictableInterfaceNames = false;
|
|
timeServers = cfg.timeServers;
|
|
nameservers = cfg.dnsServers;
|
|
};
|
|
|
|
systemd.network = {
|
|
enable = true;
|
|
|
|
links.eth0 = {
|
|
matchConfig.MACAddress = cfg.hardwareAddress;
|
|
linkConfig.Name = "eth0";
|
|
};
|
|
|
|
networks."05-eth" = {
|
|
matchConfig.Name = "eth0";
|
|
linkConfig.RequiredForOnline = "routable";
|
|
address = cfg.staticAddresses;
|
|
routes = cfg.staticRoutes;
|
|
};
|
|
};
|
|
};
|
|
}
|