diff --git a/modules/networking/default.nix b/modules/networking/default.nix index 099c705e..b53a9e4a 100644 --- a/modules/networking/default.nix +++ b/modules/networking/default.nix @@ -9,6 +9,8 @@ let emptyList = lst: if lst != [] then lst else ["empty"]; + onOff = cond: if cond then "on" else "off"; + setNetworkServices = optionalString (cfg.knownNetworkServices != []) '' networkservices=$(networksetup -listallnetworkservices) ${concatMapStringsSep "\n" (srv: '' @@ -93,6 +95,16 @@ in default = []; description = "The list of search paths used when resolving domain names."; }; + + networking.wakeOnLan.enable = mkOption { + type = types.nullOr types.bool; + default = null; + description = '' + Enable Wake-on-LAN for the device. + + Battery powered devices may require being connected to power. + ''; + }; }; config = { @@ -116,6 +128,10 @@ in ''} ${setNetworkServices} + + ${optionalString (cfg.wakeOnLan.enable != null) '' + systemsetup -setWakeOnNetworkAccess '${onOff cfg.wakeOnLan.enable}' &> /dev/null + ''} ''; }; diff --git a/tests/networking-wakeonlan.nix b/tests/networking-wakeonlan.nix new file mode 100644 index 00000000..745c39c9 --- /dev/null +++ b/tests/networking-wakeonlan.nix @@ -0,0 +1,10 @@ +{ config, pkgs, ... }: + +{ + networking.wakeOnLan.enable = true; + + test = '' + echo checking wake on network access settings in /activate >&2 + grep "systemsetup -setWakeOnNetworkAccess 'on'" ${config.out}/activate + ''; +}