Files
nixos/modules/networking/host.nix
JakeHillion 5a6d56fd29
commit-validation / validate-single-commit (pull_request) Successful in 8s
buildbot/nix-eval Build done. (709 warnings)
buildbot/nix-build Build done.
buildbot/nix-effects Build done.
rooster: configure networking from the network registry
rooster's static LAN address, its gateway and its MTU are written out in
its host config, repeating what the network registry holds for it.

Added a host module that configures a host's interface from its own
record in the registry: an address the record marks as static is set on
the interface, with the network's gateway as the default route, and the
record's MTU is applied. A record can now carry an MTU, and each network
it is on says whether its address comes from DHCP or is static. rooster's
record says both, and its host config only names the interface.

Test plan:
- CI
- rooster's and cyclone's toplevel derivations are unchanged
2026-11-20 21:20:40 +00:00

47 lines
1.4 KiB
Nix

{ config, lib, ... }:
# Configures a host's network interface from its record in the network
# registry: the same record its switch port is configured from.
let
cfg = config.custom.networking.host;
inherit (config.custom.network) networks self;
ip = import ./lib.nix { inherit lib; };
static = lib.attrsets.filterAttrs (_: membership: membership.address == "static") self.net;
in
{
options.custom.networking.host = {
enable = lib.mkEnableOption "configuring the host's network interface from the network registry";
interface = lib.mkOption {
type = lib.types.str;
description = "Name of the interface the host's record in the registry describes.";
};
};
config = lib.mkIf cfg.enable {
networking = {
interfaces.${cfg.interface} = {
ipv4.addresses = lib.attrsets.mapAttrsToList
(netName: membership: {
address = membership.ipv4;
prefixLength = ip.prefixLength networks.${netName}.ipv4;
})
static;
mtu = self.mtu;
};
# networkd needs the gateway's interface named. Scripted networking finds
# it from the address, and given a name adds a host route to the gateway.
defaultGateway = lib.mkIf (static != { }) ({
address = networks.${lib.lists.head (lib.attrsets.attrNames static)}.gateway;
} // lib.attrsets.optionalAttrs config.networking.useNetworkd {
interface = cfg.interface;
});
};
};
}