about summary refs log tree commit diff
path: root/modules/common/networking.nix
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--modules/common/networking.nix51
1 files changed, 27 insertions, 24 deletions
diff --git a/modules/common/networking.nix b/modules/common/networking.nix
index f681deb..71df24a 100644
--- a/modules/common/networking.nix
+++ b/modules/common/networking.nix
@@ -5,31 +5,30 @@
   this,
   ...
 }:
-with lib;
 let
   cfg = config.nixfiles.modules.common.networking;
 in
 {
-  options.nixfiles.modules.common.networking.onlyDefault = mkEnableOption "custom networking settings";
+  options.nixfiles.modules.common.networking.onlyDefault = lib.mkEnableOption "custom networking settings";
 
-  config = mkIf (!cfg.onlyDefault) {
+  config = lib.mkIf (!cfg.onlyDefault) {
     ark.directories =
       with config.networking;
-      optional networkmanager.enable "/etc/NetworkManager/system-connections"
-      ++ optional wireless.iwd.enable "/var/lib/iwd";
+      lib.optional networkmanager.enable "/etc/NetworkManager/system-connections"
+      ++ lib.optional wireless.iwd.enable "/var/lib/iwd";
 
-    networking = mkMerge [
+    networking = lib.mkMerge [
       {
-        domain = my.domain.shire;
+        domain = lib.my.domain.shire;
 
         hostName = this.hostname;
-        hostId = substring 0 8 (builtins.hashString "md5" this.hostname);
+        hostId = lib.substring 0 8 (builtins.hashString "md5" this.hostname);
 
         # Remove default hostname mappings. This is required at least by the
         # current implementation of the monitoring module.
         hosts = {
-          "127.0.0.2" = mkForce [ ];
-          "::1" = mkForce [ ];
+          "127.0.0.2" = lib.mkForce [ ];
+          "::1" = lib.mkForce [ ];
         };
 
         # There's no way[1] to configure DNS server priority in
@@ -41,7 +40,7 @@ in
         #
         # [1]: https://askubuntu.com/questions/1116732/how-do-i-list-dns-server-order-in-systemd-resolve
         # [2]: https://github.com/systemd/systemd/issues/6076
-        nameservers = with my.configurations.manwe.wireguard; [
+        nameservers = with lib.my.configurations.manwe.wireguard; [
           ipv6.address
           ipv4.address
         ];
@@ -68,49 +67,53 @@ in
         let
           interface = "eth0"; # This assumes `usePredictableInterfaceNames` is false.
         in
-        mkIf (hasAttr "ipv4" this && hasAttr "ipv6" this) {
+        lib.mkIf (lib.hasAttr "ipv4" this && lib.hasAttr "ipv6" this) {
           usePredictableInterfaceNames = false; # NOTE This can break something!
           interfaces.${interface} = {
             ipv4.addresses =
               with this.ipv4;
-              optional (isString address && isInt prefixLength) { inherit address prefixLength; };
+              lib.optional (lib.isString address && lib.isInt prefixLength) {
+                inherit address prefixLength;
+              };
 
             ipv6.addresses =
               with this.ipv6;
-              optional (isString address && isInt prefixLength) { inherit address prefixLength; };
+              lib.optional (lib.isString address && lib.isInt prefixLength) {
+                inherit address prefixLength;
+              };
           };
           defaultGateway =
             with this.ipv4;
-            mkIf (isString gatewayAddress) {
+            lib.mkIf (lib.isString gatewayAddress) {
               inherit interface;
               address = gatewayAddress;
             };
           defaultGateway6 =
             with this.ipv6;
-            mkIf (isString gatewayAddress) {
+            lib.mkIf (lib.isString gatewayAddress) {
               inherit interface;
               address = gatewayAddress;
             };
         }
       )
-      (mkIf this.isHeadful {
-        interfaces.eth0.useDHCP = mkDefault true;
+      (lib.mkIf this.isHeadful {
+        interfaces.eth0.useDHCP = lib.mkDefault true;
 
         networkmanager = {
-          enable = mkDefault true;
+          enable = lib.mkDefault true;
           unmanaged = [
             "bridge"
             "ethernet"
             "loopback"
             "wireguard"
           ];
-          plugins = mkForce [ ];
+          plugins = lib.mkForce [ ];
           wifi.backend = "iwd";
         };
 
         wireless = {
           enable = false;
-          iwd.enable = mkDefault true;
+          iwd.enable = lib.mkDefault true;
           userControlled.enable = true;
           allowAuxiliaryImperativeNetworks = true;
         };
@@ -121,12 +124,12 @@ in
       llmnr = "false";
       dnsovertls = "opportunistic";
       dnssec = "allow-downgrade";
-      fallbackDns = dns.mkDoT dns.const.quad9.ecs;
+      fallbackDns = lib.dns.mkDoT lib.dns.const.quad9.ecs;
     };
 
     environment = {
-      shellAliases = listToAttrs (
-        map ({ name, value }: nameValuePair name "${pkgs.iproute2}/bin/${value}") [
+      shellAliases = lib.listToAttrs (
+        map ({ name, value }: lib.nameValuePair name "${pkgs.iproute2}/bin/${value}") [
           {
             name = "bridge";
             value = "bridge -color=always";

Consider giving Nix/NixOS a try! <3