post-receive

 1#!/usr/bin/env bash
 2
 3# Ensure NixOS binaries are available in git hooks (which run with minimal PATH)
 4export PATH="/run/current-system/sw/bin:$PATH"
 5
 6# There is no session bus here. Without this, every pgit/pgit-index run
 7# autolaunches a session dbus-daemon that never exits; hundreds of them
 8# exhausted root's inotify instances (fleet-migration-plan 2.3a).
 9export DBUS_SESSION_BUS_ADDRESS=disabled:
10
11echo "Git site queued for generation"
12
13# Fork to background so git client returns immediately.
14# Double fork ensures the process survives SSH disconnect.
15(
16    (
17        # Close every inherited descriptor above stdio. soft-serve (0.11+)
18        # hands git, and so this hook, an extra pipe (fd 5) and ends the push
19        # only when it reads EOF on it; while this job holds it, the push
20        # waits for the whole site build (fleet-migration-plan 2.5b).
21        for fd in $(ls /proc/$BASHPID/fd); do
22            [ "$fd" -gt 2 ] && eval "exec $fd>&-" 2>/dev/null || true
23        done
24
25        # Sleep briefly to let parent exit, completing the double fork
26        sleep 1
27
28        forge-rebuild-site
29
30    ) < /dev/null >> /var/log/pgit.log 2>&1 & disown
31) &
32
33exit 0