From ee2c718c9728d8aed9a014a57223fbd5ba8df5e9 Mon Sep 17 00:00:00 2001 From: "quentin@aristote.fr" Date: Wed, 17 Jul 2024 08:55:39 +0200 Subject: networking: replace dummy interface hack with ifplugd service --- config/networking/services/default.nix | 7 ++----- config/networking/services/ifplugd.nix | 37 ++++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 5 deletions(-) create mode 100644 config/networking/services/ifplugd.nix (limited to 'config/networking/services') diff --git a/config/networking/services/default.nix b/config/networking/services/default.nix index 0ec9540..623a1c7 100644 --- a/config/networking/services/default.nix +++ b/config/networking/services/default.nix @@ -1,6 +1,3 @@ -{ ... }: - -{ - imports = - [ ./ap.nix ./dhcp.nix ./dns.nix ./firewall ./igmpproxy.nix ]; +{...}: { + imports = [./ap.nix ./dhcp.nix ./dns.nix ./firewall ./ifplugd.nix ./igmpproxy.nix]; } diff --git a/config/networking/services/ifplugd.nix b/config/networking/services/ifplugd.nix new file mode 100644 index 0000000..4933b97 --- /dev/null +++ b/config/networking/services/ifplugd.nix @@ -0,0 +1,37 @@ +{ + config, + pkgs, + ... +}: let + iface = config.personal.networking.networks.eth0.device; + dhcpService = "kea-dhcp4-server.service"; + action = pkgs.writeShellApplication { + name = "ifplugd-enp3s0.action"; + runtimeInputs = [pkgs.systemd]; + text = '' + INTERFACE="$1" + EVENT="$2" + + if [[ "$INTERFACE" == '${iface}' && "$EVENT" == up ]] + then + echo ${iface} went up, restarting ${dhcpService}... + systemctl restart ${dhcpService} + fi + ''; + }; +in { + systemd.services."ifplugd-${iface}" = { + enable = true; + + description = "Monitor status of interface ${iface}"; + after = ["sys-subsystem-net-devices-${iface}.device" dhcpService]; + wantedBy = [dhcpService]; + + script = '' + # iface no-daemon no-auto no-shutdown delay-up run + ifplugd -i ${iface} -n -a -q -u 5 -r \ + ${action}/bin/ifplugd-enp3s0.action + ''; + path = [pkgs.busybox]; + }; +} -- cgit v1.2.3