Created
September 27, 2018 07:59
-
-
Save adrianparvino/35e13bd2c05c959ed91b76b04d9c1610 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
wpaHook.connectHook = '' | |
case "$(${pkgs.wpa_supplicant}/bin/wpa_cli status | grep bssid | cut -d'=' -f2)" in | |
"ae:0d:1b:e7:e9:f9") | |
${pkgs.iproute}/bin/ip addr add 192.168.43.2/24 dev wlp2s0 | |
${pkgs.iproute}/bin/ip route add default via 192.168.43.1 | |
;; | |
*) | |
${pkgs.dhcpcd}/bin/dhcpcd -1 wlp2s0 | |
;; | |
esac | |
''; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ config, pkgs, lib, ... }: | |
with lib; | |
let | |
cfg = config.services.wpaHook; | |
hookScript = pkgs.writeScriptBin "wpaHook" '' | |
#!${pkgs.stdenv.shell} | |
case "$2" in | |
CONNECTED) | |
${cfg.connectHook} | |
;; | |
DISCONNECTED) | |
${cfg.disconnectHook} | |
;; | |
esac | |
''; | |
in | |
{ | |
options = { | |
services.wpaHook.enable = mkOption { | |
type = with types; bool; | |
}; | |
services.wpaHook.connectHook = mkOption { | |
type = with types; lines; | |
default = ""; | |
}; | |
services.wpaHook.disconnectHook = mkOption { | |
type = with types; lines; | |
default = ""; | |
}; | |
}; | |
config = mkIf cfg.enable { | |
assertions = [{ | |
assertion = config.networking.wireless.enable; | |
message = "wpa_suplicant must be enabled to enable wpaHook."; | |
}]; | |
systemd.services.wpaHook = { | |
requires = [ "wpa_supplicant.service" ]; | |
wantedBy = [ "wpa_supplicant.service" ]; | |
path = with pkgs; [ wpa_supplicant ]; | |
script = '' | |
while :; do | |
wpa_cli -a ${hookScript}/bin/wpaHook | |
done | |
''; | |
}; | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment