From 28856a132806adc963abfff29fff9233160b9cc7 Mon Sep 17 00:00:00 2001 From: blake Date: Tue, 14 Oct 2025 21:06:17 -0500 Subject: [PATCH] add motd --- hosts/snowbelle/configuration.nix | 1 + modules/homelab/arr/sonarr/default.nix | 4 ++ modules/homelab/default.nix | 1 + modules/homelab/motd/default.nix | 56 ++++++++++++++++++++++++++ 4 files changed, 62 insertions(+) create mode 100644 modules/homelab/motd/default.nix diff --git a/hosts/snowbelle/configuration.nix b/hosts/snowbelle/configuration.nix index 1981962..0305054 100644 --- a/hosts/snowbelle/configuration.nix +++ b/hosts/snowbelle/configuration.nix @@ -34,6 +34,7 @@ in }; homelab = { enable = true; + motd.enable = true; gitea.enable = true; glance.enable = true; immich.enable = true; diff --git a/modules/homelab/arr/sonarr/default.nix b/modules/homelab/arr/sonarr/default.nix index 5651ef7..66909ef 100644 --- a/modules/homelab/arr/sonarr/default.nix +++ b/modules/homelab/arr/sonarr/default.nix @@ -36,6 +36,10 @@ in default = true; description = "enable backups for ${service}"; }; + motd = lib.mkOption { + type = lib.types.nullOr lib.types.str; + default = service; + }; }; config = lib.mkIf cfg.enable { diff --git a/modules/homelab/default.nix b/modules/homelab/default.nix index 2e50366..cf13c09 100644 --- a/modules/homelab/default.nix +++ b/modules/homelab/default.nix @@ -41,6 +41,7 @@ in # the order determines the order in glance :3 imports = [ + ./motd ./glance ./caddy ./home/zigbee2mqtt diff --git a/modules/homelab/motd/default.nix b/modules/homelab/motd/default.nix new file mode 100644 index 0000000..147ffd7 --- /dev/null +++ b/modules/homelab/motd/default.nix @@ -0,0 +1,56 @@ +{ + config, + lib, + pkgs, + ... +}: let + homelab = config.homelab or {}; + + # Build a list of { name, unit } for all non-null motd entries + motdServices = lib.pipe homelab [ + lib.attrNames + (map (name: { + inherit name; + unit = homelab.${name}.motd or null; + })) + (lib.filter (s: s.unit != null)) + ]; + + # Build script body + motdScript = lib.concatStringsSep "\n" ( + [ + "#!/usr/bin/env bash" + "blue='\\033[34m'" + "red='\\033[31m'" + "reset='\\033[0m'" + "" + "echo \"Hostname: $(hostname)\"" + "echo \"Uptime: $(uptime -p)\"" + "echo \"Load: $(awk '{print $1, $2, $3}' /proc/loadavg)\"" + "echo" + "echo \"Service status:\"" + ] + ++ (map (s: '' + status=$(systemctl is-active ${lib.escapeShellArg s.unit} 2>/dev/null) + if [ "$status" = "active" ]; then + printf "%b%-25s%b %s\\n" "$blue" "${s.name}" "$reset" "running" + else + printf "%b%-25s%b %s\\n" "$red" "${s.name}" "$reset" "FAILED ($status)" + fi + '') + motdServices) + ++ [""] + ); +in { + options.homelab.motd = { + enable = lib.mkEnableOption "enable custom homelab motd"; + }; + + config = lib.mkIf config.homelab.motd.enable { + # write into /etc/profile.d so shells source it at login + environment.etc."profile.d/homelab-motd.sh".text = motdScript; + + # make sure it is executable + environment.etc."profile.d/homelab-motd.sh".mode = "0755"; + }; +}