diff options
| author | Mike Vink <59492084+ivi-vink@users.noreply.github.com> | 2025-01-16 22:22:34 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-01-16 22:22:34 +0100 |
| commit | 8e7bd91f353caacc0bc4105f573eb3e17f09e03a (patch) | |
| tree | c5059edcbebd9644290cad7c653c49a36d593021 /modules/networking/default.nix | |
| parent | 6bd39d420578aacf7c0bab7de3e7027b952115ae (diff) | |
| parent | bd921223ba7cdac346477d7ea5204d6f4736fcc6 (diff) | |
Diffstat (limited to 'modules/networking/default.nix')
| -rw-r--r-- | modules/networking/default.nix | 38 |
1 files changed, 27 insertions, 11 deletions
diff --git a/modules/networking/default.nix b/modules/networking/default.nix index c70b07d..7a81ca1 100644 --- a/modules/networking/default.nix +++ b/modules/networking/default.nix @@ -1,4 +1,4 @@ -{ config, lib, pkgs, ... }: +{ config, lib, ... }: with lib; @@ -8,15 +8,16 @@ let hostnameRegEx = ''^(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\-]*[A-Za-z0-9])$''; emptyList = lst: if lst != [] then lst else ["empty"]; - quoteStrings = concatMapStringsSep " " (str: "'${str}'"); + + onOff = cond: if cond then "on" else "off"; setNetworkServices = optionalString (cfg.knownNetworkServices != []) '' networkservices=$(networksetup -listallnetworkservices) ${concatMapStringsSep "\n" (srv: '' case "$networkservices" in - *'${srv}'*) - networksetup -setdnsservers '${srv}' ${quoteStrings (emptyList cfg.dns)} - networksetup -setsearchdomains '${srv}' ${quoteStrings (emptyList cfg.search)} + *${lib.escapeShellArg srv}*) + networksetup -setdnsservers ${lib.escapeShellArgs ([ srv ] ++ (emptyList cfg.dns))} + networksetup -setsearchdomains ${lib.escapeShellArgs ([ srv ] ++ (emptyList cfg.search))} ;; esac '') cfg.knownNetworkServices} @@ -29,7 +30,7 @@ in type = types.nullOr types.str; default = null; example = "John’s MacBook Pro"; - description = lib.mdDoc '' + description = '' The user-friendly name for the system, set in System Preferences > Sharing > Computer Name. Setting this option is equivalent to running `scutil --set ComputerName`. @@ -42,7 +43,7 @@ in type = types.nullOr (types.strMatching hostnameRegEx); default = null; example = "Johns-MacBook-Pro"; - description = lib.mdDoc '' + description = '' The hostname of your system, as visible from the command line and used by local and remote networks when connecting through SSH and Remote Login. @@ -56,7 +57,7 @@ in type = types.nullOr (types.strMatching hostnameRegEx); default = cfg.hostName; example = "Johns-MacBook-Pro"; - description = lib.mdDoc '' + description = '' The local hostname, or local network name, is displayed beneath the computer's name at the top of the Sharing preferences pane. It identifies your Mac to Bonjour-compatible services. @@ -74,7 +75,7 @@ in type = types.listOf types.str; default = []; example = [ "Wi-Fi" "Ethernet Adaptor" "Thunderbolt Ethernet" ]; - description = lib.mdDoc '' + description = '' List of networkservices that should be configured. To display a list of all the network services on the server's @@ -86,13 +87,23 @@ in type = types.listOf types.str; default = []; example = [ "8.8.8.8" "8.8.4.4" "2001:4860:4860::8888" "2001:4860:4860::8844" ]; - description = lib.mdDoc "The list of dns servers used when resolving domain names."; + description = "The list of dns servers used when resolving domain names."; }; networking.search = mkOption { type = types.listOf types.str; default = []; - description = lib.mdDoc "The list of search paths used when resolving domain names."; + 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. + ''; }; }; @@ -107,6 +118,7 @@ in echo "configuring networking..." >&2 ${optionalString (cfg.computerName != null) '' + # shellcheck disable=SC1112 scutil --set ComputerName ${escapeShellArg cfg.computerName} ''} ${optionalString (cfg.hostName != null) '' @@ -117,6 +129,10 @@ in ''} ${setNetworkServices} + + ${optionalString (cfg.wakeOnLan.enable != null) '' + systemsetup -setWakeOnNetworkAccess '${onOff cfg.wakeOnLan.enable}' &> /dev/null + ''} ''; }; |
