diff options
author | Matthieu Coudron <mattator@gmail.com> | 2018-04-26 18:53:19 +0900 |
---|---|---|
committer | Matthieu Coudron <mattator@gmail.com> | 2018-08-07 17:53:56 +0900 |
commit | f0980c40c1353960834302498be8d8d454aaa11f (patch) | |
tree | 8546452c14550d1ca3745d38f5bfd158a04569e1 /nixos/modules/services | |
parent | 66793d9284cbef52f4b126f74fb5480dadb18d96 (diff) | |
download | nixlib-f0980c40c1353960834302498be8d8d454aaa11f.tar nixlib-f0980c40c1353960834302498be8d8d454aaa11f.tar.gz nixlib-f0980c40c1353960834302498be8d8d454aaa11f.tar.bz2 nixlib-f0980c40c1353960834302498be8d8d454aaa11f.tar.lz nixlib-f0980c40c1353960834302498be8d8d454aaa11f.tar.xz nixlib-f0980c40c1353960834302498be8d8d454aaa11f.tar.zst nixlib-f0980c40c1353960834302498be8d8d454aaa11f.zip |
networkmanager: make hooks easier to use
First change is to override the nm-dispatcher systemd service so that it puts coreutils (wc/env/...) and iproute in PATH. Second change is to make sure userscripts have the execute bit.
Diffstat (limited to 'nixos/modules/services')
-rw-r--r-- | nixos/modules/services/networking/networkmanager.nix | 29 |
1 files changed, 27 insertions, 2 deletions
diff --git a/nixos/modules/services/networking/networkmanager.nix b/nixos/modules/services/networking/networkmanager.nix index b0bc1c83d6b7..d5af4648e8f9 100644 --- a/nixos/modules/services/networking/networkmanager.nix +++ b/nixos/modules/services/networking/networkmanager.nix @@ -289,7 +289,7 @@ in { source = mkOption { type = types.path; description = '' - A script. + Path to the hook script. ''; }; @@ -297,12 +297,28 @@ in { type = types.enum (attrNames dispatcherTypesSubdirMap); default = "basic"; description = '' - Dispatcher hook type. Only basic hooks are currently available. + Dispatcher hook type. Look up the hooks described at + <link xlink:href="https://developer.gnome.org/NetworkManager/stable/NetworkManager.html">https://developer.gnome.org/NetworkManager/stable/NetworkManager.html</link> + and choose the type depending on the output folder. + You should then filter the event type (e.g., "up"/"down") from within your script. ''; }; }; }); default = []; + example = literalExample '' + [ { + source = pkgs.writeText "upHook" ''' + + if [ "$2" != "up" ]; then + logger "exit: event $2 != up" + fi + + # coreutils and iproute are in PATH too + logger "Device $DEVICE_IFACE coming up" + '''; + type = "basic"; + } ]''; description = '' A list of scripts which will be executed in response to network events. ''; @@ -418,6 +434,7 @@ in { ++ lib.imap1 (i: s: { inherit (s) source; target = "NetworkManager/dispatcher.d/${dispatcherTypesSubdirMap.${s.type}}03userscript${lib.fixedWidthNumber 4 i}"; + mode = "0544"; }) cfg.dispatcherScripts ++ optional (dynamicHostsEnabled) { target = "NetworkManager/dnsmasq.d/dyndns.conf"; @@ -475,6 +492,14 @@ in { }; }; + systemd.services."NetworkManager-dispatcher" = { + wantedBy = [ "network.target" ]; + restartTriggers = [ configFile ]; + + # useful binaries for user-specified hooks + path = [ pkgs.iproute pkgs.utillinux pkgs.coreutils ]; + }; + # Turn off NixOS' network management networking = { useDHCP = false; |