2014-04-14 14:26:48 +00:00
|
|
|
{ config, lib, pkgs, ... }:
|
2012-10-06 04:39:56 +00:00
|
|
|
|
|
|
|
# TODO:
|
|
|
|
#
|
2015-12-26 10:35:56 +00:00
|
|
|
# asserts
|
2012-10-06 04:39:56 +00:00
|
|
|
# ensure that the nl80211 module is loaded/compiled in the kernel
|
|
|
|
# wpa_supplicant and hostapd on the same wireless interface doesn't make any sense
|
|
|
|
|
2014-04-14 14:26:48 +00:00
|
|
|
with lib;
|
2012-10-06 04:39:56 +00:00
|
|
|
|
|
|
|
let
|
|
|
|
|
|
|
|
cfg = config.services.hostapd;
|
2015-12-26 10:35:56 +00:00
|
|
|
|
|
|
|
configFile = pkgs.writeText "hostapd.conf" ''
|
2012-10-06 04:39:56 +00:00
|
|
|
interface=${cfg.interface}
|
|
|
|
driver=${cfg.driver}
|
|
|
|
ssid=${cfg.ssid}
|
|
|
|
hw_mode=${cfg.hwMode}
|
|
|
|
channel=${toString cfg.channel}
|
|
|
|
|
|
|
|
# logging (debug level)
|
|
|
|
logger_syslog=-1
|
|
|
|
logger_syslog_level=2
|
|
|
|
logger_stdout=-1
|
|
|
|
logger_stdout_level=2
|
|
|
|
|
|
|
|
ctrl_interface=/var/run/hostapd
|
|
|
|
ctrl_interface_group=${cfg.group}
|
|
|
|
|
|
|
|
${if cfg.wpa then ''
|
|
|
|
wpa=1
|
|
|
|
wpa_passphrase=${cfg.wpaPassphrase}
|
|
|
|
'' else ""}
|
|
|
|
|
2015-12-26 10:35:56 +00:00
|
|
|
${cfg.extraConfig}
|
|
|
|
'' ;
|
2012-10-06 04:39:56 +00:00
|
|
|
|
|
|
|
in
|
|
|
|
|
|
|
|
{
|
|
|
|
###### interface
|
|
|
|
|
|
|
|
options = {
|
|
|
|
|
|
|
|
services.hostapd = {
|
|
|
|
|
|
|
|
enable = mkOption {
|
|
|
|
default = false;
|
|
|
|
description = ''
|
2012-10-09 19:19:09 +00:00
|
|
|
Enable putting a wireless interface into infrastructure mode,
|
2015-12-05 10:54:27 +00:00
|
|
|
allowing other wireless devices to associate with the wireless
|
|
|
|
interface and do wireless networking. A simple access point will
|
|
|
|
<option>enable hostapd.wpa</option>,
|
|
|
|
<option>hostapd.wpaPassphrase</option>, and
|
|
|
|
<option>hostapd.ssid</option>, as well as DHCP on the wireless
|
|
|
|
interface to provide IP addresses to the associated stations, and
|
|
|
|
NAT (from the wireless interface to an upstream interface).
|
2012-10-06 04:39:56 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
interface = mkOption {
|
|
|
|
default = "";
|
2015-12-26 10:35:56 +00:00
|
|
|
example = "wlp2s0";
|
2012-10-06 04:39:56 +00:00
|
|
|
description = ''
|
2015-12-26 10:35:56 +00:00
|
|
|
The interfaces <command>hostapd</command> will use.
|
2012-10-06 04:39:56 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
driver = mkOption {
|
|
|
|
default = "nl80211";
|
|
|
|
example = "hostapd";
|
|
|
|
type = types.string;
|
2015-12-05 10:54:27 +00:00
|
|
|
description = ''
|
|
|
|
Which driver <command>hostapd</command> will use.
|
|
|
|
Most applications will probably use the default.
|
|
|
|
'';
|
2012-10-06 04:39:56 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
ssid = mkOption {
|
|
|
|
default = "nixos";
|
|
|
|
example = "mySpecialSSID";
|
|
|
|
type = types.string;
|
|
|
|
description = "SSID to be used in IEEE 802.11 management frames.";
|
|
|
|
};
|
|
|
|
|
|
|
|
hwMode = mkOption {
|
2015-12-26 10:35:56 +00:00
|
|
|
default = "g";
|
2012-10-06 04:39:56 +00:00
|
|
|
type = types.string;
|
2015-12-05 10:54:27 +00:00
|
|
|
description = ''
|
|
|
|
Operation mode.
|
|
|
|
(a = IEEE 802.11a, b = IEEE 802.11b, g = IEEE 802.11g).
|
|
|
|
'';
|
2012-10-06 04:39:56 +00:00
|
|
|
};
|
|
|
|
|
2015-12-26 10:35:56 +00:00
|
|
|
channel = mkOption {
|
2012-10-06 04:39:56 +00:00
|
|
|
default = 7;
|
|
|
|
example = 11;
|
|
|
|
type = types.int;
|
2015-12-26 10:35:56 +00:00
|
|
|
description = ''
|
2012-10-06 04:39:56 +00:00
|
|
|
Channel number (IEEE 802.11)
|
2015-12-05 10:54:27 +00:00
|
|
|
Please note that some drivers do not use this value from
|
|
|
|
<command>hostapd</command> and the channel will need to be configured
|
|
|
|
separately with <command>iwconfig</command>.
|
2015-12-26 10:35:56 +00:00
|
|
|
'';
|
2012-10-06 04:39:56 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
group = mkOption {
|
|
|
|
default = "wheel";
|
|
|
|
example = "network";
|
|
|
|
type = types.string;
|
2015-12-05 10:54:27 +00:00
|
|
|
description = ''
|
|
|
|
Members of this group can control <command>hostapd</command>.
|
|
|
|
'';
|
2012-10-09 19:19:09 +00:00
|
|
|
};
|
2012-10-06 04:39:56 +00:00
|
|
|
|
|
|
|
wpa = mkOption {
|
|
|
|
default = true;
|
2015-12-05 10:54:27 +00:00
|
|
|
description = ''
|
|
|
|
Enable WPA (IEEE 802.11i/D3.0) to authenticate with the access point.
|
|
|
|
'';
|
2012-10-09 19:19:09 +00:00
|
|
|
};
|
2012-10-06 04:39:56 +00:00
|
|
|
|
|
|
|
wpaPassphrase = mkOption {
|
|
|
|
default = "my_sekret";
|
|
|
|
example = "any_64_char_string";
|
|
|
|
type = types.string;
|
2015-12-26 10:35:56 +00:00
|
|
|
description = ''
|
2012-10-09 19:19:09 +00:00
|
|
|
WPA-PSK (pre-shared-key) passphrase. Clients will need this
|
2015-12-05 10:54:27 +00:00
|
|
|
passphrase to associate with this access point.
|
|
|
|
Warning: This passphrase will get put into a world-readable file in
|
|
|
|
the Nix store!
|
2015-12-26 10:35:56 +00:00
|
|
|
'';
|
2012-10-09 19:19:09 +00:00
|
|
|
};
|
2012-10-06 04:39:56 +00:00
|
|
|
|
2015-12-26 10:35:56 +00:00
|
|
|
extraConfig = mkOption {
|
2012-10-06 04:39:56 +00:00
|
|
|
default = "";
|
|
|
|
example = ''
|
|
|
|
auth_algo=0
|
|
|
|
ieee80211n=1
|
|
|
|
ht_capab=[HT40-][SHORT-GI-40][DSSS_CCK-40]
|
|
|
|
'';
|
|
|
|
type = types.string;
|
2015-12-05 10:54:27 +00:00
|
|
|
description = "Extra configuration options to put in hostapd.conf.";
|
2012-10-06 04:39:56 +00:00
|
|
|
};
|
|
|
|
};
|
2012-10-09 19:19:09 +00:00
|
|
|
};
|
2012-10-06 04:39:56 +00:00
|
|
|
|
|
|
|
|
|
|
|
###### implementation
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
|
|
|
|
2015-12-26 10:35:56 +00:00
|
|
|
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";
|
|
|
|
}];
|
|
|
|
|
2012-10-06 04:39:56 +00:00
|
|
|
environment.systemPackages = [ pkgs.hostapd ];
|
|
|
|
|
2013-02-24 11:11:45 +00:00
|
|
|
systemd.services.hostapd =
|
|
|
|
{ description = "hostapd wireless AP";
|
|
|
|
|
2015-12-26 10:35:56 +00:00
|
|
|
path = [ pkgs.hostapd ];
|
2013-04-13 06:25:32 +00:00
|
|
|
wantedBy = [ "network.target" ];
|
2013-02-24 11:11:45 +00:00
|
|
|
|
|
|
|
after = [ "${cfg.interface}-cfg.service" "nat.service" "bind.service" "dhcpd.service"];
|
|
|
|
|
2015-12-26 10:35:56 +00:00
|
|
|
serviceConfig =
|
2013-02-24 11:11:45 +00:00
|
|
|
{ ExecStart = "${pkgs.hostapd}/bin/hostapd ${configFile}";
|
|
|
|
Restart = "always";
|
|
|
|
};
|
2012-10-06 04:39:56 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|