From 0aad7f1b85b854feea09308d32c046f68eb45e6b Mon Sep 17 00:00:00 2001 From: aszlig Date: Mon, 14 Jul 2014 09:36:10 +0200 Subject: i3/conky: Auto-detect primary ethernet interface. This is done by determining the route to Google's DNS server (8.8.8.8) and if it's not found, we're going to wait until it becomes available. Signed-off-by: aszlig --- modules/i3/conky.nix | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'modules') diff --git a/modules/i3/conky.nix b/modules/i3/conky.nix index baee9c6f..3b2503de 100644 --- a/modules/i3/conky.nix +++ b/modules/i3/conky.nix @@ -21,8 +21,6 @@ let cexpr = name: args: "\\\${${name} ${concatStringsSep " " args}}"; - primaryNetInterface = "enp0s25"; - mkNetInfo = iface: let upspeed = cexpr "upspeed" [ iface ]; downspeed = cexpr "downspeed" [ iface ]; @@ -68,6 +66,14 @@ let cputemp() { echo $(cputemp_collect) } + while ! raw_netinfo="$(${ + "${pkgs.iproute}/sbin/ip route get 8.8.8.8 2> /dev/null" + })"; do + echo "Waiting for primary network interface to become available..." + sleep 1 + done + primary_netdev="$(echo "$raw_netinfo" | \ + ${pkgs.gnused}/bin/sed -nre 's/^.*dev *([^ ]+).*$/\1/p')" ${conky}/bin/conky -c "${baseConfig}" -t "${text}" ''; @@ -79,7 +85,7 @@ in { ]; right = mkConky [ - "NET: ${mkNetInfo primaryNetInterface}" + "NET: ${mkNetInfo "$primary_netdev"}" "DF: ${mkDiskFree "/"}" "LAVG: \\$loadavg" "TEMP - CPU: $(cputemp) - GPU: ${gpuTemp} - OUTSIDE: ${weather}" -- cgit 1.4.1