From be710ef3636621ce0751c782bbf2e3fd53e87f33 Mon Sep 17 00:00:00 2001 From: Dmitriy Pleshevskiy Date: Thu, 15 Jun 2023 11:33:59 +0300 Subject: [PATCH] home/wm: move myip script to the polybar --- home/modules/window_manager/polybar.nix | 18 +++--------------- .../window_manager/scripts/exchangerate.nix | 17 +++++++++++++++++ .../window_manager/scripts/external_ip.nix | 15 +++++++++++++++ .../window_manager/scripts/external_ip.sh | 11 +++++++++++ packages/myip.nix | 8 -------- 5 files changed, 46 insertions(+), 23 deletions(-) create mode 100644 home/modules/window_manager/scripts/exchangerate.nix create mode 100644 home/modules/window_manager/scripts/external_ip.nix create mode 100755 home/modules/window_manager/scripts/external_ip.sh delete mode 100644 packages/myip.nix diff --git a/home/modules/window_manager/polybar.nix b/home/modules/window_manager/polybar.nix index c73ef82..4fa605e 100644 --- a/home/modules/window_manager/polybar.nix +++ b/home/modules/window_manager/polybar.nix @@ -8,19 +8,8 @@ let themeCfg = config.local.theme; - exchangerate_unwrapped = pkgs.writeShellScriptBin "exchangerate" - (builtins.readFile (pkgs.substituteAll ({ src = ./scripts/exchangerate.sh; } // themeCfg.highlights))); - - exchangerate = pkgs.symlinkJoin { - name = "exchangerate"; - - paths = [ exchangerate_unwrapped ] ++ (with pkgs; [ curl gnugrep gnused coreutils ]); - buildInputs = [ pkgs.makeWrapper ]; - - postBuild = '' - wrapProgram $out/bin/exchangerate --prefix PATH : @out/bin - ''; - }; + exchangerate = import ./scripts/exchangerate.nix { inherit themeCfg pkgs; }; + external_ip = import ./scripts/external_ip.nix { inherit themeCfg pkgs; }; in { options.local.polybar = with lib; { @@ -165,11 +154,10 @@ in "module/external_ip" = { type = "custom/script"; - exec = "${pkgs.myip}/bin/myip"; + exec = "${external_ip}/bin/myip"; interval = 60; format = { inherit padding; - foreground = themeCfg.highlights.success; }; }; diff --git a/home/modules/window_manager/scripts/exchangerate.nix b/home/modules/window_manager/scripts/exchangerate.nix new file mode 100644 index 0000000..8ac2c91 --- /dev/null +++ b/home/modules/window_manager/scripts/exchangerate.nix @@ -0,0 +1,17 @@ +{ themeCfg, pkgs }: + +let + exchangerate_unwrapped = pkgs.writeShellScriptBin "exchangerate" + (builtins.readFile (pkgs.substituteAll ({ src = ./exchangerate.sh; } // themeCfg.highlights))); + +in +pkgs.symlinkJoin { + name = "exchangerate"; + + paths = [ exchangerate_unwrapped ] ++ (with pkgs; [ curl gnugrep gnused coreutils ]); + buildInputs = [ pkgs.makeWrapper ]; + + postBuild = '' + wrapProgram $out/bin/exchangerate --prefix PATH : @out/bin + ''; +} diff --git a/home/modules/window_manager/scripts/external_ip.nix b/home/modules/window_manager/scripts/external_ip.nix new file mode 100644 index 0000000..777657d --- /dev/null +++ b/home/modules/window_manager/scripts/external_ip.nix @@ -0,0 +1,15 @@ +{ themeCfg, pkgs }: +let + external_ip_unwrapped = pkgs.writeShellScriptBin "external_ip" + (builtins.readFile (pkgs.substituteAll ({ src = ./external_ip.sh; } // themeCfg.highlights))); +in +pkgs.symlinkJoin { + name = "external_ip"; + + paths = [ external_ip_unwrapped ] ++ (with pkgs; [ bind.dnsutils ]); + buildInputs = [ pkgs.makeWrapper ]; + + postBuild = '' + wrapProgram $out/bin/external_ip --prefix PATH : @out/bin + ''; +} diff --git a/home/modules/window_manager/scripts/external_ip.sh b/home/modules/window_manager/scripts/external_ip.sh new file mode 100755 index 0000000..0f34815 --- /dev/null +++ b/home/modules/window_manager/scripts/external_ip.sh @@ -0,0 +1,11 @@ +#!/usr/bin/env bash + +res=$(dig +timeout=1 +short myip.opendns.com @resolver1.opendns.com 2>/dev/null) +if [ -z "$res" ]; then + text="NO CONN" + echo "%{F@error@}${text}%{F-}" + exit 0 +fi + +echo "%{F@success@}${res}%{F-}" + diff --git a/packages/myip.nix b/packages/myip.nix deleted file mode 100644 index 1c7f60a..0000000 --- a/packages/myip.nix +++ /dev/null @@ -1,8 +0,0 @@ -{ bind, writeShellApplication }: - -writeShellApplication { - name = "myip"; - text = '' - ${bind.dnsutils}/bin/dig +short myip.opendns.com @resolver1.opendns.com - ''; -}