Watch
0
0
Fork
You've already forked hyperhive
0
hyperhive/nix/packages/hyperhive-the-movie.nix
2026-11-16 20:12:03 +01:00

135 lines
4.5 KiB
Nix

# `nix run .#hyperhive-the-movie` — gource visualisation of the git
# history of the repo it is run from. `-- --record` renders
# gource-hyperhive.webm in the cwd instead of opening a window: AV1 in WebM,
# which plays in current Firefox and Chrome and compresses this flat,
# dark picture far better than H.264. Milestones show as captions, from the git
# tags of the repo and from `hyperhive-the-movie-milestones.txt`.
{
lib,
writeShellApplication,
gource,
ffmpeg,
xvfb-run,
librsvg,
curl,
git,
coreutils,
gnugrep,
logo,
}:
writeShellApplication {
name = "hyperhive-the-movie";
runtimeInputs = [
gource
ffmpeg
xvfb-run
librsvg
curl
git
coreutils
gnugrep
];
text = ''
usage() {
cat <<'USAGE'
hyperhive-the-movie - gource visualisation of this repo's git history
Usage: nix run .#hyperhive-the-movie -- [--record | --help]
(no flag) open a gource window and play the history
--record render gource-hyperhive.webm in the current directory
instead (1280x720, 30 fps, AV1 in WebM; plays in recent
Firefox and Chrome). Needs no display.
-h, --help show this text
Run it from inside the repo. Captions come from two places: the git tags
(shown at the tagged commit's date) and the milestones file,
nix/packages/hyperhive-the-movie-milestones.txt, one "YYYY-MM-DD|caption"
per line. Edit that file, or tag a commit with `git tag NAME COMMIT`.
USAGE
}
record=false
case "''${1:-}" in
"") ;;
--record) record=true ;;
-h | --help)
usage
exit 0
;;
*)
echo "hyperhive-the-movie: unknown argument '$1'" >&2
usage >&2
exit 2
;;
esac
cd "$(git rev-parse --show-toplevel)"
# Per-agent avatars from the local forge (same icons the dashboard
# uses), rasterised because --user-image-dir needs png. Cached.
# müde is the human operator: no forge icon.
avatar_dir="''${XDG_CACHE_HOME:-$HOME/.cache}/hyperhive-the-movie/avatars"
mkdir -p "$avatar_dir"
while IFS= read -r author; do
[[ "$author" == "müde" || -f "$avatar_dir/$author.png" ]] && continue
svg="$avatar_dir/$author.svg"
curl -sSf "http://localhost/agent/$author/icon" -o "$svg" 2>/dev/null || rm -f "$svg"
# unknown agents get a 200 html fallback page, not a 404
if [[ -f "$svg" ]]; then
if head -c 200 "$svg" | grep -qi '<svg'; then
rsvg-convert -w 256 -h 256 "$svg" -o "$avatar_dir/$author.png"
fi
rm -f "$svg"
fi
done < <(git log --format='%an' | sort -u)
# Milestone captions, `unix time|text`, sorted by time: the tracked
# milestones file (`YYYY-MM-DD|text`) and the repo's git tags.
captions="$(mktemp)"
# The logo is drawn at its own size, so it is rendered small: 96 px, a third
# of the icon's 300.
logo_png="$(mktemp --suffix=.png)"
rsvg-convert -w 96 -h 96 ${logo} -o "$logo_png"
trap 'rm -f "$captions" "$logo_png"' EXIT
{
while IFS='|' read -r day text; do
[[ -z "$day" || "$day" == \#* ]] && continue
echo "$(date -d "$day" +%s)|$text"
done < ${./hyperhive-the-movie-milestones.txt}
git for-each-ref --format='%(creatordate:unix)|%(refname:short)' refs/tags
} | sort -n > "$captions"
# Catppuccin Mocha, as in frontend/packages/shared/src/colors.css.
args=(
-s 1 -1280x720 --auto-skip-seconds 1 --multi-sampling --stop-at-end
--date-format "%Y-%m-%d"
--caption-file "$captions" --caption-size 28 --caption-duration 4
--caption-colour f9e2af
--background-colour 1e1e2e --font-colour cdd6f4
--highlight-colour f9e2af --highlight-users --highlight-dirs
--filename-colour 585b70 --dir-colour 89b4fa
--bloom-multiplier 1.5 --bloom-intensity 0.75 --elasticity 0.1
--title hyperhive
--logo "$logo_png" --logo-offset 20x20
--user-image-dir "$avatar_dir"
--key
)
if $record; then
xvfb-run -a --server-args="-screen 0 1280x720x24" \
gource "''${args[@]}" --output-ppm-stream - --output-framerate 30 \
| ffmpeg -y -r 30 -f image2pipe -vcodec ppm -i - \
-vf "scale=trunc(iw/2)*2:trunc(ih/2)*2" \
-c:v libsvtav1 -preset 6 -crf 34 -g 300 -pix_fmt yuv420p \
gource-hyperhive.webm
else
gource "''${args[@]}"
fi
'';
meta = {
description = "gource movie of the hyperhive git history";
mainProgram = "hyperhive-the-movie";
platforms = lib.platforms.linux;
};
}