From f57c6e99ec62aa8e059f754379ae2f627343626b Mon Sep 17 00:00:00 2001 From: ediblerope Date: Thu, 16 Apr 2026 20:58:19 +0100 Subject: [PATCH] Add Last Update widget to Homepage via record-update script record-update parses nvd diff after switch and writes latest.json; Homepage polls a local-only nginx listener and renders date/changes/ closure/kernel via a customapi widget. Co-Authored-By: Claude Opus 4.7 --- common.nix | 2 +- hosts/FredOS-Mediaserver.nix | 4 ++++ scripts/record-update.sh | 41 ++++++++++++++++++++++++++++++++++++ services/homepage.nix | 20 ++++++++++++++++++ services/nginx.nix | 10 +++++++++ 5 files changed, 76 insertions(+), 1 deletion(-) create mode 100644 scripts/record-update.sh diff --git a/common.nix b/common.nix index d751990..094d272 100644 --- a/common.nix +++ b/common.nix @@ -74,7 +74,7 @@ # Shell aliases (work in both bash and fish) environment.shellAliases = { - update = "bash -c 'OLD_SYSTEM=$(readlink /run/current-system) && sudo nixos-rebuild build $@ --flake github:ediblerope/nixos-config && sudo nixos-rebuild switch $@ --flake github:ediblerope/nixos-config && nvd diff $OLD_SYSTEM /run/current-system && command -v matugen &>/dev/null && matugen image ~/.local/share/backgrounds/wallpaper.png --source-color-index 0 -m dark || true' --"; + update = "bash -c 'OLD_SYSTEM=$(readlink /run/current-system) && sudo nixos-rebuild build $@ --flake github:ediblerope/nixos-config && sudo nixos-rebuild switch $@ --flake github:ediblerope/nixos-config && nvd diff $OLD_SYSTEM /run/current-system && (command -v record-update &>/dev/null && record-update $OLD_SYSTEM /run/current-system || true) && command -v matugen &>/dev/null && matugen image ~/.local/share/backgrounds/wallpaper.png --source-color-index 0 -m dark || true' --"; clean = "sudo nix-collect-garbage -d"; ll = "ls -alh"; clear = "command clear"; diff --git a/hosts/FredOS-Mediaserver.nix b/hosts/FredOS-Mediaserver.nix index 9581afb..bda3d2d 100644 --- a/hosts/FredOS-Mediaserver.nix +++ b/hosts/FredOS-Mediaserver.nix @@ -22,6 +22,10 @@ export PATH="${pkgs.jellyfin-ffmpeg}/bin:${pkgs.coreutils}/bin:${pkgs.findutils}/bin:${pkgs.gnugrep}/bin:${pkgs.gawk}/bin:${pkgs.bc}/bin:${pkgs.curl}/bin:$PATH" exec ${pkgs.bash}/bin/bash ${../scripts/transcode-hevc.sh} "$@" '') + (pkgs.writeShellScriptBin "record-update" '' + export PATH="${pkgs.nvd}/bin:${pkgs.coreutils}/bin:${pkgs.gnugrep}/bin:${pkgs.gnused}/bin:$PATH" + exec ${pkgs.bash}/bin/bash ${../scripts/record-update.sh} "$@" + '') ]; # Basic networking diff --git a/scripts/record-update.sh b/scripts/record-update.sh new file mode 100644 index 0000000..d2617d2 --- /dev/null +++ b/scripts/record-update.sh @@ -0,0 +1,41 @@ +#!/usr/bin/env bash +# Parse `nvd diff ` output and write a JSON summary +# consumed by the Homepage dashboard's customapi widget. +set -euo pipefail + +OLD="${1:-}" +NEW="${2:-/run/current-system}" +OUT_DIR="/var/lib/homepage-updates" +OUT_FILE="$OUT_DIR/latest.json" + +if [ -z "$OLD" ]; then + echo "usage: record-update [new-system]" >&2 + exit 1 +fi + +mkdir -p "$OUT_DIR" + +DIFF=$(nvd diff "$OLD" "$NEW" 2>&1 || true) + +CHANGES=$(printf '%s\n' "$DIFF" | grep -cE '^\[[UAR][.*]\]' || true) +CLOSURE=$(printf '%s\n' "$DIFF" | grep -oE 'disk usage [+-][0-9.]+[A-Za-z]*B?' | head -1 | sed 's/disk usage //') +CLOSURE="${CLOSURE:-+0B}" + +KERNEL=$(uname -r) +DATE=$(date '+%Y-%m-%d %H:%M') + +if [ "$CHANGES" = "0" ]; then + LABEL="No changes" +else + LABEL="$CHANGES package changes" +fi + +cat > "$OUT_FILE.tmp" <