diff --git a/modules/homelab/motd/default.nix b/modules/homelab/motd/default.nix index 8bb7a06..c6994bf 100644 --- a/modules/homelab/motd/default.nix +++ b/modules/homelab/motd/default.nix @@ -7,9 +7,9 @@ inherit (lib) mkIf mkOption types filterAttrs mapAttrsToList; cfg = config.homelab.motd; - # Collect services that have a motd value set + # Collect all homelab services that define a motd string motdServices = - mapAttrsToList (name: value: value.motd) + mapAttrsToList (_: v: v.motd) (filterAttrs (_: v: v ? motd && v.motd != null) config.homelab); in { options.homelab.motd = { @@ -26,7 +26,6 @@ in { BLUE="\033[1;34m" RED="\033[1;31m" - GREEN="\033[1;32m" YELLOW="\033[1;33m" RESET="\033[0m" @@ -36,7 +35,7 @@ in { nixos_version=$(grep VERSION= /etc/os-release | cut -d'"' -f2) kernel_version=$(uname -r) - echo -e "''${GREEN}System Info''${RESET}" + echo -e "''${YELLOW}System Info''${RESET}" echo -e " Hostname: $(hostname)" echo -e " Interface: ''${default_iface}" echo -e " IPv4: ''${ip_addr}" @@ -52,20 +51,25 @@ in { mem_percent=$((100 * mem_used / mem_total)) uptime_fmt=$(uptime -p 2>/dev/null || cat /proc/uptime | awk '{print int($1/3600)"h "int(($1%3600)/60)"m"}') - echo -e "''${GREEN}Resources''${RESET}" + echo -e "''${YELLOW}Resources''${RESET}" echo -e " CPU Usage: ''${cpu_usage}" echo -e " Memory: ''${mem_percent}% used" echo -e " Uptime: ''${uptime_fmt}" echo - # --- Service Status --- - echo -e "''${GREEN}Homelab Services''${RESET}" + # --- Homelab Services --- + echo -e "''${YELLOW}Homelab Services''${RESET}" + ${lib.concatStringsSep "\n" (map (service: '' - status=$(systemctl is-active ''${service} 2>/dev/null) - if [ "''${status}" = "active" ]; then - echo -e " ''${BLUE}''${service}''${RESET} - running" + if systemctl list-units --type=service --all | grep -q "^''${service}"; then + status=$(systemctl is-active ''${service} 2>/dev/null) + if [ "''${status}" = "active" ]; then + echo -e " ''${BLUE}''${service}''${RESET} - running" + else + echo -e " ''${RED}''${service}''${RESET} - not running" + fi else - echo -e " ''${RED}''${service}''${RESET} - not running" + echo -e " ''${RED}''${service}''${RESET} - not found" fi '') motdServices)}