simplify dhcp config

This commit is contained in:
Vivian 2022-12-26 15:27:09 +01:00
parent 424d48bdb1
commit ba141a633d

View file

@ -1,19 +1,16 @@
{ config, pkgs, hosts, ... }: { config, pkgs, flat_hosts, ... }:
let let
inherit (builtins) filter hasAttr; inherit (builtins) filter hasAttr;
inherit (pkgs.lib.attrsets) mapAttrsToList;
hostToDhcp = { hostname, mac, ip, ... }: { hostToDhcp = { hostname, mac, ip, ... }: {
ethernetAddress = mac; ethernetAddress = mac;
hostName = hostname; hostName = hostname;
ipAddress = ip; ipAddress = ip;
}; };
localDomain = config.networking.domain; localDomain = config.networking.domain;
# TODO: Alternatively filter on flat_hosts where realm == localDomain hosts =
local_hosts = mapAttrsToList (name: value: value // { hostname = name; }) hosts.${localDomain}; filter (h: hasAttr "ip" h && hasAttr "mac" h && h.realm == localDomain)
hosts' = filter (h: hasAttr "ip" h && hasAttr "mac" h) local_hosts; flat_hosts;
in { in {
imports = [ ];
networking = { networking = {
defaultGateway = "10.42.42.1"; defaultGateway = "10.42.42.1";
nameservers = [ "10.42.42.15" "10.42.42.16" ]; nameservers = [ "10.42.42.15" "10.42.42.16" ];
@ -52,6 +49,6 @@ in {
range 10.42.43.1 10.42.43.254; range 10.42.43.1 10.42.43.254;
} }
''; '';
machines = map hostToDhcp hosts'; machines = map hostToDhcp hosts;
}; };
} }