nixos-config/nixos/components/terminal/wtf.nix

406 lines
9.7 KiB
Nix
Raw Normal View History

2023-05-28 20:22:23 +02:00
{ pkgs, config, lib, ... }:
with lib;
2020-01-06 14:36:38 +01:00
let
2021-11-01 09:20:42 +01:00
networkStatus =
let
q-online = ''
if ${pkgs.curl}/bin/curl -s google.com >/dev/null; then
echo 'status: online'
else
echo 'status: offline '
fi
'';
q-wireless = ''
for dev in $(
${pkgs.iw}/bin/iw dev \
| ${pkgs.gnused}/bin/sed -n 's/^\s*Interface\s\+\([0-9a-z]\+\)$/\1/p'
); do
inet=$(${pkgs.iproute}/bin/ip addr show $dev \
| ${pkgs.gnused}/bin/sed -n 's/.*inet \([0-9]\+\.[0-9]\+\.[0-9]\+\.[0-9]\+\).*/\1/p') \
|| unset inet
ssid=$(${pkgs.iw}/bin/iw dev $dev link \
| ${pkgs.gnused}/bin/sed -n 's/.*\tSSID: \(.*\)/\1/p' \
| ${pkgs.coreutils}/bin/tr -d '\r') \
|| unset ssid
printf '%s: %s %s\n' $dev ''${inet+ $inet} ''${ssid+ $ssid}
done
'';
in
pkgs.writers.writeBash "network-status" ''
${q-wireless}
${q-online}
${pkgs.coreutils}/bin/uptime
2020-01-07 04:32:19 +01:00
'';
2020-01-07 03:44:59 +01:00
taskNextWeek = pkgs.writers.writeDash "taskweek" ''
${pkgs.taskwarrior}/bin/task \
2021-11-20 14:52:37 +01:00
export "(due.before:today+7days and due.after:today)" \
2020-01-07 03:44:59 +01:00
| ${pkgs.jq}/bin/jq '[.[] | { Day: .due, ID: .id, Description: .description | sub("\n.*";"")} ] | sort_by(.Day)' \
| ${pkgs.miller}/bin/mlr --ijson --opprint put '$Day = strftime(strptime($Day,"%Y%m%dT%H%M%SZ")'$(date +%z)'00,"%a")'
'';
2020-01-06 14:36:38 +01:00
activeTasks = pkgs.writers.writeBash "active-tasks" ''
2021-11-20 14:52:37 +01:00
${pkgs.taskwarrior}/bin/task export status:pending and "( +ACTIVE or +DUETODAY or +TODAY or +OVERDUE )" | \
2020-01-06 14:36:38 +01:00
${pkgs.jq}/bin/jq \
--raw-output '
sort_by(.description) | reverse |
.[] |
"[ \( .id ) ] \( .description )"
'
echo
'';
userHighlight = map ({ user, ... }: user)
2020-03-13 21:22:30 +01:00
(builtins.attrValues config.programs.custom.browser.configList)
2021-11-01 09:20:42 +01:00
++ [ "steam" ];
2020-01-06 14:36:38 +01:00
activeUsers = pkgs.writers.writeBash "active-users" ''
${pkgs.procps}/bin/ps -eo user \
| ${pkgs.gnused}/bin/sed '1 d' \
| ${pkgs.coreutils}/bin/sort \
| ${pkgs.coreutils}/bin/uniq \
| ${pkgs.gnugrep}/bin/egrep --color=always '(${
pkgs.lib.concatStringsSep "|" userHighlight
})|$'
'';
# default settings
wtfModule =
args@{ height ? 1, width ? 1, top, left, enabled ? true, type, ... }:
{
enabled = enabled;
focusable = false;
position.top = top;
position.left = left;
position.height = height;
position.width = width;
} // (lib.filterAttrs
2021-11-01 09:20:42 +01:00
(key: _: lib.all (x: x != key) [ "height" "width" "top" "left" ])
args);
2020-01-10 20:16:59 +01:00
# command runner module
cmdRunner = args@{ cmd, ... }:
wtfModule ({
type = "cmdrunner";
focusable = false;
refreshInterval = 300;
} // args);
modules = {
2020-01-10 20:16:59 +01:00
inherit cmdRunner;
digitalclock = args@{ top, left, ... }:
2020-01-10 20:16:59 +01:00
cmdRunner ({
cmd = pkgs.writers.writeDash "clock" ''
${pkgs.toilet}/bin/toilet --font future `${pkgs.coreutils}/bin/date +"%a %H:%M"`
${pkgs.coreutils}/bin/date +"%B %d %Y"
'';
title = "";
2020-01-10 20:16:59 +01:00
refreshInterval = 30;
} // args);
clocks = args@{ top, left, ... }:
wtfModule ({
type = "clocks";
title = "";
border = false;
colors.rows = {
even = "white";
odd = "white";
};
locations = {
2023-04-17 09:20:38 +02:00
UTC = "Etc/UTC";
Berlin = "Europe/Berlin";
2023-04-17 09:20:38 +02:00
Cuba = "America/Havana";
Wellington = "Pacific/Auckland";
};
sort = "alphabetical";
refreshInterval = 60;
} // args);
resourceusage = args@{ top, left, ... }:
wtfModule ({
type = "resourceusage";
title = "";
cpuCombined = false;
refreshInterval = 5;
} // args);
power = args@{ top, left, ... }:
wtfModule ({
type = "power";
title = "";
refreshInterval = 100;
} // args);
prettyweather = args@{ top, left, ... }:
wtfModule ({
type = "prettyweather";
title = "";
2020-08-10 18:10:50 +02:00
city = "Essen";
unit = "m";
view = 0;
language = "en";
refreshInterval = 3600;
} // args);
2020-01-10 11:54:09 +01:00
feedreader = args@{ top, left, feeds, ... }:
wtfModule ({
type = "feedreader";
title = "";
2020-01-10 12:47:58 +01:00
refreshInterval = 3600;
2020-01-10 11:54:09 +01:00
focusable = true;
#feedLimit = 10;
colors.rows = {
even = "white";
odd = "white";
};
} // args);
github = args@{ top, left, username, apiKey, ... }:
wtfModule ({
type = "github";
title = "";
refreshInterval = 3600;
feedlimit = 10;
enableStatus = true;
# customQueries:
# othersPRs:
# title: "Others Pull Requests"
# filter: "is:open is:pr -author:wtfutil"
# repositories:
# - "wtfutil/wtf"
# - "wtfutil/docs"
# - "umbrella-corp/wesker-api"
} // args);
};
2020-01-10 11:54:09 +01:00
newsJson = {
2020-01-06 14:36:38 +01:00
wtf = {
term = "rxvt-unicode-256color";
colors.border = {
focusable = "darkslateblue";
focused = "orange";
normal = "green";
};
2020-01-10 11:54:09 +01:00
grid = {
2020-01-10 12:47:58 +01:00
columns = [ 28 0 0 ];
2020-01-10 11:54:09 +01:00
rows = [ 9 9 9 9 9 9 0 ];
};
refreshInterval = 1;
mods = with modules; {
2020-01-10 20:16:59 +01:00
clock = digitalclock {
2020-01-10 11:54:09 +01:00
top = 0;
left = 0;
};
weather = prettyweather {
top = 1;
left = 0;
};
# feeds
hackernews = feedreader {
title = "Hacker News";
top = 0;
left = 1;
2020-01-10 12:47:58 +01:00
height = 3;
2020-01-10 11:54:09 +01:00
feeds = [ "https://news.ycombinator.com/rss" ];
};
2020-01-10 12:47:58 +01:00
lopster = feedreader {
title = "Lopsters";
top = 0;
left = 2;
height = 3;
2020-01-10 20:16:59 +01:00
feeds = [ "https://lobste.rs/rss" ];
2020-01-10 12:47:58 +01:00
};
2020-01-10 20:16:59 +01:00
hackernews_tools = feedreader {
title = "Hacker News Tools";
top = 4;
left = 1;
height = 1;
feeds =
[ "https://latesthackingnews.com/category/hacking-tools/feed/" ];
};
2020-01-10 11:54:09 +01:00
nixos = feedreader {
title = "NixOS Weekly";
2020-01-10 12:47:58 +01:00
top = 3;
2020-01-10 11:54:09 +01:00
left = 1;
height = 1;
feeds = [ "https://weekly.nixos.org/feeds/all.rss.xml" ];
};
taskwarrior = feedreader {
title = "Taskwarrior";
top = 3;
2020-01-10 12:47:58 +01:00
left = 2;
2020-01-10 11:54:09 +01:00
height = 1;
feeds = [ "https://taskwarrior.org/feed.rss" ];
};
#github = github {
# username = "mrVanDalo";
# apiKey = "";
# repositories = [
# "nixos/nixpkgs"
# ];
#};
};
};
};
2020-01-06 14:36:38 +01:00
2020-01-10 11:54:09 +01:00
qJson = {
wtf = {
term = "rxvt-unicode-256color";
colors.border = {
focusable = "darkslateblue";
focused = "orange";
normal = "green";
};
2020-01-06 14:36:38 +01:00
grid = {
2020-01-07 03:44:59 +01:00
columns = [ 33 12 28 36 0 ];
2023-04-17 09:20:38 +02:00
rows = [ 9 4 6 6 0 ];
2020-01-06 14:36:38 +01:00
};
refreshInterval = 1;
mods = with modules; {
2020-01-06 14:36:38 +01:00
digitalclock = digitalclock {
top = 0;
left = 0;
2020-01-06 14:36:38 +01:00
};
clocks = clocks {
top = 1;
left = 0;
2020-01-06 14:36:38 +01:00
};
top = resourceusage {
top = 0;
left = 1;
2020-01-07 03:44:59 +01:00
width = 2;
2020-01-06 14:36:38 +01:00
};
power = power {
top = 2;
left = 0;
2020-01-06 14:36:38 +01:00
};
rates = wtfModule {
2021-11-20 14:52:37 +01:00
type = "yfinance";
top = 3;
left = 0;
2020-01-06 14:36:38 +01:00
title = "rates";
2021-11-20 14:52:37 +01:00
symbols = [ "EURUSD=X" "EURNZD=X" ];
refreshInterval = 60;
2020-01-06 14:36:38 +01:00
};
weather = prettyweather {
top = 0;
2020-01-07 03:44:59 +01:00
left = 3;
2020-01-06 14:36:38 +01:00
};
calendar = cmdRunner {
2020-01-06 14:36:38 +01:00
title = "";
args = [ "-3" "--monday" "--color=never" "-w" ];
cmd = "cal";
top = 1;
left = 1;
height = 2;
2020-01-07 03:44:59 +01:00
width = 3;
2020-01-06 14:36:38 +01:00
refreshInterval = 3600;
};
active-users = cmdRunner {
2020-01-06 14:36:38 +01:00
title = "users";
cmd = activeUsers;
top = 0;
2020-01-07 03:44:59 +01:00
left = 4;
height = 4;
width = 1;
2020-01-06 14:51:12 +01:00
refreshInterval = 30;
2020-01-06 14:36:38 +01:00
};
2022-06-23 09:51:30 +02:00
#active-tasks = cmdRunner {
# title = "active tasks";
# cmd = activeTasks;
# top = 4;
# left = 2;
# height = 1;
# width = 3;
# refreshInterval = 60;
#};
2020-01-07 03:44:59 +01:00
2022-06-23 09:51:30 +02:00
#next-week-tasks = cmdRunner {
# title = "upcoming";
# cmd = taskNextWeek;
# top = 4;
# left = 0;
# height = 1;
# width = 2;
# refreshInterval = 60;
#};
2020-01-07 04:32:19 +01:00
network-status = cmdRunner {
title = "network status";
cmd = networkStatus;
top = 3;
left = 1;
height = 1;
width = 3;
2021-12-28 16:19:29 +01:00
refreshInterval = 7;
2020-01-07 04:32:19 +01:00
};
uptime = cmdRunner {
enabled = false;
title = "uptime";
cmd = "uptime";
top = 3;
left = 1;
height = 1;
width = 3;
};
2020-01-06 14:36:38 +01:00
};
};
};
2020-01-10 11:54:09 +01:00
createDashboard = { json, name }:
let configuration = pkgs.writeText "config.yml" (builtins.toJSON json);
in pkgs.writers.writeBashBin name ''
${pkgs.unstable.wtf}/bin/wtfutil --config=${toString configuration}
2020-01-10 11:54:09 +01:00
'';
2020-01-06 14:36:38 +01:00
2021-11-01 09:20:42 +01:00
in
2020-01-06 14:36:38 +01:00
2023-05-28 20:22:23 +02:00
{
options.components.terminal.wtf.enable = mkOption {
type = lib.types.bool;
default = config.components.terminal.enable;
};
config = mkIf (config.components.terminal.wtf.enable) {
services.upower.enable = true;
environment.systemPackages = [
pkgs.unstable.wtf
(createDashboard {
json = qJson;
name = "q";
})
(createDashboard {
json = newsJson;
name = "news";
})
#activeUsers
#activeTasks
pkgs.upower
];
2020-01-06 14:36:38 +01:00
2023-05-28 20:22:23 +02:00
};
2020-01-06 14:36:38 +01:00
}