diff options
| author | quentin@aristote.fr <quentin@aristote.fr> | 2025-11-09 21:52:13 +0100 |
|---|---|---|
| committer | quentin@aristote.fr <quentin@aristote.fr> | 2025-11-09 21:52:13 +0100 |
| commit | 31dcd534ab4496526df477d0db0adad433a77dfd (patch) | |
| tree | 7ee84c057cdf0287322398198667ff591210e754 | |
| parent | 4a4c98f5107c65d1387d8e23ab16450e8525f007 (diff) | |
home: i3: bar: check status of services
| -rw-r--r-- | modules/home-manager/personal/gui/x/i3/bar.nix | 60 |
1 files changed, 59 insertions, 1 deletions
diff --git a/modules/home-manager/personal/gui/x/i3/bar.nix b/modules/home-manager/personal/gui/x/i3/bar.nix index e852dd0..f766f45 100644 --- a/modules/home-manager/personal/gui/x/i3/bar.nix +++ b/modules/home-manager/personal/gui/x/i3/bar.nix @@ -12,6 +12,51 @@ let default = null; }; ifDevice = device: attrs: lib.optional (device != null) ({ inherit device; } // attrs); + isUserServiceEnabled = service: lib.hasAttr service config.systemd.user.services; + serviceStatusBlock = + { + service, + isServiceEnabled ? (_: true), + state ? { + dead = "Idle"; + start = "Good"; + failed = "Critical"; + other = "Warning"; + }, + interval ? 60, + hide_when_empty ? true, + flags ? [ ], + }: + let + checkServiceStatus = pkgs.writeShellApplication { + name = "i3status_check-service-status"; + runtimeInputs = with pkgs; [ systemd ]; + text = '' + status=$(systemctl show ${lib.concatStringsSep " " flags} --value --property SubState ${service}) + text="${service}" + state="Idle" + case $status in + dead) + text="" + state="${state.dead}" + ;; + start) + state="${state.start}";; + failed) + state="${state.failed}";; + *) + state="${state.other}";; + esac + echo '{"icon": "update", "state": "'"$state"'", "text": "'"$text"'"}' + ''; + }; + in + lib.optional (isServiceEnabled service) { + block = "custom"; + json = true; + inherit interval hide_when_empty; + command = "${checkServiceStatus}/bin/i3status_check-service-status"; + }; in { options.personal.x.i3 = { @@ -38,7 +83,20 @@ in default = { icons = "material-nf"; blocks = - (ifDevice cfg.devices.wifi { + (serviceStatusBlock { + service = "nixos-upgrade"; + }) + ++ (serviceStatusBlock { + service = "spacemacs-update"; + isServiceEnabled = isUserServiceEnabled; + flags = [ "--user" ]; + }) + ++ (serviceStatusBlock { + service = "devenv-update"; + isServiceEnabled = isUserServiceEnabled; + flags = [ "--user" ]; + }) + ++ (ifDevice cfg.devices.wifi { block = "net"; device = cfg.devices.wifi; format = " ^icon_net_wireless $ssid "; |
