2007-12-04 14:53:37 +00:00
|
|
|
{pkgs, config}:
|
2007-03-16 16:41:38 +00:00
|
|
|
|
2007-03-20 11:04:45 +00:00
|
|
|
let
|
|
|
|
|
2007-12-04 14:53:37 +00:00
|
|
|
cfg = config.services.dhcpd;
|
|
|
|
|
2007-03-20 11:04:45 +00:00
|
|
|
stateDir = "/var/lib/dhcp"; # Don't use /var/state/dhcp; not FHS-compliant.
|
|
|
|
|
2008-05-08 13:27:01 +01:00
|
|
|
machines = pkgs.lib.concatMapStrings (machine: ''
|
2007-12-04 14:53:37 +00:00
|
|
|
host ${machine.hostName} {
|
|
|
|
hardware ethernet ${machine.ethernetAddress};
|
|
|
|
fixed-address ${machine.ipAddress};
|
|
|
|
}
|
2008-05-08 13:27:01 +01:00
|
|
|
'') cfg.machines;
|
2007-12-04 14:53:37 +00:00
|
|
|
|
2008-05-08 13:27:01 +01:00
|
|
|
configFile = if cfg.configFile != null then cfg.configFile else pkgs.writeText "dhcpd.conf" ''
|
2007-12-04 14:53:37 +00:00
|
|
|
default-lease-time 600;
|
|
|
|
max-lease-time 7200;
|
|
|
|
authoritative;
|
|
|
|
ddns-update-style ad-hoc;
|
2008-05-08 13:27:01 +01:00
|
|
|
log-facility local1; # see dhcpd.nix
|
2007-12-04 14:53:37 +00:00
|
|
|
${cfg.extraConfig}
|
|
|
|
${machines}
|
2008-05-08 13:27:01 +01:00
|
|
|
'';
|
2007-12-04 14:53:37 +00:00
|
|
|
|
2007-03-20 11:04:45 +00:00
|
|
|
in
|
|
|
|
|
2007-03-16 16:41:38 +00:00
|
|
|
{
|
|
|
|
name = "dhcpd";
|
|
|
|
|
2008-05-08 13:27:01 +01:00
|
|
|
job = ''
|
|
|
|
description "DHCP server"
|
2007-03-16 16:41:38 +00:00
|
|
|
|
2008-05-08 13:27:01 +01:00
|
|
|
start on network-interfaces/started
|
|
|
|
stop on network-interfaces/stop
|
2007-03-16 16:41:38 +00:00
|
|
|
|
2008-05-08 13:27:01 +01:00
|
|
|
script
|
2007-03-20 12:34:52 +00:00
|
|
|
|
2008-05-08 13:27:01 +01:00
|
|
|
mkdir -m 755 -p ${stateDir}
|
2007-03-20 12:34:52 +00:00
|
|
|
|
2008-05-08 13:27:01 +01:00
|
|
|
touch ${stateDir}/dhcpd.leases
|
2007-03-20 12:34:52 +00:00
|
|
|
|
2008-05-08 13:27:01 +01:00
|
|
|
exec ${pkgs.dhcp}/sbin/dhcpd -f -cf ${configFile} \
|
|
|
|
-lf ${stateDir}/dhcpd.leases \
|
|
|
|
${toString cfg.interfaces}
|
2007-03-20 12:34:52 +00:00
|
|
|
|
2008-05-08 13:27:01 +01:00
|
|
|
end script
|
|
|
|
'';
|
2007-03-16 16:41:38 +00:00
|
|
|
|
|
|
|
}
|