refactor: static networking

This commit is contained in:
arcnmx 2024-01-18 13:51:13 -08:00
parent 1a4b5ee8b2
commit 91d4895c6f
13 changed files with 155 additions and 16 deletions

View file

@ -1,14 +1,53 @@
{
config,
lib,
pkgs,
...
}:
with lib; {
}: let
inherit (lib.options) mkOption mkEnableOption;
inherit (lib.modules) mkIf mkMerge mkOptionDefault;
inherit (lib.trivial) 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.deploy.system = mkOption {
type = types.unspecified;
type = lib.types.unspecified;
readOnly = true;
};
options.systemd.network.networks = mkOption {
type = with lib.types; attrsOf (submodule networkModule);
};
config = {
deploy.system = config.system.build.toplevel;
};