@@ -4,33 +4,29 @@ with lib;
44
55let
66 cfg = config.networking.wireless;
7− configFile = "/etc/wpa_supplicant.conf";
7+ configFile = if cfg.networks != {} then pkgs.writeText "wpa_supplicant.conf" ''
8+ ${optionalString cfg.userControlled.enable ''
9+ ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=${cfg.userControlled.group}
10+ update_config=1''}
11+ ${concatStringsSep "\n" (mapAttrsToList (ssid: networkConfig: ''
12+ network={
13+ ssid="${ssid}"
14+ ${optionalString (networkConfig.psk != null) ''psk="${networkConfig.psk}"''}
15+ ${optionalString (networkConfig.psk == null) ''key_mgmt=NONE''}
16+ }
17+ '') cfg.networks)}
18+ '' else "/etc/wpa_supplicant.conf";
819in {
920 options = {
1021 networking.wireless = {
11− enable = mkOption {
12− type = types.bool;
13− default = false;
14− description = ''
15− Whether to start <command>wpa_supplicant</command> to scan for
16− and associate with wireless networks. Note: NixOS currently
17− does not manage <command>wpa_supplicant</command>'s
18− configuration file, <filename>${configFile}</filename>. You
19− should edit this file yourself to define wireless networks,
20− WPA keys and so on (see
21− <citerefentry><refentrytitle>wpa_supplicant.conf</refentrytitle>
22− <manvolnum>5</manvolnum></citerefentry>), or use
23− networking.wireless.userControlled.* to allow users to add entries
24− through <command>wpa_cli</command> and <command>wpa_gui</command>.
25− '';
26− };
22+ enable = mkEnableOption "wpa_supplicant";
2723
2824 interfaces = mkOption {
2925 type = types.listOf types.str;
3026 default = [];
3127 example = [ "wlan0" "wlan1" ];
3228 description = ''
33− The interfaces <command>wpa_supplicant</command> will use. If empty, it will
29+ The interfaces <command>wpa_supplicant</command> will use. If empty, it will
3430 automatically use all wireless interfaces.
3531 '';
3632 };
@@ -41,6 +37,34 @@ in {
4137 description = "Force a specific wpa_supplicant driver.";
4238 };
4339
40+ networks = mkOption {
41+ type = types.attrsOf (types.submodule {
42+ options = {
43+ psk = mkOption {
44+ type = types.nullOr types.str;
45+ default = null;
46+ description = ''
47+ The network's pre-shared key in plaintext defaulting
48+ to being a network without any authentication.
49+ '';
50+ };
51+ };
52+ });
53+ description = ''
54+ The network definitions to automatically connect to when
55+ <command>wpa_supplicant</command> is running. If this
56+ parameter is left empty wpa_supplicant will use
57+ /etc/wpa_supplicant.conf as the configuration file.
58+ '';
59+ default = {};
60+ example = literalExample ''
61+ echelon = {
62+ psk = "abcdefgh";
63+ };
64+ "free.wifi" = {};
65+ '';
66+ };
67+
4468 userControlled = {
4569 enable = mkOption {
4670 type = types.bool;
@@ -51,10 +75,8 @@ in {
5175 to depend on a large package such as NetworkManager just to pick nearby
5276 access points.
5377
54− When you want to use this, make sure ${configFile} doesn't exist.
55− It will be created for you.
56−
57− Currently it is also necessary to explicitly specify networking.wireless.interfaces.
78+ When using a declarative network specification you cannot persist any
79+ settings via wpa_gui or wpa_cli.
5880 '';
5981 };
6082