···
cfg = config.services.networkd-dispatcher;
services.networkd-dispatcher = {
···
17
-
scriptDir = mkOption {
19
-
default = "/var/lib/networkd-dispatcher";
20
-
description = mdDoc ''
21
-
This directory is used for keeping various scripts read and run by
22
-
networkd-dispatcher. See [https://gitlab.com/craftyguy/networkd-dispatcher](upstream instructions)
23
-
for directory structure and script usage.
22
+
example = lib.literalExpression ''
24
+
onState = ["routable" "off"];
26
+
#!''${pkgs.runtimeShell}
27
+
if [[ $IFACE == "wlan0" && $AdministrativeState == "configured" ]]; then
28
+
echo "Restarting Tor ..."
29
+
systemctl restart tor
36
+
description = lib.mdDoc ''
37
+
Declarative configuration of networkd-dispatcher rules. See
38
+
[https://gitlab.com/craftyguy/networkd-dispatcher](upstream instructions)
39
+
for an introduction and example scripts.
41
+
type = types.attrsOf (types.submodule {
43
+
onState = mkOption {
44
+
type = types.listOf (types.enum [
45
+
"routable" "dormant" "no-carrier" "off" "carrier" "degraded"
46
+
"configuring" "configured"
49
+
description = lib.mdDoc ''
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.
57
+
description = lib.mdDoc ''
58
+
Shell commands executed on specified operational states.
···
config = mkIf cfg.enable {
packages = [ pkgs.networkd-dispatcher ];
services.networkd-dispatcher = {
wantedBy = [ "multi-user.target" ];
# Override existing ExecStart definition
38
-
serviceConfig.ExecStart = [
75
+
serviceConfig.ExecStart = let
76
+
scriptDir = pkgs.symlinkJoin {
77
+
name = "networkd-dispatcher-script-dir";
78
+
paths = lib.mapAttrsToList (name: cfg:
80
+
pkgs.writeTextFile {
83
+
destination = "/${state}.d/${name}";
40
-
"${pkgs.networkd-dispatcher}/bin/networkd-dispatcher -v --script-dir ${cfg.scriptDir} $networkd_dispatcher_args"
91
+
"${pkgs.networkd-dispatcher}/bin/networkd-dispatcher -v --script-dir ${scriptDir} $networkd_dispatcher_args"
44
-
# Directory structure required according to upstream instructions
45
-
# https://gitlab.com/craftyguy/networkd-dispatcher
47
-
"d '${cfg.scriptDir}' 0750 root root - -"
48
-
"d '${cfg.scriptDir}/routable.d' 0750 root root - -"
49
-
"d '${cfg.scriptDir}/dormant.d' 0750 root root - -"
50
-
"d '${cfg.scriptDir}/no-carrier.d' 0750 root root - -"
51
-
"d '${cfg.scriptDir}/off.d' 0750 root root - -"
52
-
"d '${cfg.scriptDir}/carrier.d' 0750 root root - -"
53
-
"d '${cfg.scriptDir}/degraded.d' 0750 root root - -"
54
-
"d '${cfg.scriptDir}/configuring.d' 0750 root root - -"
55
-
"d '${cfg.scriptDir}/configured.d' 0750 root root - -"