{ pkgs, lib, ... }: let # Base script header and common setup for all device types baseScriptHeader = '' #!/usr/bin/env bash set -euo pipefail # The device type is baked into the script at build time readonly NUMBUS_DEVICE_TYPE="${deviceType}" # Common utility function for consistent output numbus_echo() { echo "[Numbus CLI - $NUMBUS_DEVICE_TYPE] $*" } ''; # --- Device-specific script definitions --- serverScript = baseScriptHeader + '' case "$1" in test) numbus_echo "Hello World! This is a Numbus Server." ;; status) numbus_echo "Checking system status for Server..." numbus_echo "--- Podman Containers ---" podman ps || numbus_echo "No Podman containers found or Podman not running." systemctl list-units --type=service "numbus-*" --no-pager || numbus_echo "No Numbus services found." ;; upgrade) numbus_echo "Pulling latest configuration and upgrading for Server..." # Add server-specific upgrade logic here (e.g., nixos-rebuild switch) ;; *) numbus_echo "Numbus CLI (Server edition)" echo "" echo "Usage: numbus " echo "" echo "Commands:" echo " test - Print a test message" numbus_echo " status - Show status of Numbus services (Podman, systemd)" numbus_echo " upgrade - Upgrade the server configuration" ;; esac ''; backupScript = baseScriptHeader + '' case "$1" in test) numbus_echo "Hello World! This is a Numbus Backup Server." ;; status) numbus_echo "Checking system status for Backup Server..." systemctl list-units --type=service "numbus-*" --no-pager || numbus_echo "No Numbus services found." # Add backup-specific status checks here (e.g., SnapRAID status, rsync jobs) ;; restore) numbus_echo "Starting interactive restore wizard for Backup Server..." # Add backup-specific restore logic here ;; upgrade) numbus_echo "Pulling latest configuration and upgrading for Backup Server..." # Add backup-specific upgrade logic here ;; *) numbus_echo "Numbus CLI (Backup Server edition)" echo "" echo "Usage: numbus " echo "" echo "Commands:" numbus_echo " test - Print a test message" numbus_echo " status - Show status of Numbus services" numbus_echo " restore - Start interactive restore wizard" numbus_echo " upgrade - Upgrade the backup server configuration" ;; esac ''; computerScript = baseScriptHeader + '' case "$1" in test) numbus_echo "Hello World! This is a Numbus Computer." ;; status) numbus_echo "Checking system status for Computer..." systemctl list-units --type=service "numbus-*" --no-pager || numbus_echo "No Numbus services found." # Add computer-specific status checks (e.g., GPU status, Flatpak updates) ;; upgrade) numbus_echo "Pulling latest configuration and upgrading for Computer..." # Add computer-specific upgrade logic here ;; *) numbus_echo "Numbus CLI (Computer edition)" echo "" echo "Usage: numbus " echo "" echo "Commands:" numbus_echo " test - Print a test message" numbus_echo " status - Show status of Numbus services" numbus_echo " upgrade - Upgrade the computer configuration" ;; esac ''; tvScript = baseScriptHeader + '' case "$1" in test) numbus_echo "Hello World! This is a Numbus TV." ;; status) numbus_echo "Checking system status for TV..." systemctl list-units --type=service "numbus-*" --no-pager || numbus_echo "No Numbus services found." # Add TV-specific status checks (e.g., media server status, remote connectivity) ;; remote) numbus_echo "Pairing a new Bluetooth remote for TV..." # Add TV-specific remote pairing logic here ;; upgrade) numbus_echo "Pulling latest configuration and upgrading for TV..." # Add TV-specific upgrade logic here ;; *) numbus_echo "Numbus CLI (TV edition)" echo "" echo "Usage: numbus " echo "" numbus_echo "Commands:" numbus_echo " test - Print a test message" numbus_echo " status - Show status of Numbus services" numbus_echo " remote - Pair a new Bluetooth remote" numbus_echo " upgrade - Upgrade the TV configuration" ;; esac ''; # Use lib.switch to select the correct script based on deviceType selectedScript = lib.switch deviceType { server = serverScript; backup = backupScript; computer = computerScript; tv = tvScript; } (throw "Unknown Numbus device type: ${deviceType}"); # Fail if an unknown deviceType is encountered # Define the numbus-cli package using the selected script numbus = pkgs.writeShellScriptBin "numbus" selectedScript; in { environment.systemPackages = [ numbus ]; # Add a useful alias so people can check the type via env environment.variables.NUMBUS_DEVICE_TYPE = deviceType; }