infrastructure/modules/nixos/network/networks.nix
2024-02-18 11:45:14 -08:00

50 lines
1.3 KiB
Nix

{
inputs,
config,
lib,
...
}: let
inherit (lib.options) mkOption mkEnableOption;
inherit (lib.modules) mkIf mkMerge mkOptionDefault;
inherit (inputs.self.lib.lib) eui64;
inherit (config) networking services;
networkModule = { config, ... }: {
options = with lib.types; {
mdns = {
enable = mkEnableOption "SLAAC" // {
default = config.matchConfig.Type or null == "ether" && services.resolved.enable;
};
};
slaac = {
enable = mkEnableOption "SLAAC" // {
default = config.matchConfig.Type or null == "ether" && networking.enableIPv6;
};
postfix = mkOption {
type = str;
};
};
};
config = {
slaac.postfix = mkIf (config.matchConfig.MACAddress or null != null) (
mkOptionDefault (eui64 config.matchConfig.MACAddress)
);
networkConfig = mkMerge [
(mkIf config.slaac.enable {
IPv6AcceptRA = true;
})
(mkIf config.mdns.enable {
MulticastDNS = true;
})
];
linkConfig = mkIf config.mdns.enable {
Multicast = true;
};
};
};
in {
options = with lib.types; {
systemd.network.networks = mkOption {
type = attrsOf (submodule networkModule);
};
};
}