Improve conditional for waybar
This commit is contained in:
5
home/hyprland/waybar/arrhist.nix
Normal file
5
home/hyprland/waybar/arrhist.nix
Normal file
@@ -0,0 +1,5 @@
|
||||
{ config, pkgs }:
|
||||
{
|
||||
sops.secrets."sonarr_api_key" = { };
|
||||
sops.secrets."radarr_api_key" = { };
|
||||
}
|
71
home/hyprland/waybar/arrhist.py
Normal file
71
home/hyprland/waybar/arrhist.py
Normal file
@@ -0,0 +1,71 @@
|
||||
#!/usr/bin/env python3
|
||||
import json
|
||||
import os
|
||||
import requests
|
||||
from datetime import datetime, date, timedelta
|
||||
|
||||
SECRET_DIR = "/home/torjus/.config/sops-nix/secrets"
|
||||
|
||||
def sonarr_url():
|
||||
xdg_dir = os.environ["XDG_RUNTIME_DIR"]
|
||||
if not xdg_dir:
|
||||
raise Exception("XDG_RUNTIME_DIR not set")
|
||||
with open(f"{SECRET_DIR}/sonarr_base_url") as f:
|
||||
return f.read().strip()
|
||||
|
||||
def radarr_url():
|
||||
with open(f"{SECRET_DIR}/radarr_base_url") as f:
|
||||
return f.read().strip()
|
||||
|
||||
def make_header(api_key: str):
|
||||
return {"X-Api-Key": api_key, "Accept": "application/json"}
|
||||
|
||||
def get_sonarr_key():
|
||||
with open(f"{SECRET_DIR}/sonarr_api_key") as f:
|
||||
return f.read().strip()
|
||||
|
||||
def get_radarr_key():
|
||||
with open(f"{SECRET_DIR}/radarr_api_key") as f:
|
||||
return f.read().strip()
|
||||
|
||||
def get_sonarr_history(since: datetime|None=None):
|
||||
api_key = get_sonarr_key()
|
||||
if not since:
|
||||
since = datetime.combine(date.today()-timedelta(days=1),datetime.min.time())
|
||||
url = f"{sonarr_url()}/api/history/since"
|
||||
url += f"?date={since.isoformat()}"
|
||||
response = requests.get(url, headers=make_header(api_key))
|
||||
response.raise_for_status()
|
||||
data = response.json()
|
||||
|
||||
items = []
|
||||
for item in data:
|
||||
if item["eventType"] == "downloadFolderImported":
|
||||
items.append(item["sourceTitle"])
|
||||
return items
|
||||
|
||||
def get_radarr_history(since: datetime|None=None):
|
||||
api_key = get_radarr_key()
|
||||
if not since:
|
||||
since = datetime.combine(date.today()-timedelta(days=7),datetime.min.time())
|
||||
url = f"{radarr_url()}/api/v3/history/since"
|
||||
url += f"?date={since.isoformat()}"
|
||||
response = requests.get(url, headers=make_header(api_key))
|
||||
response.raise_for_status()
|
||||
data = response.json()
|
||||
|
||||
items = []
|
||||
for item in data:
|
||||
if item["eventType"] == "downloadFolderImported":
|
||||
items.append(item["sourceTitle"])
|
||||
return items
|
||||
|
||||
if __name__ == "__main__":
|
||||
sonarr_items = get_sonarr_history()
|
||||
radarr_items = get_radarr_history()
|
||||
|
||||
output = {
|
||||
"text": f"Son: {len(sonarr_items)}|Rad: {len(radarr_items)}",
|
||||
"tooltip": "\n".join(radarr_items) + "\n".join(sonarr_items)
|
||||
}
|
||||
print(json.dumps(output))
|
@@ -8,8 +8,26 @@ let
|
||||
];
|
||||
text = builtins.readFile ./flakestat.sh;
|
||||
};
|
||||
arrhist = pkgs.stdenv.mkDerivation {
|
||||
name = "arrhist";
|
||||
propagatedBuildInputs = [
|
||||
(pkgs.python3.withPackages (pythonPackages: with pythonPackages; [
|
||||
requests
|
||||
]))
|
||||
];
|
||||
src = ./arrhist.py;
|
||||
dontUnpack = true;
|
||||
installPhase = "install -Dm755 ${./arrhist.py} $out/bin/arrhist";
|
||||
};
|
||||
withArrhist = if (osConfig.system.name == "gunter") then true else false;
|
||||
withBattery = if (osConfig.system.name == "magicman") then true else false;
|
||||
in
|
||||
{
|
||||
sops.secrets."sonarr_base_url" = { };
|
||||
sops.secrets."sonarr_api_key" = { };
|
||||
sops.secrets."radarr_base_url" = { };
|
||||
sops.secrets."radarr_api_key" = { };
|
||||
|
||||
xdg.configFile."waybar/macchiato.css" = {
|
||||
source = pkgs.fetchFromGitHub
|
||||
{
|
||||
@@ -108,6 +126,7 @@ in
|
||||
#battery,
|
||||
#custom-powermenu,
|
||||
#custom-flakestat,
|
||||
#custom-arrhist,
|
||||
#custom-cava-internal {
|
||||
padding-left: 10px;
|
||||
padding-right: 10px;
|
||||
@@ -149,86 +168,95 @@ in
|
||||
font-family: "Hack Nerd Font";
|
||||
}
|
||||
'';
|
||||
settings = [{
|
||||
"layer" = "top";
|
||||
"position" = "top";
|
||||
modules-left = [ "custom/launcher" "hyprland/workspaces" ];
|
||||
modules-center = [ "clock" ];
|
||||
modules-right =
|
||||
[
|
||||
"custom/flakestat"
|
||||
"pulseaudio"
|
||||
"pulseaudio#microphone"
|
||||
"memory"
|
||||
"cpu"
|
||||
"tray"
|
||||
(lib.mkIf (osConfig.system.name == "magicman") "battery")
|
||||
];
|
||||
"custom/launcher" = {
|
||||
"format" = " ";
|
||||
"on-click" = "pkill rofi || ~/.config/rofi/launcher.sh";
|
||||
"tooltip" = false;
|
||||
};
|
||||
"hyprland/workspaces" = {
|
||||
"format" = "{name}";
|
||||
"on-click" = "activate";
|
||||
"on-scroll-up" = "hyprctl dispatch workspace e+1";
|
||||
"on-scroll-down" = "hyprctl dispatch workspace e-1";
|
||||
};
|
||||
"pulseaudio" = {
|
||||
"scroll-step" = 5;
|
||||
"format" = "{icon} {volume}%";
|
||||
"format-muted" = "";
|
||||
"format-icons" = { "default" = [ "" "" "" ]; };
|
||||
"on-click" = "pamixer -t";
|
||||
};
|
||||
"pulseaudio#microphone" = {
|
||||
"format" = "{format_source}";
|
||||
"format-source" = " {volume}%";
|
||||
"format-source-muted" = "";
|
||||
"on-click" = "pamixer --default-source -t";
|
||||
"on-scroll-up" = "pamixer --default-source -i 5";
|
||||
"on-scroll-down" = "pamixer --default-source -d 5";
|
||||
"scroll-step" = 5;
|
||||
"on-click-right" = "pavucontrol";
|
||||
};
|
||||
"clock" = {
|
||||
"interval" = 1;
|
||||
"format" = "{:%H:%M %A %b %d}";
|
||||
"tooltip" = true;
|
||||
};
|
||||
"memory" = {
|
||||
"interval" = 3;
|
||||
"format" = " {percentage}%";
|
||||
"states" = { "warning" = 85; };
|
||||
};
|
||||
"cpu" = {
|
||||
"interval" = 3;
|
||||
"format" = " {usage}%";
|
||||
};
|
||||
"tray" = {
|
||||
"icon-size" = 15;
|
||||
"spacing" = 6;
|
||||
};
|
||||
"battery" = {
|
||||
"interval" = 60;
|
||||
"states" = {
|
||||
"warning" = 20;
|
||||
"critical" = 5;
|
||||
settings = [
|
||||
({
|
||||
"layer" = "top";
|
||||
"position" = "top";
|
||||
modules-left = [ "custom/launcher" "hyprland/workspaces" ];
|
||||
modules-center = [ "clock" ];
|
||||
modules-right =
|
||||
[
|
||||
(lib.mkIf (withArrhist) "custom/arrhist")
|
||||
"custom/flakestat"
|
||||
"pulseaudio"
|
||||
"pulseaudio#microphone"
|
||||
"memory"
|
||||
"cpu"
|
||||
"tray"
|
||||
(lib.mkIf (withBattery) "battery")
|
||||
];
|
||||
"custom/launcher" = {
|
||||
"format" = " ";
|
||||
"on-click" = "pkill rofi || ~/.config/rofi/launcher.sh";
|
||||
"tooltip" = false;
|
||||
};
|
||||
"format" = "{icon} {capacity}%";
|
||||
"format-icons" = [
|
||||
""
|
||||
""
|
||||
""
|
||||
""
|
||||
""
|
||||
];
|
||||
};
|
||||
"custom/flakestat" = {
|
||||
"exec" = "${flakestat}/bin/flakestat";
|
||||
"interval" = 600;
|
||||
};
|
||||
}];
|
||||
"hyprland/workspaces" = {
|
||||
"format" = "{name}";
|
||||
"on-click" = "activate";
|
||||
"on-scroll-up" = "hyprctl dispatch workspace e+1";
|
||||
"on-scroll-down" = "hyprctl dispatch workspace e-1";
|
||||
};
|
||||
"pulseaudio" = {
|
||||
"scroll-step" = 5;
|
||||
"format" = "{icon} {volume}%";
|
||||
"format-muted" = "";
|
||||
"format-icons" = { "default" = [ "" "" "" ]; };
|
||||
"on-click" = "pamixer -t";
|
||||
};
|
||||
"pulseaudio#microphone" = {
|
||||
"format" = "{format_source}";
|
||||
"format-source" = " {volume}%";
|
||||
"format-source-muted" = "";
|
||||
"on-click" = "pamixer --default-source -t";
|
||||
"on-scroll-up" = "pamixer --default-source -i 5";
|
||||
"on-scroll-down" = "pamixer --default-source -d 5";
|
||||
"scroll-step" = 5;
|
||||
"on-click-right" = "pavucontrol";
|
||||
};
|
||||
"clock" = {
|
||||
"interval" = 1;
|
||||
"format" = "{:%H:%M %A %b %d}";
|
||||
"tooltip" = true;
|
||||
};
|
||||
"memory" = {
|
||||
"interval" = 3;
|
||||
"format" = " {percentage}%";
|
||||
"states" = { "warning" = 85; };
|
||||
};
|
||||
"cpu" = {
|
||||
"interval" = 3;
|
||||
"format" = " {usage}%";
|
||||
};
|
||||
"tray" = {
|
||||
"icon-size" = 15;
|
||||
"spacing" = 6;
|
||||
};
|
||||
"battery" = {
|
||||
"interval" = 60;
|
||||
"states" = {
|
||||
"warning" = 20;
|
||||
"critical" = 5;
|
||||
};
|
||||
"format" = "{icon} {capacity}%";
|
||||
"format-icons" = [
|
||||
""
|
||||
""
|
||||
""
|
||||
""
|
||||
""
|
||||
];
|
||||
};
|
||||
"custom/flakestat" = {
|
||||
"exec" = "${flakestat}/bin/flakestat";
|
||||
"interval" = 600;
|
||||
};
|
||||
} // lib.optionalAttrs (withArrhist) {
|
||||
"custom/arrhist" = {
|
||||
"exec" = "${arrhist}/bin/arrhist";
|
||||
"return-type" = "json";
|
||||
"interval" = 30;
|
||||
};
|
||||
})
|
||||
];
|
||||
};
|
||||
}
|
||||
|
@@ -1,201 +0,0 @@
|
||||
{ pkgs, ... }:
|
||||
{
|
||||
programs.waybar = {
|
||||
enable = true;
|
||||
systemd = {
|
||||
enable = false; # disable it,autostart it in hyprland conf
|
||||
target = "graphical-session.target";
|
||||
};
|
||||
style = ''
|
||||
* {
|
||||
font-family: "FiraCodeNerdFont-Regular";
|
||||
font-size: 14px;
|
||||
font-weight: bold;
|
||||
border-radius: 0px;
|
||||
transition-property: background-color;
|
||||
transition-duration: 0.5s;
|
||||
}
|
||||
@keyframes blink_red {
|
||||
to {
|
||||
background-color: rgb(242, 143, 173);
|
||||
color: rgb(26, 24, 38);
|
||||
}
|
||||
}
|
||||
.warning,
|
||||
.critical,
|
||||
.urgent {
|
||||
animation-name: blink_red;
|
||||
animation-duration: 1s;
|
||||
animation-timing-function: linear;
|
||||
animation-iteration-count: infinite;
|
||||
animation-direction: alternate;
|
||||
}
|
||||
window#waybar {
|
||||
background-color: transparent;
|
||||
}
|
||||
window > box {
|
||||
margin-left: 0px;
|
||||
margin-right: 0px;
|
||||
margin-top: 0px;
|
||||
border-bottom: 2px solid @color1;
|
||||
background-color: @background;
|
||||
}
|
||||
#workspaces {
|
||||
padding-left: 0px;
|
||||
padding-right: 4px;
|
||||
}
|
||||
#workspaces button {
|
||||
padding-top: 5px;
|
||||
padding-bottom: 5px;
|
||||
padding-left: 6px;
|
||||
padding-right: 6px;
|
||||
color: @color1;
|
||||
}
|
||||
#workspaces button.active {
|
||||
background-color: @color1;
|
||||
color: rgb(26, 24, 38);
|
||||
}
|
||||
#workspaces button.urgent {
|
||||
color: rgb(26, 24, 38);
|
||||
}
|
||||
#workspaces button:hover {
|
||||
background-color: #b38dac;
|
||||
color: rgb(26, 24, 38);
|
||||
}
|
||||
tooltip {
|
||||
background: #3b4253;
|
||||
}
|
||||
tooltip label {
|
||||
color: #e4e8ef;
|
||||
}
|
||||
#custom-launcher {
|
||||
font-size: 20px;
|
||||
padding-left: 8px;
|
||||
padding-right: 6px;
|
||||
color: #7ebae4;
|
||||
}
|
||||
#mode,
|
||||
#clock,
|
||||
#memory,
|
||||
#temperature,
|
||||
#cpu,
|
||||
#mpd,
|
||||
#custom-wall,
|
||||
#temperature,
|
||||
#backlight,
|
||||
#pulseaudio,
|
||||
#network,
|
||||
#battery,
|
||||
#custom-powermenu,
|
||||
#custom-cava-internal {
|
||||
padding-left: 10px;
|
||||
padding-right: 10px;
|
||||
color: @color1;
|
||||
}
|
||||
#network.disconnected {
|
||||
color: #cccccc;
|
||||
}
|
||||
#battery.charging,
|
||||
#battery.full,
|
||||
#battery.discharging {
|
||||
color: #cf876f;
|
||||
}
|
||||
#battery.critical:not(.charging) {
|
||||
color: #d6dce7;
|
||||
}
|
||||
#custom-powermenu {
|
||||
color: #bd6069;
|
||||
}
|
||||
#tray {
|
||||
padding-right: 8px;
|
||||
padding-left: 10px;
|
||||
}
|
||||
#tray menu {
|
||||
background: #3b4252;
|
||||
color: #dee2ea;
|
||||
}
|
||||
#mpd.paused {
|
||||
color: rgb(192, 202, 245);
|
||||
font-style: italic;
|
||||
}
|
||||
#mpd.stopped {
|
||||
background: transparent;
|
||||
}
|
||||
#mpd {
|
||||
color: #e4e8ef;
|
||||
}
|
||||
#custom-cava-internal {
|
||||
font-family: "Hack Nerd Font";
|
||||
}
|
||||
'';
|
||||
settings = [{
|
||||
"layer" = "top";
|
||||
"position" = "top";
|
||||
modules-left = [ "custom/launcher" "hyprland/workspaces" ];
|
||||
modules-center = [ "clock" ];
|
||||
modules-right =
|
||||
[ "pulseaudio" "pulseaudio#microphone" "memory" "cpu" "tray" "battery" ];
|
||||
"custom/launcher" = {
|
||||
"format" = " ";
|
||||
"on-click" = "pkill rofi || ~/.config/rofi/launcher.sh";
|
||||
"tooltip" = false;
|
||||
};
|
||||
"hyprland/workspaces" = {
|
||||
"format" = "{name}";
|
||||
"on-click" = "activate";
|
||||
"on-scroll-up" = "hyprctl dispatch workspace e+1";
|
||||
"on-scroll-down" = "hyprctl dispatch workspace e-1";
|
||||
};
|
||||
"pulseaudio" = {
|
||||
"scroll-step" = 5;
|
||||
"format" = "{icon} {volume}%";
|
||||
"format-muted" = "";
|
||||
"format-icons" = { "default" = [ "" "" "" ]; };
|
||||
"on-click" = "pamixer -t";
|
||||
};
|
||||
"pulseaudio#microphone" = {
|
||||
"format" = "{format_source}";
|
||||
"format-source" = " {volume}%";
|
||||
"format-source-muted" = "";
|
||||
"on-click" = "pamixer --default-source -t";
|
||||
"on-scroll-up" = "pamixer --default-source -i 5";
|
||||
"on-scroll-down" = "pamixer --default-source -d 5";
|
||||
"scroll-step" = 5;
|
||||
"on-click-right" = "pavucontrol";
|
||||
};
|
||||
"clock" = {
|
||||
"interval" = 1;
|
||||
"format" = "{:%H:%M %A %b %d}";
|
||||
"tooltip" = true;
|
||||
};
|
||||
"memory" = {
|
||||
"interval" = 3;
|
||||
"format" = " {percentage}%";
|
||||
"states" = { "warning" = 85; };
|
||||
};
|
||||
"cpu" = {
|
||||
"interval" = 3;
|
||||
"format" = " {usage}%";
|
||||
};
|
||||
"tray" = {
|
||||
"icon-size" = 15;
|
||||
"spacing" = 6;
|
||||
};
|
||||
"battery" = {
|
||||
"interval" = 60;
|
||||
"states" = {
|
||||
"warning" = 30;
|
||||
"critical" = 5;
|
||||
};
|
||||
"format" = "{icon} {capacity}%";
|
||||
"format-icons" = [
|
||||
""
|
||||
""
|
||||
""
|
||||
""
|
||||
""
|
||||
];
|
||||
};
|
||||
}];
|
||||
};
|
||||
}
|
Reference in New Issue
Block a user