lol

Merge pull request #12164 from NixOS/revert-12015-wpa_supplicant-service

Revert "Basic Declaritive Network Configuration in wpa_supplicant Service"

+87 -87
+2 -12
nixos/doc/manual/configuration/wireless.xml
··· 18 18 networking.wireless.enable = true; 19 19 </programlisting> 20 20 21 - NixOS lets you specify networks for wpa_supplicant declaratively: 22 - <programlisting> 23 - networking.wireless.networks = { 24 - echelon = { 25 - psk = "abcdefgh"; 26 - }; 27 - "free.wifi" = {}; 28 - } 29 - </programlisting> 30 - 31 - When no networks are set it will default to using a configuration file at 32 - <literal>/etc/wpa_supplicant.conf</literal>. You should edit this file 21 + NixOS currently does not generate wpa_supplicant's 22 + configuration file, <literal>/etc/wpa_supplicant.conf</literal>. You should edit this file 33 23 yourself to define wireless networks, WPA keys and so on (see 34 24 wpa_supplicant.conf(5)). 35 25 </para>
+85 -75
nixos/modules/services/networking/wpa_supplicant.nix
··· 3 3 with lib; 4 4 5 5 let 6 + 6 7 cfg = config.networking.wireless; 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"; 19 - in { 8 + configFile = "/etc/wpa_supplicant.conf"; 9 + 10 + ifaces = 11 + cfg.interfaces ++ 12 + optional (config.networking.WLANInterface != "") config.networking.WLANInterface; 13 + 14 + in 15 + 16 + { 17 + 18 + ###### interface 19 + 20 20 options = { 21 + 22 + networking.WLANInterface = mkOption { 23 + default = ""; 24 + description = "Obsolete. Use <option>networking.wireless.interfaces</option> instead."; 25 + }; 26 + 21 27 networking.wireless = { 22 - enable = mkEnableOption "wpa_supplicant"; 28 + enable = mkOption { 29 + type = types.bool; 30 + default = false; 31 + description = '' 32 + Whether to start <command>wpa_supplicant</command> to scan for 33 + and associate with wireless networks. Note: NixOS currently 34 + does not manage <command>wpa_supplicant</command>'s 35 + configuration file, <filename>${configFile}</filename>. You 36 + should edit this file yourself to define wireless networks, 37 + WPA keys and so on (see 38 + <citerefentry><refentrytitle>wpa_supplicant.conf</refentrytitle> 39 + <manvolnum>5</manvolnum></citerefentry>), or use 40 + networking.wireless.userControlled.* to allow users to add entries 41 + through <command>wpa_cli</command> and <command>wpa_gui</command>. 42 + ''; 43 + }; 23 44 24 45 interfaces = mkOption { 25 46 type = types.listOf types.str; 26 47 default = []; 27 48 example = [ "wlan0" "wlan1" ]; 28 49 description = '' 29 - The interfaces <command>wpa_supplicant</command> will use. If empty, it will 50 + The interfaces <command>wpa_supplicant</command> will use. If empty, it will 30 51 automatically use all wireless interfaces. 31 52 ''; 32 53 }; ··· 37 58 description = "Force a specific wpa_supplicant driver."; 38 59 }; 39 60 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 - 68 61 userControlled = { 69 62 enable = mkOption { 70 63 type = types.bool; ··· 75 68 to depend on a large package such as NetworkManager just to pick nearby 76 69 access points. 77 70 78 - When using a declarative network specification you cannot persist any 79 - settings via wpa_gui or wpa_cli. 71 + When you want to use this, make sure ${configFile} doesn't exist. 72 + It will be created for you. 73 + 74 + Currently it is also necessary to explicitly specify networking.wireless.interfaces. 80 75 ''; 81 76 }; 82 77 ··· 90 85 }; 91 86 }; 92 87 93 - config = mkMerge [ 94 - (mkIf cfg.enable { 95 - environment.systemPackages = [ pkgs.wpa_supplicant ]; 96 88 97 - services.dbus.packages = [ pkgs.wpa_supplicant ]; 89 + ###### implementation 90 + 91 + config = mkIf cfg.enable { 92 + 93 + environment.systemPackages = [ pkgs.wpa_supplicant ]; 98 94 99 - # FIXME: start a separate wpa_supplicant instance per interface. 100 - systemd.services.wpa_supplicant = let 101 - ifaces = cfg.interfaces; 102 - in { 103 - description = "WPA Supplicant"; 95 + services.dbus.packages = [ pkgs.wpa_supplicant ]; 96 + 97 + # FIXME: start a separate wpa_supplicant instance per interface. 98 + jobs.wpa_supplicant = 99 + { description = "WPA Supplicant"; 104 100 105 101 wantedBy = [ "network.target" ]; 106 102 107 103 path = [ pkgs.wpa_supplicant ]; 108 104 109 - script = '' 110 - ${if ifaces == [] then '' 111 - for i in $(cd /sys/class/net && echo *); do 112 - DEVTYPE= 113 - source /sys/class/net/$i/uevent 114 - if [ "$DEVTYPE" = "wlan" -o -e /sys/class/net/$i/wireless ]; then 115 - ifaces="$ifaces''${ifaces:+ -N} -i$i" 116 - fi 117 - done 118 - '' else '' 119 - ifaces="${concatStringsSep " -N " (map (i: "-i${i}") ifaces)}" 120 - ''} 121 - exec wpa_supplicant -s -u -D${cfg.driver} -c ${configFile} $ifaces 105 + preStart = '' 106 + touch -a ${configFile} 107 + chmod 600 ${configFile} 108 + '' + optionalString cfg.userControlled.enable '' 109 + if [ ! -s ${configFile} ]; then 110 + echo "ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=${cfg.userControlled.group}" >> ${configFile} 111 + echo "update_config=1" >> ${configFile} 112 + fi 122 113 ''; 114 + 115 + script = 116 + '' 117 + ${if ifaces == [] then '' 118 + for i in $(cd /sys/class/net && echo *); do 119 + DEVTYPE= 120 + source /sys/class/net/$i/uevent 121 + if [ "$DEVTYPE" = "wlan" -o -e /sys/class/net/$i/wireless ]; then 122 + ifaces="$ifaces''${ifaces:+ -N} -i$i" 123 + fi 124 + done 125 + '' else '' 126 + ifaces="${concatStringsSep " -N " (map (i: "-i${i}") ifaces)}" 127 + ''} 128 + exec wpa_supplicant -s -u -D${cfg.driver} -c ${configFile} $ifaces 129 + ''; 123 130 }; 124 131 125 - powerManagement.resumeCommands = '' 132 + powerManagement.resumeCommands = 133 + '' 126 134 ${config.systemd.package}/bin/systemctl try-restart wpa_supplicant 127 135 ''; 128 136 129 - # Restart wpa_supplicant when a wlan device appears or disappears. 130 - services.udev.extraRules = '' 137 + assertions = [{ assertion = !cfg.userControlled.enable || cfg.interfaces != []; 138 + message = "user controlled wpa_supplicant needs explicit networking.wireless.interfaces";}]; 139 + 140 + # Restart wpa_supplicant when a wlan device appears or disappears. 141 + services.udev.extraRules = 142 + '' 131 143 ACTION=="add|remove", SUBSYSTEM=="net", ENV{DEVTYPE}=="wlan", RUN+="${config.systemd.package}/bin/systemctl try-restart wpa_supplicant.service" 132 144 ''; 133 - }) 134 - { 135 - meta.maintainers = with lib.maintainers; [ globin ]; 136 - } 137 - ]; 145 + 146 + }; 147 + 138 148 }