Move all nixos networking config to networking.nix, make networkmanager not configure ethernet if static-ip is set

This commit is contained in:
xenia 2024-06-23 22:43:00 +02:00
parent e8c73318a1
commit 0c641b47ad
3 changed files with 15 additions and 13 deletions

View File

@ -152,6 +152,7 @@
background = "pan-wire-3.png"; background = "pan-wire-3.png";
}; };
networking = mkNixOsNetworking { networking = mkNixOsNetworking {
inherit pkgs;
eth-interface = "enp0s31f6"; eth-interface = "enp0s31f6";
static-ip = "192.168.0.199"; static-ip = "192.168.0.199";
}; };

View File

@ -39,7 +39,6 @@
grub.devce = grub-device; grub.devce = grub-device;
} else throw "Please use either use-efi or use-grub = true"; } else throw "Please use either use-efi or use-grub = true";
networking.networkmanager.enable = true;
time.timeZone = "Europe/Stockholm"; time.timeZone = "Europe/Stockholm";
@ -86,10 +85,6 @@
virtualisation.docker.enable = true; virtualisation.docker.enable = true;
networking.resolvconf.enable = true;
networking.nameservers = [ "8.8.8.8" ];
networking.resolvconf.dnsExtensionMechanism = false; # edns seems to be fucky with this enabled
nix.settings = { nix.settings = {
experimental-features = [ "nix-command" "flakes" ]; experimental-features = [ "nix-command" "flakes" ];
auto-optimise-store = true; auto-optimise-store = true;

View File

@ -1,16 +1,22 @@
{ {
pkgs,
eth-interface ? "eth0", eth-interface ? "eth0",
static-ip ? false, # false, or IPv4 address static-ip ? false, # false, or IPv4 address as string
default-gateway ? "192.168.1.1", default-gateway ? "192.168.1.1",
}: }:
{ let static-ip-conf = if static-ip != false then {
networking = if static-ip != false then { networking.defaultGateway = { address = default-gateway; interface = eth-interface; };
defaultGateway = { address = default-gateway; interface = eth-interface; }; networking.useDHCP = false;
useDHCP = false; networking.interfaces.${eth-interface}.ipv4.addresses = [ {
interfaces.${eth-interface}.ipv4.addresses = [ {
address = static-ip; address = static-ip;
prefixLength = 24; prefixLength = 24;
} ]; } ];
} else { 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
} }