blob: 81efaf2165f12dada73294ddf2c3a68d5d79f72f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
|
# 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;
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.";
};
};
config = {
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";};
};
};
wan = {
device = "wlp1s0";
interface = "wan";
subnet = "192.168.2";
machines = {self.ip = "192.168.2.1";};
};
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";
};
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";
};
};
};
};
};
networking = {
hostName = "kerberos";
domain = "local";
nameservers = [cfg.networks.lan.machines.livebox.ip];
defaultGateway = with cfg.networks.lan; {
inherit interface;
address = machines.livebox.ip;
};
useDHCP = false;
dhcpcd.enable = false;
interfaces =
lib.concatMapAttrs (_: {
interface,
machines,
...
}: {
"${interface}" = {
useDHCP = false;
ipv4.addresses = lib.optional (machines ? self) {
address = machines.self.ip;
prefixLength = 24;
};
};
})
cfg.networks;
};
};
}
|