From 8a23bd79324a85a5d85e5be68fda4023df06729f Mon Sep 17 00:00:00 2001 From: Gabriel Arazas Date: Tue, 31 Jan 2023 16:48:10 +0800 Subject: [PATCH] hosts/ni: modularize networking configuration Re-added the setup with the traditional networking configuration since I'm currently using GNOME which only integrates with NetworkManager which is working alongside it. systemd-networkd not being used at this point but I'm keeping it. --- hosts/ni/hardware-configuration.nix | 53 ++----------------- .../ni/modules/hardware/systemd-networkd.nix | 51 ++++++++++++++++++ .../hardware/traditional-networking.nix | 21 ++++++++ 3 files changed, 76 insertions(+), 49 deletions(-) create mode 100644 hosts/ni/modules/hardware/systemd-networkd.nix create mode 100644 hosts/ni/modules/hardware/traditional-networking.nix diff --git a/hosts/ni/hardware-configuration.nix b/hosts/ni/hardware-configuration.nix index 28e2f631..e70874af 100644 --- a/hosts/ni/hardware-configuration.nix +++ b/hosts/ni/hardware-configuration.nix @@ -1,7 +1,10 @@ { config, lib, pkgs, modulesPath, ... }: { - imports = [ (modulesPath + "/installer/scan/not-detected.nix") ]; + imports = [ + (modulesPath + "/installer/scan/not-detected.nix") + ./modules/hardware/traditional-networking.nix + ]; boot.initrd.availableKernelModules = [ "xhci_pci" "ahci" "nvme" "usb_storage" "uas" "sd_mod" ]; @@ -25,54 +28,6 @@ swapDevices = [{ label = "swap"; }]; - networking = { - usePredictableInterfaceNames = true; - useNetworkd = true; - - # We're using networkd to configure so we're disabling this - # service. - useDHCP = false; - dhcpcd.enable = false; - }; - - # Enable systemd-resolved. This is mostly setup by `systemd.network.enable` - # by we're being explicit just to be safe. - services.resolved = { - enable = true; - llmnr = "true"; - }; - - # Combining my ethernet and wireless network interfaces. - systemd.network = { - enable = true; - netdevs."40-bond1" = { - netdevConfig = { - Name = "bond1"; - Kind = "bond"; - }; - }; - - networks = { - "40-bond1" = { - matchConfig.Name = "bond1"; - networkConfig.DHCP = "yes"; - }; - - "40-bond1-dev1" = { - matchConfig.Name = "enp1s0"; - networkConfig.Bond = "bond1"; - }; - - "40-bond1-dev2" = { - matchConfig.Name = "wlp2s0"; - networkConfig = { - Bond = "bond1"; - IgnoreCarrierLoss = "15"; - }; - }; - }; - }; - powerManagement.cpuFreqGovernor = lib.mkDefault "powersave"; hardware.cpu.intel.updateMicrocode = lib.mkDefault true; diff --git a/hosts/ni/modules/hardware/systemd-networkd.nix b/hosts/ni/modules/hardware/systemd-networkd.nix new file mode 100644 index 00000000..6c134480 --- /dev/null +++ b/hosts/ni/modules/hardware/systemd-networkd.nix @@ -0,0 +1,51 @@ +{ config, options, lib, pkgs, ... }: + +{ + networking = { + usePredictableInterfaceNames = true; + useNetworkd = true; + + # We're using networkd to configure so we're disabling this + # service. + useDHCP = false; + dhcpcd.enable = false; + }; + + # Enable systemd-resolved. This is mostly setup by `systemd.network.enable` + # by we're being explicit just to be safe. + services.resolved = { + enable = false; + llmnr = "true"; + }; + + # Combining my ethernet and wireless network interfaces. + systemd.network = { + enable = false; + netdevs."40-bond1" = { + netdevConfig = { + Name = "bond1"; + Kind = "bond"; + }; + }; + + networks = { + "40-bond1" = { + matchConfig.Name = "bond1"; + networkConfig.DHCP = "yes"; + }; + + "40-bond1-dev1" = { + matchConfig.Name = "enp1s0"; + networkConfig.Bond = "bond1"; + }; + + "40-bond1-dev2" = { + matchConfig.Name = "wlp2s0"; + networkConfig = { + Bond = "bond1"; + IgnoreCarrierLoss = "15"; + }; + }; + }; + }; +} diff --git a/hosts/ni/modules/hardware/traditional-networking.nix b/hosts/ni/modules/hardware/traditional-networking.nix new file mode 100644 index 00000000..ec61cd27 --- /dev/null +++ b/hosts/ni/modules/hardware/traditional-networking.nix @@ -0,0 +1,21 @@ +{ config, options, lib, pkgs, ... }: + +{ + networking = { + usePredictableInterfaceNames = true; + + useDHCP = false; + dhcpcd.enable = true; + + interfaces.enp1s0.useDHCP = true; + interfaces.wlp2s0.useDHCP = true; + + bonds.bond0 = { + driverOptions = { + miimon = "100"; + mode = "active-backup"; + }; + interfaces = [ "enp1s0" "wlp2s0" ]; + }; + }; +}