mirror of
https://github.com/LnL7/nix-darwin.git
synced 2024-12-14 11:57:34 +00:00
networking: use lib.escapeShellArgs
instead of custom version
This commit is contained in:
parent
7bb6366f40
commit
7a3ec6459c
2 changed files with 9 additions and 10 deletions
|
@ -1,4 +1,4 @@
|
||||||
{ config, lib, pkgs, ... }:
|
{ config, lib, ... }:
|
||||||
|
|
||||||
with lib;
|
with lib;
|
||||||
|
|
||||||
|
@ -8,15 +8,14 @@ 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])$'';
|
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"];
|
emptyList = lst: if lst != [] then lst else ["empty"];
|
||||||
quoteStrings = concatMapStringsSep " " (str: "'${str}'");
|
|
||||||
|
|
||||||
setNetworkServices = optionalString (cfg.knownNetworkServices != []) ''
|
setNetworkServices = optionalString (cfg.knownNetworkServices != []) ''
|
||||||
networkservices=$(networksetup -listallnetworkservices)
|
networkservices=$(networksetup -listallnetworkservices)
|
||||||
${concatMapStringsSep "\n" (srv: ''
|
${concatMapStringsSep "\n" (srv: ''
|
||||||
case "$networkservices" in
|
case "$networkservices" in
|
||||||
*'${srv}'*)
|
*${lib.escapeShellArg srv}*)
|
||||||
networksetup -setdnsservers '${srv}' ${quoteStrings (emptyList cfg.dns)}
|
networksetup -setdnsservers ${lib.escapeShellArgs ([ srv ] ++ (emptyList cfg.dns))}
|
||||||
networksetup -setsearchdomains '${srv}' ${quoteStrings (emptyList cfg.search)}
|
networksetup -setsearchdomains ${lib.escapeShellArgs ([ srv ] ++ (emptyList cfg.search))}
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
'') cfg.knownNetworkServices}
|
'') cfg.knownNetworkServices}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
{ config, pkgs, ... }:
|
{ config, lib, ... }:
|
||||||
|
|
||||||
{
|
{
|
||||||
networking.knownNetworkServices = [ "Wi-Fi" "Thunderbolt Ethernet" ];
|
networking.knownNetworkServices = [ "Wi-Fi" "Thunderbolt Ethernet" ];
|
||||||
|
@ -6,10 +6,10 @@
|
||||||
|
|
||||||
test = ''
|
test = ''
|
||||||
echo checking dns settings in /activate >&2
|
echo checking dns settings in /activate >&2
|
||||||
grep "networksetup -setdnsservers 'Wi-Fi' '8.8.8.8' '8.8.4.4'" ${config.out}/activate
|
grep "networksetup -setdnsservers ${lib.escapeShellArgs [ "Wi-Fi" "8.8.8.8" "8.8.4.4" ]}" ${config.out}/activate
|
||||||
grep "networksetup -setdnsservers 'Thunderbolt Ethernet' '8.8.8.8' '8.8.4.4'" ${config.out}/activate
|
grep "networksetup -setdnsservers ${lib.escapeShellArgs [ "Thunderbolt Ethernet" "8.8.8.8" "8.8.4.4" ]}" ${config.out}/activate
|
||||||
echo checking empty searchdomain settings in /activate >&2
|
echo checking empty searchdomain settings in /activate >&2
|
||||||
grep "networksetup -setsearchdomains 'Wi-Fi' 'empty'" ${config.out}/activate
|
grep "networksetup -setsearchdomains ${lib.escapeShellArgs [ "Wi-Fi" "empty" ]}" ${config.out}/activate
|
||||||
grep "networksetup -setsearchdomains 'Thunderbolt Ethernet' 'empty'" ${config.out}/activate
|
grep "networksetup -setsearchdomains ${lib.escapeShellArgs [ "Thunderbolt Ethernet" "empty" ]}" ${config.out}/activate
|
||||||
'';
|
'';
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue