7 meta = with lib.maintainers; {
8 maintainers = [ oddlama rnhmjoj ];
11 naughtyPassphrase = ''!,./;'[]\-=<>?:"{}|_+@$%^&*()`~ # ceci n'est pas un commentaire'';
13 runConnectionTest = name: extraConfig: runTest {
14 name = "wpa_supplicant-${name}";
18 # add a virtual wlan interface
19 boot.kernelModules = [ "mac80211_hwsim" ];
21 # wireless access point
30 ssid = "nixos-test-sae";
33 saePasswords = [ { password = naughtyPassphrase; } ];
35 bssid = "02:00:00:00:00:00";
38 ssid = "nixos-test-mixed";
40 mode = "wpa3-sae-transition";
41 saeAddToMacAllow = true;
42 saePasswordsFile = pkgs.writeText "password" naughtyPassphrase;
43 wpaPasswordFile = pkgs.writeText "password" naughtyPassphrase;
45 bssid = "02:00:00:00:00:01";
48 ssid = "nixos-test-wpa2";
51 wpaPassword = naughtyPassphrase;
53 bssid = "02:00:00:00:00:02";
60 networking.wireless = lib.mkMerge [
62 # the override is needed because the wifi is
63 # disabled with mkVMOverride in qemu-vm.nix.
64 enable = lib.mkOverride 0 true;
65 userControlled.enable = true;
66 interfaces = [ "wlan1" ];
67 fallbackToWPA2 = lib.mkDefault true;
70 secretsFile = pkgs.writeText "wpa-secrets" ''
71 psk_nixos_test=${naughtyPassphrase}
79 # save hostapd config file for manual inspection
80 machine.wait_for_unit("hostapd.service")
81 machine.copy_from_vm("/run/hostapd/wlan0.hostapd.conf")
83 with subtest("Daemon can connect to the access point"):
84 machine.wait_for_unit("wpa_supplicant-wlan1.service")
85 machine.wait_until_succeeds(
86 "wpa_cli -i wlan1 status | grep -q wpa_state=COMPLETED"
94 # Test the basic setup:
95 # - automatic interface discovery
97 # - connecting to the daemon
99 name = "wpa_supplicant-basic";
103 # add a virtual wlan interface
104 boot.kernelModules = [ "mac80211_hwsim" ];
107 networking.wireless = {
108 # the override is needed because the wifi is
109 # disabled with mkVMOverride in qemu-vm.nix.
110 enable = lib.mkOverride 0 true;
111 userControlled.enable = true;
112 fallbackToWPA2 = true;
118 authProtocols = [ "WPA-PSK" "SAE" ];
122 authProtocols = [ "SAE" ];
129 with subtest("Daemon is running and accepting connections"):
130 machine.wait_for_unit("wpa_supplicant.service")
131 status = machine.wait_until_succeeds("wpa_cli status")
132 assert "Failed to connect" not in status, \
133 "Failed to connect to the daemon"
135 # get the configuration file
136 cmdline = machine.succeed("cat /proc/$(pgrep wpa)/cmdline").split('\x00')
137 config_file = cmdline[cmdline.index("-c") + 1]
139 with subtest("WPA2 fallbacks have been generated"):
140 assert int(machine.succeed(f"grep -c sae-only {config_file}")) == 1
141 assert int(machine.succeed(f"grep -c mixed-wpa {config_file}")) == 2
143 # save file for manual inspection
144 machine.copy_from_vm(config_file)
148 # Test configuring the daemon imperatively
149 imperative = runTest {
150 name = "wpa_supplicant-imperative";
154 # add a virtual wlan interface
155 boot.kernelModules = [ "mac80211_hwsim" ];
158 networking.wireless = {
159 enable = lib.mkOverride 0 true;
160 userControlled.enable = true;
161 allowAuxiliaryImperativeNetworks = true;
162 interfaces = [ "wlan1" ];
167 with subtest("Daemon is running and accepting connections"):
168 machine.wait_for_unit("wpa_supplicant-wlan1.service")
169 status = machine.wait_until_succeeds("wpa_cli -i wlan1 status")
170 assert "Failed to connect" not in status, \
171 "Failed to connect to the daemon"
173 with subtest("Daemon can be configured imperatively"):
174 machine.succeed("wpa_cli -i wlan1 add_network")
175 machine.succeed("wpa_cli -i wlan1 set_network 0 ssid '\"nixos-test\"'")
176 machine.succeed("wpa_cli -i wlan1 set_network 0 psk '\"reproducibility\"'")
177 machine.succeed("wpa_cli -i wlan1 save_config")
178 machine.succeed("grep -q nixos-test /etc/wpa_supplicant.conf")
182 # Test connecting to a SAE-only hotspot using SAE
183 saeOnly = runConnectionTest "sae-only" {
184 fallbackToWPA2 = false;
185 networks.nixos-test-sae = {
186 pskRaw = "ext:psk_nixos_test";
187 authProtocols = [ "SAE" ];
191 # Test connecting to a mixed SAE/WPA2 hotspot using SAE
192 mixedUsingSae = runConnectionTest "mixed-using-sae" {
193 fallbackToWPA2 = false;
194 networks.nixos-test-mixed = {
195 pskRaw = "ext:psk_nixos_test";
196 authProtocols = [ "SAE" ];
200 # Test connecting to a mixed SAE/WPA2 hotspot using WPA2
201 mixedUsingWpa2 = runConnectionTest "mixed-using-wpa2" {
202 fallbackToWPA2 = true;
203 networks.nixos-test-mixed = {
204 pskRaw = "ext:psk_nixos_test";
205 authProtocols = [ "WPA-PSK-SHA256" ];
209 # Test connecting to a legacy WPA2-only hotspot using WPA2
210 legacy = runConnectionTest "legacy" {
211 fallbackToWPA2 = true;
212 networks.nixos-test-wpa2 = {
213 pskRaw = "ext:psk_nixos_test";
214 authProtocols = [ "WPA-PSK-SHA256" ];