fix colors

This commit is contained in:
2025-10-14 22:23:16 -05:00
parent 69a671559a
commit 8321e6fe2c

View File

@@ -7,16 +7,17 @@
inherit (lib) mkIf mkOption types filterAttrs mapAttrsToList;
cfg = config.homelab.motd;
# Collect all homelab services that define a motd string
motdServices =
# collect services to display
motd_list =
mapAttrsToList (_: v: v.motd)
(filterAttrs (_: v: v ? motd && v.motd != null) config.homelab);
in {
options.homelab.motd = {
enable = mkOption {
type = types.bool;
default = true;
description = "Enable the homelab MOTD.";
description = "enable motd script";
};
};
@@ -24,10 +25,10 @@ in {
environment.etc."motd".text = ''
#!/usr/bin/env bash
BLUE="\033[1;34m"
RED="\033[1;31m"
YELLOW="\033[1;33m"
RESET="\033[0m"
active="\033[1;34m"
inactive="\033[1;31m"
headings="\033[0;36m"
reset="\033[0m"
# --- System Info ---
default_iface=$(ip route | awk '/default/ {print $5; exit}')
@@ -35,7 +36,7 @@ in {
nixos_version=$(grep VERSION= /etc/os-release | cut -d'"' -f2)
kernel_version=$(uname -r)
echo -e "''${YELLOW}System Info''${RESET}"
echo -e "''${headings}System Info''${reset}"
echo -e " Hostname: $(hostname)"
echo -e " Interface: ''${default_iface}"
echo -e " IPv4: ''${ip_addr}"
@@ -51,28 +52,28 @@ 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 "''${YELLOW}Resources''${RESET}"
echo -e "''${headings}Resources''${reset}"
echo -e " CPU Usage: ''${cpu_usage}"
echo -e " Memory: ''${mem_percent}% used"
echo -e " Uptime: ''${uptime_fmt}"
echo
# --- Homelab Services ---
echo -e "''${YELLOW}Homelab Services''${RESET}"
echo -e "''${headings}Homelab Services''${reset}"
${lib.concatStringsSep "\n" (map (service: ''
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"
echo -e " ''${active}${service}''${reset} - running"
else
echo -e " ''${RED}${service}''${RESET} - not running"
echo -e " ''${inactive}${service}''${reset} - not running"
fi
else
echo -e " ''${RED}${service}''${RESET} - not found"
echo -e " ''${inactive}${service}''${reset} - not found"
fi
'')
motdServices)}
motd_list)}
echo
'';