1 { config, lib, pkgs, ... }:
7 cfg = config.services.networkd-dispatcher;
12 services.networkd-dispatcher = {
14 enable = mkEnableOption ''
15 Networkd-dispatcher service for systemd-networkd connection status
16 change. See [upstream instructions](https://gitlab.com/craftyguy/networkd-dispatcher)
22 example = lib.literalExpression ''
24 onState = ["routable" "off"];
26 #!''${pkgs.runtimeShell}
27 if [[ $IFACE == "wlan0" && $AdministrativeState == "configured" ]]; then
28 echo "Restarting Tor ..."
37 Declarative configuration of networkd-dispatcher rules. See
38 [upstream instructions](https://gitlab.com/craftyguy/networkd-dispatcher)
39 for an introduction and example scripts.
41 type = types.attrsOf (types.submodule {
44 type = types.listOf (types.enum [
45 "routable" "dormant" "no-carrier" "off" "carrier" "degraded"
46 "configuring" "configured"
50 List of names of the systemd-networkd operational states which
51 should trigger the script. See <https://www.freedesktop.org/software/systemd/man/networkctl.html>
52 for a description of the specific state type.
58 Shell commands executed on specified operational states.
68 config = mkIf cfg.enable {
71 packages = [ pkgs.networkd-dispatcher ];
72 services.networkd-dispatcher = {
73 wantedBy = [ "multi-user.target" ];
74 # Override existing ExecStart definition
75 serviceConfig.ExecStart = let
76 scriptDir = pkgs.symlinkJoin {
77 name = "networkd-dispatcher-script-dir";
78 paths = lib.mapAttrsToList (name: cfg:
83 destination = "/${state}.d/${name}";
91 "${pkgs.networkd-dispatcher}/bin/networkd-dispatcher -v --script-dir ${scriptDir} $networkd_dispatcher_args"