From 308f2a22bf4e4d0ef895f5f597b42e05ab4debf3 Mon Sep 17 00:00:00 2001 From: Matt Layher Date: Fri, 24 Jan 2020 10:34:36 -0500 Subject: [PATCH] nixos: refactor vars.hosts, generate CoreDNS host records --- nixos/coredns.nix | 16 +++++++--------- nixos/dhcpd4.nix | 6 +++--- nixos/nftables.nix | 6 +++--- nixos/vars.nix | 9 ++++++--- 4 files changed, 19 insertions(+), 18 deletions(-) diff --git a/nixos/coredns.nix b/nixos/coredns.nix index ddc8f12..bf64527 100644 --- a/nixos/coredns.nix +++ b/nixos/coredns.nix @@ -1,4 +1,4 @@ -{ config, ... }: +{ config, lib, ... }: let vars = import ./vars.nix; @@ -58,14 +58,12 @@ in { ${lan0.ipv4} routnerr-2.${domain} ${lan0.ipv6.ula} routnerr-2.${domain} - ${vars.hosts.monitnerr-1.ipv4} monitnerr-1.${domain} - ${vars.hosts.monitnerr-1.ipv6.ula} monitnerr-1.${domain} - - ${vars.hosts.nerr-3.ipv4} nerr-3.${domain} - ${vars.hosts.nerr-3.ipv6.ula} nerr-3.${domain} - - ${vars.hosts.servnerr-3.ipv4} servnerr-3.${domain} - ${vars.hosts.servnerr-3.ipv6.ula} servnerr-3.${domain} + ${ + lib.concatMapStrings (host: '' + ${host.ipv4} ${host.name}.${domain} + ${host.ipv6.ula} ${host.name}.${domain} + '') [ vars.hosts.desktop vars.hosts.monitor vars.hosts.server ] + } 192.168.1.2 switch-livingroom01.${domain} 192.168.1.3 switch-office01.${domain} diff --git a/nixos/dhcpd4.nix b/nixos/dhcpd4.nix index 1de8645..c613d32 100644 --- a/nixos/dhcpd4.nix +++ b/nixos/dhcpd4.nix @@ -17,17 +17,17 @@ in { { hostName = "monitnerr-1"; ethernetAddress = "dc:a6:32:1e:66:94"; - ipAddress = "${vars.hosts.monitnerr-1.ipv4}"; + ipAddress = "${vars.hosts.monitor.ipv4}"; } { hostName = "nerr-3"; ethernetAddress = "04:d9:f5:7e:1c:47"; - ipAddress = "${vars.hosts.nerr-3.ipv4}"; + ipAddress = "${vars.hosts.desktop.ipv4}"; } { hostName = "servnerr-3"; ethernetAddress = "06:cb:90:4d:a2:59"; - ipAddress = "${vars.hosts.servnerr-3.ipv4}"; + ipAddress = "${vars.hosts.server.ipv4}"; } { hostName = "switch-livingroom01"; diff --git a/nixos/nftables.nix b/nixos/nftables.nix index e63f543..637ac98 100644 --- a/nixos/nftables.nix +++ b/nixos/nftables.nix @@ -10,9 +10,9 @@ let wan0 = vars.interfaces.wan0; wg0 = vars.interfaces.wg0; - desktop = vars.hosts.nerr-3; - monitor = vars.hosts.monitnerr-1; - server = vars.hosts.servnerr-3; + desktop = vars.hosts.desktop; + monitor = vars.hosts.monitor; + server = vars.hosts.server; ports = { dns = "53"; diff --git a/nixos/vars.nix b/nixos/vars.nix index 744086f..dfe1604 100644 --- a/nixos/vars.nix +++ b/nixos/vars.nix @@ -2,21 +2,24 @@ cfg = "/home/matt/cfg"; domain = "lan.servnerr.com"; hosts = { - monitnerr-1 = { + monitor = { + name = "monitnerr-1"; ipv4 = "192.168.1.11"; ipv6 = { gua = "2600:6c4a:787f:d100:dea6:32ff:fe1e:6694"; ula = "fd9e:1a04:f01d:0:dea6:32ff:fe1e:6694"; }; }; - nerr-3 = { + desktop = { + name = "nerr-3"; ipv4 = "192.168.1.9"; ipv6 = { gua = "2600:6c4a:787f:d100:6d9:f5ff:fe7e:1c47"; ula = "fd9e:1a04:f01d:0:6d9:f5ff:fe7e:1c47"; }; }; - servnerr-3 = { + server = { + name = "servnerr-3"; ipv4 = "192.168.1.4"; ipv6 = { gua = "2600:6c4a:787f:d100:4cb:90ff:fe4d:a259";