fix colors
This commit is contained in:
@@ -7,16 +7,17 @@
|
|||||||
inherit (lib) mkIf mkOption types filterAttrs mapAttrsToList;
|
inherit (lib) mkIf mkOption types filterAttrs mapAttrsToList;
|
||||||
cfg = config.homelab.motd;
|
cfg = config.homelab.motd;
|
||||||
|
|
||||||
# Collect all homelab services that define a motd string
|
# collect services to display
|
||||||
motdServices =
|
motd_list =
|
||||||
mapAttrsToList (_: v: v.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 = {
|
||||||
enable = mkOption {
|
enable = mkOption {
|
||||||
type = types.bool;
|
type = types.bool;
|
||||||
default = true;
|
default = true;
|
||||||
description = "Enable the homelab MOTD.";
|
description = "enable motd script";
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -24,10 +25,10 @@ in {
|
|||||||
environment.etc."motd".text = ''
|
environment.etc."motd".text = ''
|
||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
BLUE="\033[1;34m"
|
active="\033[1;34m"
|
||||||
RED="\033[1;31m"
|
inactive="\033[1;31m"
|
||||||
YELLOW="\033[1;33m"
|
headings="\033[0;36m"
|
||||||
RESET="\033[0m"
|
reset="\033[0m"
|
||||||
|
|
||||||
# --- System Info ---
|
# --- System Info ---
|
||||||
default_iface=$(ip route | awk '/default/ {print $5; exit}')
|
default_iface=$(ip route | awk '/default/ {print $5; exit}')
|
||||||
@@ -35,7 +36,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 "''${YELLOW}System Info''${RESET}"
|
echo -e "''${headings}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}"
|
||||||
@@ -51,28 +52,28 @@ 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 "''${YELLOW}Resources''${RESET}"
|
echo -e "''${headings}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
|
||||||
|
|
||||||
# --- Homelab Services ---
|
# --- Homelab Services ---
|
||||||
echo -e "''${YELLOW}Homelab Services''${RESET}"
|
echo -e "''${headings}Homelab Services''${reset}"
|
||||||
|
|
||||||
${lib.concatStringsSep "\n" (map (service: ''
|
${lib.concatStringsSep "\n" (map (service: ''
|
||||||
if systemctl list-units --type=service --all | grep -q "${service}"; then
|
if systemctl list-units --type=service --all | grep -q "${service}"; then
|
||||||
status=$(systemctl is-active ${service} 2>/dev/null)
|
status=$(systemctl is-active ${service} 2>/dev/null)
|
||||||
if [ "''${status}" = "active" ]; then
|
if [ "''${status}" = "active" ]; then
|
||||||
echo -e " ''${BLUE}${service}''${RESET} - running"
|
echo -e " ''${active}${service}''${reset} - running"
|
||||||
else
|
else
|
||||||
echo -e " ''${RED}${service}''${RESET} - not running"
|
echo -e " ''${inactive}${service}''${reset} - not running"
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
echo -e " ''${RED}${service}''${RESET} - not found"
|
echo -e " ''${inactive}${service}''${reset} - not found"
|
||||||
fi
|
fi
|
||||||
'')
|
'')
|
||||||
motdServices)}
|
motd_list)}
|
||||||
|
|
||||||
echo
|
echo
|
||||||
'';
|
'';
|
||||||
|
|||||||
Reference in New Issue
Block a user