mirror of
https://github.com/LnL7/nix-darwin.git
synced 2025-03-13 20:30:02 +00:00
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.
This commit is contained in:
parent
48b888c800
commit
5c18e86a07
1 changed files with 43 additions and 3 deletions
|
@ -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}
|
||||
'';
|
||||
|
||||
};
|
||||
|
|
Loading…
Add table
Reference in a new issue