diff options
author | Eelco Dolstra <eelco.dolstra@logicblox.com> | 2009-10-12 16:36:19 +0000 |
---|---|---|
committer | Eelco Dolstra <eelco.dolstra@logicblox.com> | 2009-10-12 16:36:19 +0000 |
commit | e91d882a946fc736f62235296e77c139cee7d9b3 (patch) | |
tree | e220488319f0cc28aafb01ca26809429eeaf7f82 /modules/services/networking/dhcpd.nix | |
parent | 4a78ef25e73da292d060a2afde0c00980a22b2ac (diff) | |
download | nixpkgs-e91d882a946fc736f62235296e77c139cee7d9b3.tar nixpkgs-e91d882a946fc736f62235296e77c139cee7d9b3.tar.gz nixpkgs-e91d882a946fc736f62235296e77c139cee7d9b3.tar.bz2 nixpkgs-e91d882a946fc736f62235296e77c139cee7d9b3.tar.lz nixpkgs-e91d882a946fc736f62235296e77c139cee7d9b3.tar.xz nixpkgs-e91d882a946fc736f62235296e77c139cee7d9b3.tar.zst nixpkgs-e91d882a946fc736f62235296e77c139cee7d9b3.zip |
* Converted modules that were still using the old (concrete syntax)
style of declaring Upstart jobs. While at it, converted them to the current NixOS module style and improved some option descriptions. Hopefully I didn't break too much :-) svn path=/nixos/trunk/; revision=17761
Diffstat (limited to 'modules/services/networking/dhcpd.nix')
-rw-r--r-- | modules/services/networking/dhcpd.nix | 208 |
1 files changed, 103 insertions, 105 deletions
diff --git a/modules/services/networking/dhcpd.nix b/modules/services/networking/dhcpd.nix index 9604dd965b9..5a2d9034dfd 100644 --- a/modules/services/networking/dhcpd.nix +++ b/modules/services/networking/dhcpd.nix @@ -1,123 +1,121 @@ -{pkgs, config, ...}: +{ config, pkgs, ... }: + +with pkgs.lib; -###### 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"; + cfg = config.services.dhcpd; + + stateDir = "/var/lib/dhcp"; # Don't use /var/state/dhcp; not FHS-compliant. + + configFile = if cfg.configFile != null then cfg.configFile else pkgs.writeText "dhcpd.conf" + '' + default-lease-time 600; + max-lease-time 7200; + authoritative; + ddns-update-style ad-hoc; + log-facility local1; # see dhcpd.nix + + ${cfg.extraConfig} + + ${pkgs.lib.concatMapStrings + (machine: '' + host ${machine.hostName} { + hardware ethernet ${machine.ethernetAddress}; + fixed-address ${machine.ipAddress}; } - ]; - description = " - A list mapping ethernet addresses to IP addresses for the - DHCP server. - "; - }; + '') + cfg.machines + } + ''; - }; - }; - }; in + +{ -###### implementation + ###### interface -let + options = { + + services.dhcpd = { - cfg = config.services.dhcpd; + enable = mkOption { + default = false; + description = " + Whether to enable the DHCP server. + "; + }; - stateDir = "/var/lib/dhcp"; # Don't use /var/state/dhcp; not FHS-compliant. + 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. + "; + }; - machines = pkgs.lib.concatMapStrings (machine: '' - host ${machine.hostName} { - hardware ethernet ${machine.ethernetAddress}; - fixed-address ${machine.ipAddress}; - } - '') cfg.machines; - - configFile = if cfg.configFile != null then cfg.configFile else pkgs.writeText "dhcpd.conf" '' - default-lease-time 600; - max-lease-time 7200; - authoritative; - ddns-update-style ad-hoc; - log-facility local1; # see dhcpd.nix - ${cfg.extraConfig} - ${machines} - ''; + 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. + "; + }; -in + 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. + "; + }; + + }; + + }; -mkIf config.services.dhcpd.enable { - require = [ - options - ]; + ###### implementation - services = { - extraJobs = [{ - name = "dhcpd"; - - job = '' - description "DHCP server" + config = mkIf config.services.dhcpd.enable { - start on network-interfaces/started - stop on network-interfaces/stop + jobAttrs.dhcpd = + { description = "DHCP server"; - script + startOn = "network-interfaces/started"; + stopOn = "network-interfaces/stop"; + script = + '' mkdir -m 755 -p ${stateDir} touch ${stateDir}/dhcpd.leases @@ -125,9 +123,9 @@ mkIf config.services.dhcpd.enable { exec ${pkgs.dhcp}/sbin/dhcpd -f -cf ${configFile} \ -lf ${stateDir}/dhcpd.leases \ ${toString cfg.interfaces} + ''; + }; - end script - ''; - }]; }; + } |