dhcp-server.nix: add fixed-hosts

This commit is contained in:
Astro 2021-03-31 02:20:08 +02:00
parent df3ef74862
commit 775b91fb18
3 changed files with 24 additions and 5 deletions

View File

@ -32,7 +32,7 @@ in
(builtins.mapAttrs (_: hosts4: { inherit hosts4; }) pillar.hosts-inet) (builtins.mapAttrs (_: hosts4: { inherit hosts4; }) pillar.hosts-inet)
(builtins.mapAttrs (net: dhcpData: { (builtins.mapAttrs (net: dhcpData: {
dhcp = { dhcp = {
inherit (dhcpData) start end time max-time; inherit (dhcpData) start end time max-time fixed-hosts;
server = server =
if netHasDHCP net if netHasDHCP net
then "${net}-gw" then "${net}-gw"

View File

@ -31,6 +31,10 @@ let
description = "Domain name option"; description = "Domain name option";
type = types.str; type = types.str;
}; };
fixed-hosts = mkOption {
type = with types; attrsOf str;
default = {};
};
}; };
netOpts = { name, ... }: { netOpts = { name, ... }: {
options = { options = {

View File

@ -16,23 +16,38 @@ in
interfaces = builtins.attrNames dhcpNets; interfaces = builtins.attrNames dhcpNets;
extraConfig = '' extraConfig = ''
option domain-name-servers 172.20.73.8, 9.9.9.9;
${builtins.concatStringsSep "\n" ( ${builtins.concatStringsSep "\n" (
builtins.attrValues ( builtins.attrValues (
builtins.mapAttrs (net: { dhcp, subnet4Net, subnet4Len, ...}: builtins.mapAttrs (net: { dhcp, subnet4Net, subnet4Len, ...}:
'' ''
subnet ${subnet4Net} netmask ${lib.netmasks.${toString subnet4Len}} { group {
range ${dhcp.start} ${dhcp.end};
default-lease-time ${toString dhcp.time}; default-lease-time ${toString dhcp.time};
max-lease-time ${toString dhcp.max-time}; max-lease-time ${toString dhcp.max-time};
option routers ${config.site.net.${net}.hosts4.${builtins.replaceStrings [".${net}"] [""] dhcp.router}}; option routers ${config.site.net.${net}.hosts4.${builtins.replaceStrings [".${net}"] [""] dhcp.router}};
option domain-name "${dhcp.domainName}"; option domain-name "${dhcp.domainName}";
option domain-name-servers 172.20.73.8, 9.9.9.9;
subnet ${subnet4Net} netmask ${lib.netmasks.${toString subnet4Len}} {
range ${dhcp.start} ${dhcp.end};
}
${builtins.concatStringsSep "\n" (
builtins.attrValues (
builtins.mapAttrs (addr: hwaddr:
''
host ${addr} {
hardware ethernet ${hwaddr};
fixed-address ${addr};
}
''
) dhcp.fixed-hosts
)
)}
} }
'' ''
) dhcpNets ) dhcpNets
) )
)} )}
''; '';
# TODO: fixed-hosts
}; };
} }