[fabrica] Release pin (QC M1): nix-pin.sh pins a clean commit and records it, its source tree and nixpkgs; release-pin.mjs refuses a pin whose source tree is not the tag's and publishes the pinned commit; docs say what is checked (one rebuild of the outputs) and that none of it has run yet
This commit is contained in:
+28
-12
@@ -3,11 +3,14 @@
|
||||
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
# file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
#
|
||||
# The verifiable Nix build (ROADMAP §6 phase 4, docs/verify.md): build .#ianitor and
|
||||
# .#ianitor-web, build them a second time from scratch (`--rebuild`: Nix fails if the bytes
|
||||
# differ), and record each output's store path and NAR hash in .fabrica/nix/pin.json. The release
|
||||
# pipeline publishes that pin, with the tag's commit, as ianitor-nix.json under SHA256SUMS signed
|
||||
# by domi-release; anyone who builds the tag gets the same NAR hashes.
|
||||
# The verifiable Nix build (ROADMAP §6 phase 4, docs/verify.md): at a clean commit, build
|
||||
# .#ianitor and .#ianitor-web, rebuild each output derivation once more (`--rebuild`: Nix builds
|
||||
# the top derivation again and fails if its bytes differ; the dependencies come from the binary
|
||||
# cache and are not rebuilt), and record in .fabrica/nix/pin.json each output's store path and NAR
|
||||
# hash, the commit and its source tree (every tracked file but the pin), and the nixpkgs revision
|
||||
# of flake.lock. The release pipeline refuses the pin unless the tagged commit has that source
|
||||
# tree (scripts/release-pin.mjs) and publishes it as ianitor-nix.json under SHA256SUMS signed by
|
||||
# domi-release.
|
||||
#
|
||||
# scripts/nix-pin.sh # write .fabrica/nix/pin.json (commit it before tagging)
|
||||
# scripts/nix-pin.sh --check # rebuild and compare with the committed pin; 1 if different
|
||||
@@ -21,20 +24,30 @@ cd "$root"
|
||||
mode=${1:-write}
|
||||
pin=.fabrica/nix/pin.json
|
||||
nf=(--extra-experimental-features "nix-command flakes")
|
||||
# The pin speaks for a commit: nothing but the pin itself may differ from it.
|
||||
if [ -n "$(git status --porcelain --untracked-files=all -- . ":(exclude)$pin")" ]; then
|
||||
echo "the tree has changes that are not committed; pin a clean commit" >&2
|
||||
git status --short -- . ":(exclude)$pin" >&2
|
||||
exit 1
|
||||
fi
|
||||
commit=$(git rev-parse HEAD)
|
||||
tree=$(node scripts/release-pin.mjs --source-tree "$commit")
|
||||
nixpkgs=$(jq -r '.nodes.nixpkgs.locked.rev' flake.lock)
|
||||
system=$(nix "${nf[@]}" eval --raw --impure --expr builtins.currentSystem)
|
||||
version=$(sed -n '/^\[workspace.package\]/,/^\[/s/^version = "\(.*\)"/\1/p' Cargo.toml)
|
||||
|
||||
mkdir -p "$root/target"
|
||||
entries=()
|
||||
for attr in ianitor ianitor-web; do
|
||||
path=$(nix "${nf[@]}" build ".#$attr" --no-link --print-out-paths)
|
||||
# A second, independent build of the same derivation; Nix compares the outputs bit for bit.
|
||||
if ! nix "${nf[@]}" build ".#$attr" --rebuild --no-link >/dev/null 2>"$root/target-nix-rebuild.log"; then
|
||||
if ! nix "${nf[@]}" build ".#$attr" --rebuild --no-link >/dev/null 2>"$root/target/nix-rebuild.log"; then
|
||||
echo "$attr is not reproducible: a rebuild gave other bytes" >&2
|
||||
cat "$root/target-nix-rebuild.log" >&2
|
||||
rm -f "$root/target-nix-rebuild.log"
|
||||
cat "$root/target/nix-rebuild.log" >&2
|
||||
rm -f "$root/target/nix-rebuild.log"
|
||||
exit 1
|
||||
fi
|
||||
rm -f "$root/target-nix-rebuild.log"
|
||||
rm -f "$root/target/nix-rebuild.log"
|
||||
nar=$(nix "${nf[@]}" path-info --json "$path" | jq -r 'if type == "array" then .[0].narHash else .[].narHash end')
|
||||
size=$(nix "${nf[@]}" path-info --json "$path" | jq -r 'if type == "array" then .[0].narSize else .[].narSize end')
|
||||
entries+=("$(jq -cn --arg a "$attr" --arg p "$path" --arg h "$nar" --argjson s "$size" \
|
||||
@@ -42,13 +55,16 @@ for attr in ianitor ianitor-web; do
|
||||
echo "$attr: $path $nar (rebuilt: identical)"
|
||||
done
|
||||
new=$(printf '%s\n' "${entries[@]}" | jq -s --arg v "$version" --arg sys "$system" \
|
||||
'{version: $v, system: $sys, outputs: add}')
|
||||
--arg c "$commit" --arg t "$tree" --arg n "$nixpkgs" \
|
||||
'{version: $v, system: $sys, commit: $c, sourceTree: $t, nixpkgs: $n, outputs: add}')
|
||||
|
||||
if [ "$mode" = --check ]; then
|
||||
[ -f "$pin" ] || { echo "no $pin to check" >&2; exit 1; }
|
||||
if [ "$(jq -S . "$pin")" != "$(jq -S . <<<"$new")" ]; then
|
||||
# At a tag the commit is the pin's child (only pin.json differs), so the commit itself is not
|
||||
# compared; the source tree, nixpkgs and every hash are.
|
||||
if [ "$(jq -S 'del(.commit)' "$pin")" != "$(jq -S 'del(.commit)' <<<"$new")" ]; then
|
||||
echo "the build differs from $pin:" >&2
|
||||
diff <(jq -S . "$pin") <(jq -S . <<<"$new") >&2 || true
|
||||
diff <(jq -S 'del(.commit)' "$pin") <(jq -S 'del(.commit)' <<<"$new") >&2 || true
|
||||
exit 1
|
||||
fi
|
||||
echo "matches $pin"
|
||||
|
||||
Reference in New Issue
Block a user