summaryrefslogtreecommitdiff
path: root/config/networking/default.nix
diff options
context:
space:
mode:
authorquentin@aristote.fr <quentin@aristote.fr>2024-09-29 19:56:08 +0200
committerquentin@aristote.fr <quentin@aristote.fr>2024-10-27 19:08:46 +0100
commit491c4bf6b4596b486b12724e9124a854cc7abc26 (patch)
tree3911453e589959da652a1d5f62e5966b05f1643e /config/networking/default.nix
parent072ad00164e98823691e7da1cdd07ac368391c38 (diff)
migrate hostapd config
Diffstat (limited to 'config/networking/default.nix')
-rw-r--r--config/networking/default.nix202
1 files changed, 108 insertions, 94 deletions
diff --git a/config/networking/default.nix b/config/networking/default.nix
index 81efaf2..d1546d2 100644
--- a/config/networking/default.nix
+++ b/config/networking/default.nix
@@ -1,57 +1,16 @@
-# https://skogsbrus.xyz/blog/2022/06/12/router/
-# https://blog.fraggod.net/2017/04/27/wifi-hostapd-configuration-for-80211ac-networks.html
{
config,
lib,
...
}: let
- cfg = config.personal.networking;
+ ifaces = config.personal.networking.interfaces;
in {
imports = [./bridges.nix ./services];
options.personal.networking = {
- networks = lib.mkOption {
- type = with lib.types;
- attrsOf (submodule {
- options = {
- device = lib.mkOption {
- type = with lib.types; nullOr str;
- default = null;
- description = "Name of the network device.";
- example = "wlp1s0";
- };
- interface = lib.mkOption {
- type = lib.types.str;
- description = "Name of the network interface.";
- example = "enp4s0";
- };
- subnet = lib.mkOption {
- type = lib.types.str;
- description = "IPv4 subnet of the network.";
- example = "192.168.1";
- };
- machines = lib.mkOption {
- type = with lib.types;
- attrsOf (submodule {
- options = {
- ip = lib.mkOption {
- type = lib.types.str;
- description = "IP address of this machine.";
- example = "192.168.1.1";
- };
- mac = lib.mkOption {
- type = with lib.types; nullOr str;
- description = "MAC address of this machine.";
- default = null;
- example = "01:23:45:67:89:ab";
- };
- };
- });
- description = "Some machines connected to this network.";
- };
- };
- });
- description = "Networks this device belongs to.";
+ interfaces = lib.mkOption {
+ type = with lib.types; attrsOf anything;
+ description = "Available interfaces.";
};
};
@@ -59,82 +18,137 @@ in {
personal.networking = {
enable = true;
ssh.enable = true;
- networks = {
- lan = let
- device = "enp4s0";
- in {
- inherit device;
- interface = device;
- subnet = "192.168.1";
- machines = {
- livebox = {ip = "192.168.1.1";};
- self = {ip = "192.168.1.2";};
+ interfaces = let
+ devices = {
+ enp2s0.machines.self.mac = "00:0d:b9:5f:58:f0";
+ enp3s0 = {
+ subnet = {
+ prefix = "192.168.4";
+ prefixLength = 24;
+ };
+ machines = {
+ self = {
+ mac = "00:0d:b9:5f:58:f1";
+ ip = "192.168.4.1";
+ };
+ steam-deck = {
+ mac = "10:82:86:22:90:17";
+ ip = "192.168.4.10";
+ };
+ };
+ };
+ enp4s0 = {
+ subnet = {
+ prefix = "192.168.1";
+ prefixLength = 24;
+ };
+ machines = {
+ self = {
+ mac = "00:0d:b9:5f:58:f2";
+ ip = "192.168.1.2";
+ };
+ livebox.ip = "192.168.1.1";
+ };
+ };
+ wlp1s0 = {
+ bridges = ["wan"];
+ machines.self.mac = "04:f0:21:b6:11:fc";
+ };
+ wlp5s0 = {
+ bridges = ["wan"];
+ machines.self.mac = "04:f0:21:b2:61:09";
};
};
- wan = {
- device = "wlp1s0";
- interface = "wan";
- subnet = "192.168.2";
- machines = {self.ip = "192.168.2.1";};
+ wlan = {
+ wlp1s0-iot = {
+ device = "wlp1s0";
+ machines.self.mac = "02:f0:21:b6:11:fc";
+ bridges = ["iot"];
+ };
+ wlp5s0-iot = {
+ device = "wlp5s0";
+ machines.self.mac = "02:f0:21:b2:61:09";
+ bridges = ["iot"];
+ };
+ wlp5s0-guest = {
+ device = "wlp5s0";
+ machines.self.mac = "06:f0:21:b2:61:09";
+ bridges = ["guest"];
+ };
};
- iot = {
- device = "wlp5s0";
- interface = "iot";
- subnet = "192.168.3";
- machines = {
- self.ip = "192.168.3.1";
- sonos-move = {
- ip = "192.168.3.10";
- mac = "54:2a:1b:73:7a:1e";
+ bridges = {
+ wan = {
+ interfaces = ["wlp1s0" "wlp5s0"];
+ subnet = {
+ prefix = "192.168.2";
+ prefixLength = 24;
};
- sonos-play1 = {
- ip = "192.168.3.11";
- mac = "5c:aa:fd:44:b2:6a";
+ machines.self.ip = "192.168.2.1";
+ };
+ iot = {
+ interfaces = ["wlp1s0-iot" "wlp5s0-iot"];
+ subnet = {
+ prefix = "192.168.3";
+ prefixLength = 24;
+ };
+ machines = {
+ self.ip = "192.168.3.1";
+ sonos-move = {
+ ip = "192.168.3.10";
+ mac = "54:2a:1b:73:7a:1e";
+ };
+ sonos-play1 = {
+ ip = "192.168.3.11";
+ mac = "5c:aa:fd:44:b2:6a";
+ };
};
};
- };
- eth0 = {
- device = "enp3s0";
- interface = "enp3s0";
- subnet = "192.168.4";
- machines = {
- self.ip = "192.168.4.1";
- steam-deck = {
- ip = "192.168.4.10";
- mac = "10:82:86:22:90:17";
+ guest = {
+ interfaces = ["wlp5s0-guest"];
+ subnet = {
+ prefix = "192.168.5";
+ prefixLength = 24;
};
+ machines.self.ip = "192.168.5.1";
};
};
+ in {
+ inherit devices wlan bridges;
+ all = devices // wlan // bridges;
};
};
networking = {
hostName = "kerberos";
domain = "local";
- nameservers = [cfg.networks.lan.machines.livebox.ip];
- defaultGateway = with cfg.networks.lan; {
+ nameservers = [
+ # quad9
+ "9.9.9.9"
+ "149.112.112.112"
+ # isp
+ config.networking.defaultGateway.address
+ ];
+ defaultGateway = let
+ interface = "enp4s0";
+ in {
inherit interface;
- address = machines.livebox.ip;
+ address = ifaces.all."${interface}".machines.livebox.ip;
};
useDHCP = false;
dhcpcd.enable = false;
+
interfaces =
- lib.concatMapAttrs (_: {
- interface,
- machines,
- ...
- }: {
+ lib.concatMapAttrs (interface: attrs: {
"${interface}" = {
- useDHCP = false;
- ipv4.addresses = lib.optional (machines ? self) {
- address = machines.self.ip;
+ ipv4.addresses = lib.optional (attrs ? machines.self.ip) {
+ address = attrs.machines.self.ip;
prefixLength = 24;
};
};
})
- cfg.networks;
+ ifaces.all;
};
};
}