about summary refs log tree commit diff stats
path: root/modules/system/networking
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--modules/system/networking/default.nix81
1 files changed, 81 insertions, 0 deletions
diff --git a/modules/system/networking/default.nix b/modules/system/networking/default.nix
new file mode 100644
index 00000000..aaaab782
--- /dev/null
+++ b/modules/system/networking/default.nix
@@ -0,0 +1,81 @@
+{
+  config,
+  lib,
+  ...
+}: let
+  cfg = config.soispha.networking;
+in {
+  options.soispha.networking = {
+    enable = lib.mkEnableOption "networking";
+
+    networkManager = {
+      enable = lib.mkEnableOption "NetworkManager";
+    };
+
+    hostName = lib.mkOption {
+      type = lib.types.str;
+      example = "apzu";
+      description = "The name of the host";
+    };
+  };
+
+  config =
+    lib.mkIf cfg.enable {
+      systemd.network = {
+        networks = {
+          "tap0" = {
+            name = "tap0";
+            bridge = [
+              "virbr0"
+            ];
+          };
+          "enp4s0" = {
+            name = "enp4s0";
+            networkConfig = {
+              DHCP = "yes";
+              DNSOverTLS = "yes";
+              DNSSEC = "yes";
+            };
+            bridge = [
+              "virbr0"
+            ];
+          };
+        };
+
+        netdevs = {
+          "tap0" = {
+            netdevConfig = {
+              Name = "tap0";
+              Kind = "tap";
+            };
+            tapConfig = {
+              User = "${config.users.users.soispha.uid}";
+              Group = "libvirtd";
+            };
+          };
+          "virbr0" = {
+            netdevConfig = {
+              Name = "br0";
+              Kind = "bridge";
+            };
+          };
+        };
+      };
+    }
+    // lib.mkIf cfg.networkManager.enable {
+      networking = {
+        networkmanager = {
+          enable = true;
+          dns = "default";
+          wifi = {
+            powersave = true;
+          };
+        };
+        inherit (cfg) hostName;
+      };
+
+      users.users.soispha.extraGroups = [
+        "networkmanager" # allows to configure networkmanager as this user
+      ];
+    };
+}