add motd
This commit is contained in:
@@ -34,6 +34,7 @@ in
|
||||
};
|
||||
homelab = {
|
||||
enable = true;
|
||||
motd.enable = true;
|
||||
gitea.enable = true;
|
||||
glance.enable = true;
|
||||
immich.enable = true;
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -41,6 +41,7 @@ in
|
||||
|
||||
# the order determines the order in glance :3
|
||||
imports = [
|
||||
./motd
|
||||
./glance
|
||||
./caddy
|
||||
./home/zigbee2mqtt
|
||||
|
||||
56
modules/homelab/motd/default.nix
Normal file
56
modules/homelab/motd/default.nix
Normal file
@@ -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";
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user