diff options
| author | Daiderd Jordan <daiderd@gmail.com> | 2018-01-08 00:00:11 +0100 |
|---|---|---|
| committer | Daiderd Jordan <daiderd@gmail.com> | 2018-01-08 00:16:46 +0100 |
| commit | 5c18e86a07a2aec40b97829b1c2d2744e657efff (patch) | |
| tree | 9280d9984479259c0cc7d8dce94eb232e6d0115b /modules | |
| parent | 48b888c800448e2dd0577f6d33e0118d8d98301d (diff) | |
networking: add dns/search options
These options are only enabled for networkservices that are explicitly
enabled and will clear existing values if nothing is set.
Diffstat (limited to 'modules')
| -rw-r--r-- | modules/networking/default.nix | 46 |
1 files changed, 43 insertions, 3 deletions
diff --git a/modules/networking/default.nix b/modules/networking/default.nix index e45199e..0cc9a4e 100644 --- a/modules/networking/default.nix +++ b/modules/networking/default.nix @@ -5,11 +5,26 @@ with lib; let cfg = config.networking; - hostName = optionalString (cfg.hostName != null) '' + emptyList = lst: if lst != [] then lst else ["empty"]; + quoteStrings = concatMapStringsSep " " (str: "'${str}'"); + + setHostName = optionalString (cfg.hostName != null) '' scutil --set ComputerName '${cfg.hostName}' scutil --set LocalHostName '${cfg.hostName}' scutil --set HostName '${cfg.hostName}' ''; + + setNetworkServices = optionalString (cfg.networkservices != []) '' + networkservices=$(networksetup -listallnetworkservices) + ${concatMapStringsSep "\n" (srv: '' + case "$networkservices" in + *'${srv}'*) + networksetup -setdnsservers '${srv}' ${quoteStrings (emptyList cfg.dns)} + networksetup -setsearchdomains '${srv}' ${quoteStrings (emptyList cfg.search)} + ;; + esac + '') cfg.networkservices} + ''; in { @@ -20,6 +35,31 @@ in example = "myhostname"; description = "Hostname for your machine."; }; + + networking.networkservices = mkOption { + type = types.listOf types.str; + default = []; + example = [ "Wi-Fi" "Ethernet Adaptor" "Thunderbolt Ethernet" ]; + description = '' + List of networkservices that should be configured. + + To display a list of all the network services on the server's + hardware ports, use <command>networksetup -listallnetworkservices</command>. + ''; + }; + + networking.dns = mkOption { + type = types.listOf types.str; + default = []; + example = [ "8.8.8.8" "8.8.4.4" "2001:4860:4860::8888" "2001:4860:4860::8844" ]; + description = "The list of dns servers used when resolving domain names."; + }; + + networking.search = mkOption { + type = types.listOf types.str; + default = []; + description = "The list of search paths used when resolving domain names."; + }; }; config = { @@ -27,10 +67,10 @@ in system.defaults.smb.NetBIOSName = cfg.hostName; system.activationScripts.networking.text = '' - # Set defaults echo "configuring networking..." >&2 - ${hostName} + ${setHostName} + ${setNetworkServices} ''; }; |
