wpa_supplicant module: refactor

This commit is contained in:
Robin Gloster 2015-12-26 01:12:32 +00:00
parent 57210ce1c1
commit 9dceabc95d

@ -5,12 +5,7 @@ with lib;
let
cfg = config.networking.wireless;
configFile = "/etc/wpa_supplicant.conf";
in
{
###### interface
in {
options = {
networking.wireless = {
enable = mkOption {
@ -73,19 +68,17 @@ in
};
};
###### implementation
config = mkIf cfg.enable {
config = mkMerge [
(mkIf cfg.enable {
environment.systemPackages = [ pkgs.wpa_supplicant ];
services.dbus.packages = [ pkgs.wpa_supplicant ];
# FIXME: start a separate wpa_supplicant instance per interface.
jobs.wpa_supplicant = let
systemd.services.wpa_supplicant = let
ifaces = cfg.interfaces;
in { description = "WPA Supplicant";
in {
description = "WPA Supplicant";
wantedBy = [ "network.target" ];
@ -101,8 +94,7 @@ in
fi
'';
script =
''
script = ''
${if ifaces == [] then ''
for i in $(cd /sys/class/net && echo *); do
DEVTYPE=
@ -118,20 +110,17 @@ in
'';
};
powerManagement.resumeCommands =
''
powerManagement.resumeCommands = ''
${config.systemd.package}/bin/systemctl try-restart wpa_supplicant
'';
assertions = [{ assertion = !cfg.userControlled.enable || cfg.interfaces != [];
message = "user controlled wpa_supplicant needs explicit networking.wireless.interfaces";}];
# Restart wpa_supplicant when a wlan device appears or disappears.
services.udev.extraRules =
''
services.udev.extraRules = ''
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 ];
}
];
}