From ae4a7f9351ae77d24fe72f88ee95cc56554528b4 Mon Sep 17 00:00:00 2001 From: Jakob Gillich Date: Sat, 26 Dec 2015 11:35:56 +0100 Subject: [PATCH] hostapd: rename extraCfg -> extraConfig, added asserts --- nixos/modules/rename.nix | 2 + nixos/modules/services/networking/hostapd.nix | 47 ++++++++++--------- 2 files changed, 26 insertions(+), 23 deletions(-) diff --git a/nixos/modules/rename.nix b/nixos/modules/rename.nix index 28ac1c3e888a..2a3d89e9f6f2 100644 --- a/nixos/modules/rename.nix +++ b/nixos/modules/rename.nix @@ -75,6 +75,8 @@ with lib; # DNSCrypt-proxy (mkRenamedOptionModule [ "services" "dnscrypt-proxy" "port" ] [ "services" "dnscrypt-proxy" "localPort" ]) + (mkRenamedOptionModule [ "services" "hostapd" "extraCfg" ] [ "services" "hostapd" "extraConfig" ]) + # Options that are obsolete and have no replacement. (mkRemovedOptionModule [ "boot" "initrd" "luks" "enable" ]) (mkRemovedOptionModule [ "programs" "bash" "enable" ]) diff --git a/nixos/modules/services/networking/hostapd.nix b/nixos/modules/services/networking/hostapd.nix index 5a6ca139ddad..287964aab072 100644 --- a/nixos/modules/services/networking/hostapd.nix +++ b/nixos/modules/services/networking/hostapd.nix @@ -2,21 +2,17 @@ # TODO: # -# asserts +# asserts # ensure that the nl80211 module is loaded/compiled in the kernel -# hwMode must be a/b/g -# channel must be between 1 and 13 (maybe) # wpa_supplicant and hostapd on the same wireless interface doesn't make any sense -# perhaps an assertion that there is a dhcp server and a dns server on the IP address serviced by the hostapd? with lib; let cfg = config.services.hostapd; - - configFile = pkgs.writeText "hostapd.conf" - '' + + configFile = pkgs.writeText "hostapd.conf" '' interface=${cfg.interface} driver=${cfg.driver} ssid=${cfg.ssid} @@ -37,8 +33,8 @@ let wpa_passphrase=${cfg.wpaPassphrase} '' else ""} - ${cfg.extraCfg} - '' ; + ${cfg.extraConfig} + '' ; in @@ -65,9 +61,9 @@ in interface = mkOption { default = ""; - example = "wlan0"; + example = "wlp2s0"; description = '' - The interfaces hostapd will use. + The interfaces hostapd will use. ''; }; @@ -89,8 +85,7 @@ in }; hwMode = mkOption { - default = "b"; - example = "g"; + default = "g"; type = types.string; description = '' Operation mode. @@ -98,17 +93,16 @@ in ''; }; - channel = mkOption { + channel = mkOption { default = 7; example = 11; type = types.int; - description = - '' + description = '' Channel number (IEEE 802.11) Please note that some drivers do not use this value from hostapd and the channel will need to be configured separately with iwconfig. - ''; + ''; }; group = mkOption { @@ -131,16 +125,15 @@ in default = "my_sekret"; example = "any_64_char_string"; type = types.string; - description = - '' + description = '' WPA-PSK (pre-shared-key) passphrase. Clients will need this passphrase to associate with this access point. Warning: This passphrase will get put into a world-readable file in the Nix store! - ''; + ''; }; - extraCfg = mkOption { + extraConfig = mkOption { default = ""; example = '' auth_algo=0 @@ -158,17 +151,25 @@ in config = mkIf cfg.enable { + assertions = [ + { assertion = (cfg.hwMode == "a" || cfg.hwMode == "b" || cfg.hwMode == "g"); + message = "hwMode must be a/b/g"; + } + { assertion = (cfg.channel >= 1 && cfg.channel <= 13); + message = "channel must be between 1 and 13"; + }]; + environment.systemPackages = [ pkgs.hostapd ]; systemd.services.hostapd = { description = "hostapd wireless AP"; - path = [ pkgs.hostapd ]; + path = [ pkgs.hostapd ]; wantedBy = [ "network.target" ]; after = [ "${cfg.interface}-cfg.service" "nat.service" "bind.service" "dhcpd.service"]; - serviceConfig = + serviceConfig = { ExecStart = "${pkgs.hostapd}/bin/hostapd ${configFile}"; Restart = "always"; };