git.iko.soy/typeable/nixpkgs
on master help sign in
Merge pull request #39142 from teto/nm_dispatchers

[RDY] networkmanager: enrich dispatcher PATH

commitca47cc90c2d5502afddfb575c01d17aff13373b8 authorSamuel Dionne-Riel <samuel@dionne-riel.com> dateSat 1 Sep 2018, 23:26 (8 years ago) parent4a8a80df0980c4
1 file changed+27−2
nixos/modules/services/networking/networkmanager.nix+27−2
nixos/modules/services/networking/networkmanager.nix+27−2
@@ -289,7 +289,7 @@ in {
289289 source = mkOption {
290290 type = types.path;
291291 description = ''
292− A script.
292+ Path to the hook script.
293293 '';
294294 };
295295
@@ -297,12 +297,28 @@ in {
297297 type = types.enum (attrNames dispatcherTypesSubdirMap);
298298 default = "basic";
299299 description = ''
300− Dispatcher hook type. Only basic hooks are currently available.
300+ Dispatcher hook type. Look up the hooks described at
301+ <link xlink:href="https://developer.gnome.org/NetworkManager/stable/NetworkManager.html">https://developer.gnome.org/NetworkManager/stable/NetworkManager.html</link>
302+ and choose the type depending on the output folder.
303+ You should then filter the event type (e.g., "up"/"down") from within your script.
301304 '';
302305 };
303306 };
304307 });
305308 default = [];
309+ example = literalExample ''
310+ [ {
311+ source = pkgs.writeText "upHook" '''
312+
313+ if [ "$2" != "up" ]; then
314+ logger "exit: event $2 != up"
315+ fi
316+
317+ # coreutils and iproute are in PATH too
318+ logger "Device $DEVICE_IFACE coming up"
319+ ''';
320+ type = "basic";
321+ } ]'';
306322 description = ''
307323 A list of scripts which will be executed in response to network events.
308324 '';
@@ -418,6 +434,7 @@ in {
418434 ++ lib.imap1 (i: s: {
419435 inherit (s) source;
420436 target = "NetworkManager/dispatcher.d/${dispatcherTypesSubdirMap.${s.type}}03userscript${lib.fixedWidthNumber 4 i}";
437+ mode = "0544";
421438 }) cfg.dispatcherScripts
422439 ++ optional (dynamicHostsEnabled)
423440 { target = "NetworkManager/dnsmasq.d/dyndns.conf";
@@ -475,6 +492,14 @@ in {
475492 };
476493 };
477494
495+ systemd.services."NetworkManager-dispatcher" = {
496+ wantedBy = [ "network.target" ];
497+ restartTriggers = [ configFile ];
498+
499+ # useful binaries for user-specified hooks
500+ path = [ pkgs.iproute pkgs.utillinux pkgs.coreutils ];
501+ };
502+
478503 # Turn off NixOS' network management
479504 networking = {
480505 useDHCP = false;