summaryrefslogtreecommitdiff
path: root/config/networking/services/ifplugd.nix
diff options
context:
space:
mode:
authorquentin@aristote.fr <quentin@aristote.fr>2024-07-17 08:55:39 +0200
committerquentin@aristote.fr <quentin@aristote.fr>2024-07-17 09:50:25 +0200
commitee2c718c9728d8aed9a014a57223fbd5ba8df5e9 (patch)
tree011cf5f97f9595f898084dc7e662c33f71ac94dd /config/networking/services/ifplugd.nix
parent607f2bd9f6422d5a448471a9bfc899eacabff1a6 (diff)
networking: replace dummy interface hack with ifplugd service
Diffstat (limited to 'config/networking/services/ifplugd.nix')
-rw-r--r--config/networking/services/ifplugd.nix37
1 files changed, 37 insertions, 0 deletions
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];
+ };
+}