home/wm: move myip script to the polybar

This commit is contained in:
Dmitriy Pleshevskiy 2023-06-15 11:33:59 +03:00
parent 6485c3b9fb
commit be710ef363
Signed by: pleshevskiy
GPG key ID: 79C4487B44403985
5 changed files with 46 additions and 23 deletions

View file

@ -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;
};
};

View file

@ -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
'';
}

View file

@ -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
'';
}

View file

@ -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-}"

View file

@ -1,8 +0,0 @@
{ bind, writeShellApplication }:
writeShellApplication {
name = "myip";
text = ''
${bind.dnsutils}/bin/dig +short myip.opendns.com @resolver1.opendns.com
'';
}