Systemd/networkd/dispatcher: Difference between revisions
imported>Onny mNo edit summary |
imported>Onny Update interface to latest PR state |
||
| Line 3: | Line 3: | ||
{{Note|Parts of this instruction and module are not yet stable and will be available in the upcoming NixOS 23.05 release.}} | {{Note|Parts of this instruction and module are not yet stable and will be available in the upcoming NixOS 23.05 release.}} | ||
== | == Usage == | ||
The following example triggers a script every time the networkd state <code>routable</code> or <code>off</code> is reached. This is the case when you connect to a new network or quit an existing connection as with [[OpenVPN]]. An additional check ensures that the affected interface corresponds to <code>wlan0</code> and that the uplink is <code>configured</code>. After that the [[Tor]] daemon gets restarted. | |||
<syntaxhighlight lang="nix"> | <syntaxhighlight lang="nix"> | ||
services.networkd-dispatcher | services.networkd-dispatcher = { | ||
enable = true; | |||
rules."restart-tor" = { | |||
onState = ["routable" "off"]; | |||
script = '' | |||
#!${pkgs.runtimeShell} | |||
if [[ $IFACE == "wlan0" && $AdministrativeState == "configured" ]]; then | |||
{ | echo "Restarting Tor ..." | ||
systemctl restart tor | |||
if [[ $IFACE == "wlan0" && $AdministrativeState == "configured" ]]; then | fi | ||
exit 0 | |||
fi | ''; | ||
exit 0 | }; | ||
}; | |||
</syntaxhighlight> | </syntaxhighlight> | ||