From 356ff794001f422412a1c464940273abcf85a406 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Sun, 4 Mar 2012 17:21:14 +0000 Subject: [PATCH] * wpa_supplicant: automatically figure out the wireless interface(s) on which to run wpa_supplicant, unless they're set explicitly. svn path=/nixos/trunk/; revision=32777 --- modules/rename.nix | 1 + .../services/networking/wpa_supplicant.nix | 36 +++++++++++++++---- 2 files changed, 30 insertions(+), 7 deletions(-) diff --git a/modules/rename.nix b/modules/rename.nix index b92e4e06da5..7f6fd6383a0 100644 --- a/modules/rename.nix +++ b/modules/rename.nix @@ -68,6 +68,7 @@ in zipModules ([] ++ rename obsolete "environment.extraPackages" "environment.systemPackages" ++ rename obsolete "security.extraSetuidPrograms" "security.setuidPrograms" +++ rename obsolete "networking.enableWLAN" "networking.wireless.enable" # Old Grub-related options. ++ rename obsolete "boot.copyKernels" "boot.loader.grub.copyKernels" diff --git a/modules/services/networking/wpa_supplicant.nix b/modules/services/networking/wpa_supplicant.nix index bf4cd6ae29a..795a766b836 100644 --- a/modules/services/networking/wpa_supplicant.nix +++ b/modules/services/networking/wpa_supplicant.nix @@ -6,6 +6,10 @@ let configFile = "/etc/wpa_supplicant.conf"; + ifaces = + config.networking.wireless.interfaces ++ + optional (config.networking.WLANInterface != "") config.networking.WLANInterface; + in { @@ -14,7 +18,7 @@ in options = { - networking.enableWLAN = mkOption { + networking.wireless.enable = mkOption { default = false; description = '' Whether to start wpa_supplicant to scan for @@ -29,9 +33,16 @@ in }; networking.WLANInterface = mkOption { - default = "wlan0"; + default = ""; + description = "Obsolete. Use instead."; + }; + + networking.wireless.interfaces = mkOption { + default = []; + example = [ "wlan0" "wlan1" ]; description = '' - The interface wpa_supplicant will use, if enableWLAN is set. + The interfaces wpa_supplicant will use. If empty, it will + automatically use all wireless interfaces. ''; }; @@ -40,7 +51,7 @@ in ###### implementation - config = mkIf config.networking.enableWLAN { + config = mkIf config.networking.wireless.enable { environment.systemPackages = [ pkgs.wpa_supplicant ]; @@ -58,9 +69,20 @@ in chmod 600 ${configFile} ''; - exec = - "wpa_supplicant -s -u -c ${configFile} " - + (optionalString (config.networking.WLANInterface != null) "-i ${config.networking.WLANInterface}"); + script = + '' + ${if ifaces == [] then '' + for i in $(cd /sys/class/net && echo *); do + if [ -e /sys/class/net/$i/wireless ]; then + ifaces="$ifaces''${ifaces:+ -N} -i$i" + fi + done + '' else '' + ifaces="${concatStringsSep " -N " (map (i: "-i${i}") ifaces)}" + ''} + echo "|$ifaces|" + exec wpa_supplicant -s -u -c ${configFile} $ifaces + ''; }; powerManagement.resumeCommands =