84 lines
1.9 KiB
Nix
84 lines
1.9 KiB
Nix
# SPDX-FileCopyrightText: 2020-2024 Simon Bruder <simon@sbruder.de>
|
|
#
|
|
# SPDX-License-Identifier: AGPL-3.0-or-later
|
|
|
|
{ lib, ... }:
|
|
let
|
|
vlans = {
|
|
lan = 10;
|
|
guest = 30;
|
|
};
|
|
dhcpVlans = [ "lan" ];
|
|
in
|
|
{
|
|
networking.useDHCP = false;
|
|
|
|
systemd.network = {
|
|
enable = true;
|
|
wait-online.extraArgs = [ "--any" ];
|
|
netdevs =
|
|
let
|
|
vlanNetdevs = (lib.mapAttrs
|
|
(Name: Id: {
|
|
netdevConfig = {
|
|
inherit Name;
|
|
Kind = "vlan";
|
|
};
|
|
vlanConfig = {
|
|
inherit Id;
|
|
};
|
|
})
|
|
vlans);
|
|
bridgeNetdevs = (lib.mapAttrs'
|
|
(name: _: lib.nameValuePair "br-${name}" {
|
|
netdevConfig = {
|
|
Name = "br-${name}";
|
|
Kind = "bridge";
|
|
};
|
|
})
|
|
vlans);
|
|
in
|
|
lib.mkMerge [ vlanNetdevs bridgeNetdevs ];
|
|
networks =
|
|
let
|
|
vlanNetworks = (lib.mapAttrs
|
|
(name: _: {
|
|
inherit name;
|
|
matchConfig = {
|
|
Type = "vlan";
|
|
};
|
|
bridge = lib.singleton "br-${name}";
|
|
})
|
|
vlans);
|
|
bridgeNetworks = (lib.mapAttrs'
|
|
(name: _: lib.nameValuePair "br-${name}"
|
|
({
|
|
name = "br-${name}";
|
|
} // lib.optionalAttrs (lib.elem name dhcpVlans) {
|
|
DHCP = "ipv4";
|
|
networkConfig = {
|
|
IPv6AcceptRA = "yes";
|
|
};
|
|
}))
|
|
vlans);
|
|
in
|
|
lib.mkMerge [
|
|
{
|
|
physical-lan = {
|
|
name = "eno1";
|
|
vlan = [ "lan" "guest" ];
|
|
networkConfig = {
|
|
LinkLocalAddressing = "no";
|
|
LLDP = "no";
|
|
EmitLLDP = "no";
|
|
IPv6AcceptRA = "no";
|
|
IPv6SendRA = "no";
|
|
};
|
|
};
|
|
}
|
|
vlanNetworks
|
|
bridgeNetworks
|
|
];
|
|
};
|
|
}
|