diff options
author | Robin Gloster <mail@glob.in> | 2015-12-26 01:12:32 +0000 |
---|---|---|
committer | Robin Gloster <mail@glob.in> | 2016-01-06 03:58:39 +0000 |
commit | 3a5f48844593fc129184d00a1ee32717b42e5e57 (patch) | |
tree | d9c76cb594cc5c3beac771ba928021bcdc8989ce /nixos | |
parent | 7d973a56d0a38b8b0bb7e1e715ca3e3ebcdb2ac3 (diff) | |
download | nixpkgs-3a5f48844593fc129184d00a1ee32717b42e5e57.tar nixpkgs-3a5f48844593fc129184d00a1ee32717b42e5e57.tar.gz nixpkgs-3a5f48844593fc129184d00a1ee32717b42e5e57.tar.bz2 nixpkgs-3a5f48844593fc129184d00a1ee32717b42e5e57.tar.lz nixpkgs-3a5f48844593fc129184d00a1ee32717b42e5e57.tar.xz nixpkgs-3a5f48844593fc129184d00a1ee32717b42e5e57.tar.zst nixpkgs-3a5f48844593fc129184d00a1ee32717b42e5e57.zip |
wpa_supplicant module: refactor
Diffstat (limited to 'nixos')
-rw-r--r-- | nixos/modules/services/networking/wpa_supplicant.nix | 75 |
1 files changed, 32 insertions, 43 deletions
diff --git a/nixos/modules/services/networking/wpa_supplicant.nix b/nixos/modules/services/networking/wpa_supplicant.nix index bef4b2bc0b9..5979ab7fbe3 100644 --- a/nixos/modules/services/networking/wpa_supplicant.nix +++ b/nixos/modules/services/networking/wpa_supplicant.nix @@ -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 }; }; + config = mkMerge [ + (mkIf cfg.enable { + environment.systemPackages = [ pkgs.wpa_supplicant ]; - ###### implementation - - config = mkIf cfg.enable { - - environment.systemPackages = [ pkgs.wpa_supplicant ]; - - services.dbus.packages = [ pkgs.wpa_supplicant ]; + services.dbus.packages = [ pkgs.wpa_supplicant ]; - # FIXME: start a separate wpa_supplicant instance per interface. - jobs.wpa_supplicant = let - ifaces = cfg.interfaces; - in { description = "WPA Supplicant"; + # FIXME: start a separate wpa_supplicant instance per interface. + systemd.services.wpa_supplicant = let + ifaces = cfg.interfaces; + in { + description = "WPA Supplicant"; wantedBy = [ "network.target" ]; @@ -101,37 +94,33 @@ in fi ''; - script = - '' - ${if ifaces == [] then '' - for i in $(cd /sys/class/net && echo *); do - DEVTYPE= - source /sys/class/net/$i/uevent - if [ "$DEVTYPE" = "wlan" -o -e /sys/class/net/$i/wireless ]; then - ifaces="$ifaces''${ifaces:+ -N} -i$i" - fi - done - '' else '' - ifaces="${concatStringsSep " -N " (map (i: "-i${i}") ifaces)}" - ''} - exec wpa_supplicant -s -u -D${cfg.driver} -c ${configFile} $ifaces - ''; + script = '' + ${if ifaces == [] then '' + for i in $(cd /sys/class/net && echo *); do + DEVTYPE= + source /sys/class/net/$i/uevent + if [ "$DEVTYPE" = "wlan" -o -e /sys/class/net/$i/wireless ]; then + ifaces="$ifaces''${ifaces:+ -N} -i$i" + fi + done + '' else '' + ifaces="${concatStringsSep " -N " (map (i: "-i${i}") 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 ''; - 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 = - '' + # 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" ''; - - }; - + }) + { + meta.maintainers = with lib.maintainers; [ globin ]; + } + ]; } |