From ba141a633dcb9016fa334849abd81a9913d395d9 Mon Sep 17 00:00:00 2001 From: Victor Date: Mon, 26 Dec 2022 15:27:09 +0100 Subject: [PATCH] simplify dhcp config --- nixos/hosts/olympus/dhcp/configuration.nix | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/nixos/hosts/olympus/dhcp/configuration.nix b/nixos/hosts/olympus/dhcp/configuration.nix index cc36022..90fdb3c 100644 --- a/nixos/hosts/olympus/dhcp/configuration.nix +++ b/nixos/hosts/olympus/dhcp/configuration.nix @@ -1,19 +1,16 @@ -{ config, pkgs, hosts, ... }: +{ config, pkgs, flat_hosts, ... }: let inherit (builtins) filter hasAttr; - inherit (pkgs.lib.attrsets) mapAttrsToList; hostToDhcp = { hostname, mac, ip, ... }: { ethernetAddress = mac; hostName = hostname; ipAddress = ip; }; localDomain = config.networking.domain; - # TODO: Alternatively filter on flat_hosts where realm == localDomain - local_hosts = mapAttrsToList (name: value: value // { hostname = name; }) hosts.${localDomain}; - hosts' = filter (h: hasAttr "ip" h && hasAttr "mac" h) local_hosts; + hosts = + filter (h: hasAttr "ip" h && hasAttr "mac" h && h.realm == localDomain) + flat_hosts; in { - imports = [ ]; - networking = { defaultGateway = "10.42.42.1"; nameservers = [ "10.42.42.15" "10.42.42.16" ]; @@ -52,6 +49,6 @@ in { range 10.42.43.1 10.42.43.254; } ''; - machines = map hostToDhcp hosts'; + machines = map hostToDhcp hosts; }; }