Systemd/networkd/dispatcher
Appearance
Networkd-dispatcher is a dispatcher service for systemd-networkd connection status changes. This daemon is similar to NetworkManager-dispatcher, but is much more limited in the types of events it supports due to the limited nature of systemd-networkd.
Note: Parts of this instruction and module are not yet stable and will be available in the upcoming NixOS 23.05 release.
Installation
Add following line to your system configuration to install and enable Networkd-dispatcher
services.networkd-dispatcher.enable = true;
Configuration
In the following example we're going to create a script which will restart the Tor daemon everytime the interface wlan0
establishes a new successfull connection to a wifi network.
≡︎ /var/lib/networkd-dispatcher/routable.d/00-restart-tor.sh
#!/usr/bin/env bash
if [[ $IFACE == "wlan0" && $AdministrativeState == "configured" ]]; then
systemctl restart tor
fi
exit 0
Adjusting file permissions for the script to work
chmod 755 /var/lib/networkd-dispatcher/routable.d/00-restart-tor
chown root /var/lib/networkd-dispatcher/routable.d/00-restart-tor
Please refer upstream documentation for configuration syntax and additional examples.