wpa_supplicant module: refactor

This commit is contained in:
Robin Gloster 2015-12-26 01:12:32 +00:00
parent 7d973a56d0
commit 3a5f488445

View File

@ -5,12 +5,7 @@ with lib;
let let
cfg = config.networking.wireless; cfg = config.networking.wireless;
configFile = "/etc/wpa_supplicant.conf"; configFile = "/etc/wpa_supplicant.conf";
in in {
{
###### interface
options = { options = {
networking.wireless = { networking.wireless = {
enable = mkOption { enable = mkOption {
@ -73,19 +68,17 @@ in
}; };
}; };
config = mkMerge [
(mkIf cfg.enable {
environment.systemPackages = [ pkgs.wpa_supplicant ];
###### implementation services.dbus.packages = [ pkgs.wpa_supplicant ];
config = mkIf cfg.enable { # FIXME: start a separate wpa_supplicant instance per interface.
systemd.services.wpa_supplicant = let
environment.systemPackages = [ pkgs.wpa_supplicant ]; ifaces = cfg.interfaces;
in {
services.dbus.packages = [ pkgs.wpa_supplicant ]; description = "WPA Supplicant";
# FIXME: start a separate wpa_supplicant instance per interface.
jobs.wpa_supplicant = let
ifaces = cfg.interfaces;
in { description = "WPA Supplicant";
wantedBy = [ "network.target" ]; wantedBy = [ "network.target" ];
@ -101,37 +94,33 @@ in
fi fi
''; '';
script = script = ''
'' ${if ifaces == [] then ''
${if ifaces == [] then '' for i in $(cd /sys/class/net && echo *); do
for i in $(cd /sys/class/net && echo *); do DEVTYPE=
DEVTYPE= source /sys/class/net/$i/uevent
source /sys/class/net/$i/uevent if [ "$DEVTYPE" = "wlan" -o -e /sys/class/net/$i/wireless ]; then
if [ "$DEVTYPE" = "wlan" -o -e /sys/class/net/$i/wireless ]; then ifaces="$ifaces''${ifaces:+ -N} -i$i"
ifaces="$ifaces''${ifaces:+ -N} -i$i" fi
fi done
done '' else ''
'' else '' ifaces="${concatStringsSep " -N " (map (i: "-i${i}") ifaces)}"
ifaces="${concatStringsSep " -N " (map (i: "-i${i}") ifaces)}" ''}
''} exec wpa_supplicant -s -u -D${cfg.driver} -c ${configFile} $ifaces
exec wpa_supplicant -s -u -D${cfg.driver} -c ${configFile} $ifaces '';
'';
}; };
powerManagement.resumeCommands = powerManagement.resumeCommands = ''
''
${config.systemd.package}/bin/systemctl try-restart wpa_supplicant ${config.systemd.package}/bin/systemctl try-restart wpa_supplicant
''; '';
assertions = [{ assertion = !cfg.userControlled.enable || cfg.interfaces != []; # Restart wpa_supplicant when a wlan device appears or disappears.
message = "user controlled wpa_supplicant needs explicit networking.wireless.interfaces";}]; services.udev.extraRules = ''
# Restart wpa_supplicant when a wlan device appears or disappears.
services.udev.extraRules =
''
ACTION=="add|remove", SUBSYSTEM=="net", ENV{DEVTYPE}=="wlan", RUN+="${config.systemd.package}/bin/systemctl try-restart wpa_supplicant.service" ACTION=="add|remove", SUBSYSTEM=="net", ENV{DEVTYPE}=="wlan", RUN+="${config.systemd.package}/bin/systemctl try-restart wpa_supplicant.service"
''; '';
})
}; {
meta.maintainers = with lib.maintainers; [ globin ];
}
];
} }