Difference between revisions of "Networkd-dispatcher"

From NixOS Wiki
Jump to: navigation, search
(Add warning about the new wiki)
m (rollback unauthorized mass edits)
Tag: Rollback
 
Line 1: Line 1:
{{warning|1=You are reading an article on the deprecated unofficial wiki. For the up to date version of this article, see https://wiki.nixos.org/wiki/Networkd-dispatcher.}}
 
 
 
[https://gitlab.com/craftyguy/networkd-dispatcher 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.
 
[https://gitlab.com/craftyguy/networkd-dispatcher 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.
  

Latest revision as of 11:08, 6 April 2024

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.

Usage

The following example triggers a script every time the networkd state routable or off 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 wlan0 and that the uplink is configured. After that the Tor daemon gets restarted.

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
      fi
      exit 0
    '';
  };
};

Please refer upstream documentation for available states and additional examples.