From 4768fd6488cf87f52114299fdddc90321772c42b Mon Sep 17 00:00:00 2001 From: Marc Weber Date: Fri, 6 Mar 2009 12:26:05 +0000 Subject: [PATCH] Convert "dhcpd" daemon svn path=/nixos/branches/fix-style/; revision=14369 --- system/options.nix | 66 +--------------------- upstart-jobs/default.nix | 6 -- upstart-jobs/dhcpd.nix | 117 +++++++++++++++++++++++++++++++++------ 3 files changed, 101 insertions(+), 88 deletions(-) diff --git a/system/options.nix b/system/options.nix index 60c5dd6c3ff..97b53917f24 100644 --- a/system/options.nix +++ b/system/options.nix @@ -480,71 +480,6 @@ in }; - dhcpd = { - - enable = mkOption { - default = false; - description = " - Whether to enable the DHCP server. - "; - }; - - extraConfig = mkOption { - default = ""; - example = " - option subnet-mask 255.255.255.0; - option broadcast-address 192.168.1.255; - option routers 192.168.1.5; - option domain-name-servers 130.161.158.4, 130.161.33.17, 130.161.180.1; - option domain-name \"example.org\"; - subnet 192.168.1.0 netmask 255.255.255.0 { - range 192.168.1.100 192.168.1.200; - } - "; - description = " - Extra text to be appended to the DHCP server configuration - file. Currently, you almost certainly need to specify - something here, such as the options specifying the subnet - mask, DNS servers, etc. - "; - }; - - configFile = mkOption { - default = null; - description = " - The path of the DHCP server configuration file. If no file - is specified, a file is generated using the other options. - "; - }; - - interfaces = mkOption { - default = ["eth0"]; - description = " - The interfaces on which the DHCP server should listen. - "; - }; - - machines = mkOption { - default = []; - example = [ - { hostName = "foo"; - ethernetAddress = "00:16:76:9a:32:1d"; - ipAddress = "192.168.1.10"; - } - { hostName = "bar"; - ethernetAddress = "00:19:d1:1d:c4:9a"; - ipAddress = "192.168.1.11"; - } - ]; - description = " - A list mapping ethernet addresses to IP addresses for the - DHCP server. - "; - }; - - }; - - sshd = { enable = mkOption { @@ -1763,6 +1698,7 @@ in (import ../upstart-jobs/kbd.nix) (import ../upstart-jobs/gw6c.nix) # Gateway6 (import ../upstart-jobs/syslogd.nix) + (import ../upstart-jobs/dhcpd.nix) # nix (import ../upstart-jobs/nix.nix) # nix options and daemon diff --git a/upstart-jobs/default.nix b/upstart-jobs/default.nix index 6dad24c35b3..043e82d1c44 100644 --- a/upstart-jobs/default.nix +++ b/upstart-jobs/default.nix @@ -141,12 +141,6 @@ let inherit config; }) - # DHCP server. - ++ optional config.services.dhcpd.enable - (import ../upstart-jobs/dhcpd.nix { - inherit pkgs config; - }) - # SSH daemon. ++ optional config.services.sshd.enable (import ../upstart-jobs/sshd.nix { diff --git a/upstart-jobs/dhcpd.nix b/upstart-jobs/dhcpd.nix index d1f0a9626d5..9604dd965b9 100644 --- a/upstart-jobs/dhcpd.nix +++ b/upstart-jobs/dhcpd.nix @@ -1,4 +1,79 @@ -{pkgs, config}: +{pkgs, config, ...}: + +###### interface +let + inherit (pkgs.lib) mkOption mkIf; + + options = { + services = { + dhcpd = { + + enable = mkOption { + default = false; + description = " + Whether to enable the DHCP server. + "; + }; + + extraConfig = mkOption { + default = ""; + example = " + option subnet-mask 255.255.255.0; + option broadcast-address 192.168.1.255; + option routers 192.168.1.5; + option domain-name-servers 130.161.158.4, 130.161.33.17, 130.161.180.1; + option domain-name \"example.org\"; + subnet 192.168.1.0 netmask 255.255.255.0 { + range 192.168.1.100 192.168.1.200; + } + "; + description = " + Extra text to be appended to the DHCP server configuration + file. Currently, you almost certainly need to specify + something here, such as the options specifying the subnet + mask, DNS servers, etc. + "; + }; + + configFile = mkOption { + default = null; + description = " + The path of the DHCP server configuration file. If no file + is specified, a file is generated using the other options. + "; + }; + + interfaces = mkOption { + default = ["eth0"]; + description = " + The interfaces on which the DHCP server should listen. + "; + }; + + machines = mkOption { + default = []; + example = [ + { hostName = "foo"; + ethernetAddress = "00:16:76:9a:32:1d"; + ipAddress = "192.168.1.10"; + } + { hostName = "bar"; + ethernetAddress = "00:19:d1:1d:c4:9a"; + ipAddress = "192.168.1.11"; + } + ]; + description = " + A list mapping ethernet addresses to IP addresses for the + DHCP server. + "; + }; + + }; + }; + }; +in + +###### implementation let @@ -25,26 +100,34 @@ let in -{ - name = "dhcpd"; - - job = '' - description "DHCP server" - start on network-interfaces/started - stop on network-interfaces/stop +mkIf config.services.dhcpd.enable { + require = [ + options + ]; - script + services = { + extraJobs = [{ + name = "dhcpd"; + + job = '' + description "DHCP server" - mkdir -m 755 -p ${stateDir} + start on network-interfaces/started + stop on network-interfaces/stop - touch ${stateDir}/dhcpd.leases + script - exec ${pkgs.dhcp}/sbin/dhcpd -f -cf ${configFile} \ - -lf ${stateDir}/dhcpd.leases \ - ${toString cfg.interfaces} + mkdir -m 755 -p ${stateDir} - end script - ''; - + touch ${stateDir}/dhcpd.leases + + exec ${pkgs.dhcp}/sbin/dhcpd -f -cf ${configFile} \ + -lf ${stateDir}/dhcpd.leases \ + ${toString cfg.interfaces} + + end script + ''; + }]; + }; }