From 0c641b47ad2110a60e512ed47adc06bb8b76c60b Mon Sep 17 00:00:00 2001 From: xenia Date: Sun, 23 Jun 2024 22:43:00 +0200 Subject: [PATCH] Move all nixos networking config to networking.nix, make networkmanager not configure ethernet if static-ip is set --- flake.nix | 1 + nixos/base.nix | 5 ----- nixos/networking.nix | 22 ++++++++++++++-------- 3 files changed, 15 insertions(+), 13 deletions(-) diff --git a/flake.nix b/flake.nix index 0e7a383e..6816e099 100644 --- a/flake.nix +++ b/flake.nix @@ -152,6 +152,7 @@ background = "pan-wire-3.png"; }; networking = mkNixOsNetworking { + inherit pkgs; eth-interface = "enp0s31f6"; static-ip = "192.168.0.199"; }; diff --git a/nixos/base.nix b/nixos/base.nix index 5a92cf24..aa308f2d 100644 --- a/nixos/base.nix +++ b/nixos/base.nix @@ -39,7 +39,6 @@ grub.devce = grub-device; } else throw "Please use either use-efi or use-grub = true"; - networking.networkmanager.enable = true; time.timeZone = "Europe/Stockholm"; @@ -86,10 +85,6 @@ 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 = { experimental-features = [ "nix-command" "flakes" ]; auto-optimise-store = true; diff --git a/nixos/networking.nix b/nixos/networking.nix index 7f9bc9b7..c695cccf 100644 --- a/nixos/networking.nix +++ b/nixos/networking.nix @@ -1,16 +1,22 @@ { + pkgs, 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", }: -{ - networking = if static-ip != false then { - defaultGateway = { address = default-gateway; interface = eth-interface; }; - useDHCP = false; - interfaces.${eth-interface}.ipv4.addresses = [ { + 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 = [ { address = static-ip; 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 }