From eba5f5c1e5a61ef65a970c699b9f93aff87448bf Mon Sep 17 00:00:00 2001 From: rnhmjoj Date: Mon, 7 Jun 2021 15:55:58 +0200 Subject: [PATCH 1/2] Revert "nixos/wireless: make wireless.interfaces mandatory" This reverts commit 030a521adc9510207dd9f06b8d8b552ff7d999f9. --- nixos/doc/manual/release-notes/rl-2105.xml | 9 ------- .../services/networking/wpa_supplicant.nix | 27 ++++++++++++------- 2 files changed, 17 insertions(+), 19 deletions(-) diff --git a/nixos/doc/manual/release-notes/rl-2105.xml b/nixos/doc/manual/release-notes/rl-2105.xml index bdc2386f24c..54abbb6e38e 100644 --- a/nixos/doc/manual/release-notes/rl-2105.xml +++ b/nixos/doc/manual/release-notes/rl-2105.xml @@ -181,15 +181,6 @@ GNOME desktop environment was upgraded to 40, see the release notes for 40.0 and 3.38. The gnome3 attribute set has been renamed to gnome and so have been the NixOS options. - - - Enabling wireless networking now requires specifying at least one network - interface using . - This is to avoid a race condition with the card initialisation (see - issue - #101963 for more information). - - If you are using to assign diff --git a/nixos/modules/services/networking/wpa_supplicant.nix b/nixos/modules/services/networking/wpa_supplicant.nix index d9308b37064..8a0685c3d96 100644 --- a/nixos/modules/services/networking/wpa_supplicant.nix +++ b/nixos/modules/services/networking/wpa_supplicant.nix @@ -40,7 +40,8 @@ in { default = []; example = [ "wlan0" "wlan1" ]; description = '' - The interfaces wpa_supplicant will use. + The interfaces wpa_supplicant will use. If empty, it will + automatically use all wireless interfaces. ''; }; @@ -219,14 +220,7 @@ in { }; config = mkIf cfg.enable { - assertions = [ - { assertion = cfg.interfaces != []; - message = '' - No network interfaces for wpa_supplicant have been configured. - Please, specify at least one using networking.wireless.interfaces. - ''; - } - ] ++ flip mapAttrsToList cfg.networks (name: cfg: { + assertions = flip mapAttrsToList cfg.networks (name: cfg: { assertion = with cfg; count (x: x != null) [ psk pskRaw auth ] <= 1; message = ''options networking.wireless."${name}".{psk,pskRaw,auth} are mutually exclusive''; }); @@ -261,7 +255,20 @@ in { then echo >&2 "<3>/etc/wpa_supplicant.conf present but ignored. Generated ${configFile} is used instead." fi iface_args="-s -u -D${cfg.driver} ${configStr}" - args="${concatMapStringsSep " -N " (i: "-i${i} $iface_args") ifaces}" + ${if ifaces == [] then '' + for i in $(cd /sys/class/net && echo *); do + DEVTYPE= + UEVENT_PATH=/sys/class/net/$i/uevent + if [ -e "$UEVENT_PATH" ]; then + source "$UEVENT_PATH" + if [ "$DEVTYPE" = "wlan" -o -e /sys/class/net/$i/wireless ]; then + args+="''${args:+ -N} -i$i $iface_args" + fi + fi + done + '' else '' + args="${concatMapStringsSep " -N " (i: "-i${i} $iface_args") ifaces}" + ''} exec wpa_supplicant $args ''; }; From be01320a6c39867eac0a20b4dfe04680d3b1ce26 Mon Sep 17 00:00:00 2001 From: rnhmjoj Date: Mon, 7 Jun 2021 16:01:52 +0200 Subject: [PATCH 2/2] nixos/wireless: only warn for no interfaces A hard failure breaks the NixOS installer, which can't possibly know the interface names in advance. --- .../modules/services/networking/wpa_supplicant.nix | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/nixos/modules/services/networking/wpa_supplicant.nix b/nixos/modules/services/networking/wpa_supplicant.nix index 8a0685c3d96..c0a4ce40760 100644 --- a/nixos/modules/services/networking/wpa_supplicant.nix +++ b/nixos/modules/services/networking/wpa_supplicant.nix @@ -42,6 +42,11 @@ in { description = '' The interfaces wpa_supplicant will use. If empty, it will automatically use all wireless interfaces. + + The automatic discovery of interfaces does not work reliably on boot: + it may fail and leave the system without network. When possible, specify + a known interface name. + ''; }; @@ -225,6 +230,14 @@ in { message = ''options networking.wireless."${name}".{psk,pskRaw,auth} are mutually exclusive''; }); + warnings = + optional (cfg.interfaces == [] && config.systemd.services.wpa_supplicant.wantedBy != []) + '' + No network interfaces for wpa_supplicant have been configured: the service + may randomly fail to start at boot. You should specify at least one using the option + networking.wireless.interfaces. + ''; + environment.systemPackages = [ package ]; services.dbus.packages = [ package ];