testing motd

This commit is contained in:
2025-10-14 21:30:11 -05:00
parent 86d3855734
commit a92f00a2ac

View File

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