lol

Merge pull request #39142 from teto/nm_dispatchers

[RDY] networkmanager: enrich dispatcher PATH

authored by

Samuel Dionne-Riel and committed by
GitHub
ca47cc90 4a8a80d9

+27 -2
+27 -2
nixos/modules/services/networking/networkmanager.nix
··· 289 source = mkOption { 290 type = types.path; 291 description = '' 292 - A script. 293 ''; 294 }; 295 ··· 297 type = types.enum (attrNames dispatcherTypesSubdirMap); 298 default = "basic"; 299 description = '' 300 - Dispatcher hook type. Only basic hooks are currently available. 301 ''; 302 }; 303 }; 304 }); 305 default = []; 306 description = '' 307 A list of scripts which will be executed in response to network events. 308 ''; ··· 418 ++ lib.imap1 (i: s: { 419 inherit (s) source; 420 target = "NetworkManager/dispatcher.d/${dispatcherTypesSubdirMap.${s.type}}03userscript${lib.fixedWidthNumber 4 i}"; 421 }) cfg.dispatcherScripts 422 ++ optional (dynamicHostsEnabled) 423 { target = "NetworkManager/dnsmasq.d/dyndns.conf"; ··· 473 Type = "oneshot"; 474 RemainAfterExist = true; 475 }; 476 }; 477 478 # Turn off NixOS' network management
··· 289 source = mkOption { 290 type = types.path; 291 description = '' 292 + Path to the hook script. 293 ''; 294 }; 295 ··· 297 type = types.enum (attrNames dispatcherTypesSubdirMap); 298 default = "basic"; 299 description = '' 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. 304 ''; 305 }; 306 }; 307 }); 308 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 + } ]''; 322 description = '' 323 A list of scripts which will be executed in response to network events. 324 ''; ··· 434 ++ lib.imap1 (i: s: { 435 inherit (s) source; 436 target = "NetworkManager/dispatcher.d/${dispatcherTypesSubdirMap.${s.type}}03userscript${lib.fixedWidthNumber 4 i}"; 437 + mode = "0544"; 438 }) cfg.dispatcherScripts 439 ++ optional (dynamicHostsEnabled) 440 { target = "NetworkManager/dnsmasq.d/dyndns.conf"; ··· 490 Type = "oneshot"; 491 RemainAfterExist = true; 492 }; 493 + }; 494 + 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 503 # Turn off NixOS' network management