[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:
2026-11-22 18:49:35 +01:00
parent 43a0dfdadc
commit b492ccf5f9
8 changed files with 140 additions and 59 deletions
+4 -3
View File
@@ -6,9 +6,10 @@
# `notes` is Fabrica's release notes since the previous v* tag (Fabrica docs/12_release_kit.md); `shots` takes the
# same files as `fabrica aula shots` (core docs/FORMATS.md, "Fabrica: the Aula page") from the built web UI against
# the demo control plane with invented data, in headless Edge. No landing page while app.yaml has no `aula: true`.
# `pin` publishes the Nix build's NAR hashes (.fabrica/nix/pin.json, written by scripts/nix-pin.sh on Linux and
# committed before the tag) with the tag's commit as ianitor-nix.json, so SHA256SUMS also vouches for the build
# anyone can repeat (docs/verify.md); the `verify-nix` pipeline rebuilds the tag on the NixOS runner and compares.
# `pin` publishes the Nix build's NAR hashes (.fabrica/nix/pin.json, written by scripts/nix-pin.sh on Linux at a
# clean commit and committed before the tag) as ianitor-nix.json, and refuses a pin made from other code than the
# tag's (its recorded source tree must be the tag's); that check is the gate, since pipelines cannot depend on one
# another. The `verify-nix` pipeline rebuilds the tag on the NixOS runner and compares (docs/verify.md).
name: release
on:
tag: "v*"
+4 -3
View File
@@ -1,7 +1,8 @@
# Ianitor Domi: the verifiable build (docs/verify.md). On a v* tag the NixOS runner builds .#ianitor and
# .#ianitor-web from the tag (the run record keeps each output's store path and NAR hash), builds them again
# from scratch, and compares with the pin the release publishes (.fabrica/nix/pin.json at the tag); any
# difference fails the run. Runner: label `nixos`, Nix with flakes; no KVM needed.
# .#ianitor-web from the tag (the run record keeps each output's store path and NAR hash), rebuilds each output
# derivation once more, and compares with the pin the release publishes (.fabrica/nix/pin.json at the tag: the
# source tree, nixpkgs and every hash); any difference fails the run. Runner: label `nixos`, Nix with flakes,
# node and jq from the `ci` shell; no KVM needed.
name: verify-nix
on:
tag: "v*"
+3 -1
View File
@@ -80,7 +80,9 @@ support is best effort), Caddy and Pebble on PATH: `nix develop .#ci`.
A release is a signed manifest, not a binary: `SHA256SUMS` signed by `domi-release` (through Custos) over the
release notes, screenshots of the UI and `ianitor-nix.json`, the NAR hashes of the Nix build at the tagged commit.
The build is reproducible, so anyone can rebuild the tag and compare: [docs/verify.md](docs/verify.md).
Anyone can rebuild the pinned commit and compare the hashes: [docs/verify.md](docs/verify.md). What is checked
so far is narrower than "reproducible": the output derivations are rebuilt once and compared, with dependencies
from the binary cache, and that has not run yet; the first pin needs a machine with Nix.
## Support
+3 -2
View File
@@ -38,8 +38,9 @@ how it is run, not for a number.
## Verifiable, and signed
Every release is a `SHA256SUMS` signed through Custos with my release key, over the notes, screenshots of the UI,
and the NAR hashes of the Nix build. The build is reproducible: rebuild the tag and you get the same bytes
(docs/verify.md tells you how).
and the NAR hashes of the Nix build. Rebuild the pinned commit and compare (docs/verify.md tells you how).
[Before posting: say "reproducible" only once two independent builds have matched; until then, what is checked is
one rebuild of the output derivations, with dependencies from the binary cache.]
## Five test layers
+7 -4
View File
@@ -22,15 +22,18 @@ are on every step's PATH).
| `check`, `test` | `svelte-check` and the vitest click smoke test of the web UI the shots show | |
| `notes` | `fabrica notes` (the range since the previous `v*` tag; the first release covers the whole history) | `target/notes/release-notes.md`, `release-notes.json` |
| `shots` | `node apps/web/scripts/shots.mjs` (below) | `target/aula/aula-<name>.png`, `aula.json` |
| `pin` | `node scripts/release-pin.mjs <version> <tag> <commit>`: the Nix pin committed before the tag (`.fabrica/nix/pin.json`, by `scripts/nix-pin.sh` on Linux) with the tag and commit; refuses a pin of another version | `target/nix/ianitor-nix.json` |
| `pin` | `node scripts/release-pin.mjs <version> <tag> <commit>`: the Nix pin committed before the tag (`.fabrica/nix/pin.json`, by `scripts/nix-pin.sh` on Linux); refuses a missing pin, a pin of another version, and one made from other code than the tag's; publishes the pinned commit | `target/nix/ianitor-nix.json` |
| `approve` | the run's Custos approval, before anything is published | |
| `publish` | the Gitea release of the tag: the notes, the shots, `aula.json` and `ianitor-nix.json`; `sums: domi-release` adds `SHA256SUMS` and `SHA256SUMS.minisig`; `release-notes.md` becomes the release's text | |
**The Nix build is pinned, not shipped.** The Windows runner has no Nix and Fabrica's `SHA256SUMS` covers only the
files of one `publish` step, so the release cannot carry a build made by the NixOS runner. It carries the build's
NAR hashes instead (`ianitor-nix.json`, under the signed `SHA256SUMS`), and the build is reproducible: anyone
rebuilds the tag and compares ([verify.md](verify.md)); the `verify-nix` pipeline does exactly that on every
`v*` tag on the NixOS runner.
NAR hashes instead (`ianitor-nix.json`, under the signed `SHA256SUMS`): anyone rebuilds the pinned commit and
compares ([verify.md](verify.md)), and the `verify-nix` pipeline does that on every `v*` tag on the NixOS runner.
The `pin` step refuses a pin made from other code than the tag's (its source tree must match), which is the gate:
Fabrica pipelines cannot depend on one another, so `publish` cannot wait for `verify-nix`. What "reproducible"
covers so far: the output derivations are rebuilt once and compared; their dependencies come from the binary
cache. Nothing of it has run yet (no machine with Nix in phase 4); the first pin needs one.
The Rust tests are not in it: the edge, diff and ACME tests are Linux-only (ROADMAP §8.3) and the release builds
nothing. They run in WSL2 and in the Nix build.
+21 -12
View File
@@ -1,12 +1,15 @@
# Verifying a release
Every Ianitor release on Gitea (`vX.Y.Z`) carries `SHA256SUMS` and `SHA256SUMS.minisig`, signed through Custos by
the `domi-release` key, and among the files that `SHA256SUMS` lists, `ianitor-nix.json`: the tag's commit and the
NAR hash of every Nix output (`.#ianitor`, the two binaries; `.#ianitor-web`, the built UI). Ianitor ships no
binary download: you build the tag yourself (or your server does, through the NixOS module) and check that you got
exactly the bytes the release vouches for. The build is reproducible: `scripts/nix-pin.sh` builds each output twice
from scratch and refuses to pin one whose bytes differ, and the `verify-nix` pipeline rebuilds every tag on the
NixOS runner and compares.
the `domi-release` key, and among the files that `SHA256SUMS` lists, `ianitor-nix.json`: the commit the build was
made from and the NAR hash of every Nix output (`.#ianitor`, the two binaries; `.#ianitor-web`, the built UI).
Ianitor ships no binary download: you build that commit yourself (or your server does, through the NixOS module)
and check that you got exactly the bytes the release vouches for.
What is checked, and what is not yet: `scripts/nix-pin.sh` builds each output, then rebuilds the output derivation itself once more (`nix build --rebuild`) and refuses to pin it if the two differ; the dependencies come from the binary cache and are not rebuilt. The `verify-nix` pipeline does the same on the NixOS
runner for every tag. **None of this has run yet:** the first pin needs a Linux machine with Nix, and the
development machine has had none since phase 4 began, so no release so far carries a pin and nothing here is
shown reproducible across machines until two independent builds have matched.
## 1. The signature
@@ -29,10 +32,11 @@ sha256sum -c --ignore-missing SHA256SUMS # every downloaded file: OK
## 2. The build
`ianitor-nix.json` names the commit and the hashes:
`ianitor-nix.json` names the commit the hashes were built from (`commit`; the tag's own commit, `taggedCommit`,
differs from it at most by the pin file), the nixpkgs revision of its flake.lock, and the hashes:
```json
{ "version": "1.0.0", "commit": "<40 hex>", "system": "x86_64-linux",
{ "version": "1.0.0", "commit": "<40 hex>", "taggedCommit": "<40 hex>", "nixpkgs": "<40 hex>", "system": "x86_64-linux",
"outputs": { "ianitor": { "storePath": "/nix/store/…-ianitor-1.0.0", "narHash": "sha256-…" }, … } }
```
@@ -67,12 +71,17 @@ gives the same NAR hash.
## For Mark: making the pin before a tag
On a Linux machine with Nix (WSL2 Debian works), at the commit to be tagged:
On a Linux machine with Nix, at a clean commit, the last one before the tag:
```sh
scripts/nix-pin.sh # builds twice, writes .fabrica/nix/pin.json
scripts/nix-pin.sh # builds, rebuilds the outputs, writes .fabrica/nix/pin.json
git add .fabrica/nix/pin.json && git commit -m "[repo] Release: the Nix pin of X.Y.Z"
git tag vX.Y.Z # on that commit: it differs from the pinned one only by the pin
```
The pin lies outside every package's source, so the commit does not change what it pins. The `release` pipeline's
`pin` step refuses a pin of another version, so a forgotten pin stops the release before anything is published.
The pin records its commit and that commit's source tree (every tracked file but the pin itself). The `release`
pipeline's `pin` step (`scripts/release-pin.mjs`) refuses a missing pin, a pin of another version, and a pin whose
source tree is not the tagged commit's: so "pin at A, fixes land at B, tag B" stops the release before anything is
published, and the pin has to be made again at B. That check is the gate: Fabrica's pipelines cannot depend on
each other, so `publish` cannot wait for `verify-nix`, which runs on the same tag as an independent second
build.
+28 -12
View File
@@ -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"
+70 -22
View File
@@ -3,55 +3,103 @@
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
// The release's Nix pin (docs/verify.md): .fabrica/nix/pin.json, written by scripts/nix-pin.sh on
// Linux and committed before tagging, becomes target/nix/ianitor-nix.json with the tag and the
// commit, published under SHA256SUMS signed by domi-release. Refuses a pin of another version.
// node scripts/release-pin.mjs <X.Y.Z> <tag> <commit>
// Exit codes: 0 written, 1 no pin or a pin of another version, 2 usage.
// Linux at a clean commit and committed before tagging, becomes target/nix/ianitor-nix.json,
// published under SHA256SUMS signed by domi-release.
//
// The pin is a claim about the code it was built from, so it is refused unless the tagged commit
// holds exactly that code: its source tree (every tracked file except pin.json itself) must be
// the one the pin recorded. That is `git diff --name-only <pinned> <tag>` being empty or only
// pin.json, checked without the pinned commit's history (a runner's clone is shallow). The
// published file names the commit the hashes were built from, not the tag's.
//
// node scripts/release-pin.mjs <X.Y.Z> <tag> <commit> write target/nix/ianitor-nix.json
// node scripts/release-pin.mjs --source-tree <commit> print that commit's source-tree hash
// $IANITOR_REPO names another repository (tests). Exit codes: 0 written, 1 refused, 2 usage.
import { execFileSync } from "node:child_process";
import { createHash } from "node:crypto";
import { mkdirSync, readFileSync, writeFileSync } from "node:fs";
import { dirname, join, resolve } from "node:path";
import { fileURLToPath } from "node:url";
const repo = resolve(dirname(fileURLToPath(import.meta.url)), "..");
const [version, tag, commit] = process.argv.slice(2);
if (
process.argv.length !== 5 ||
!/^\d+\.\d+\.\d+$/.test(version) ||
!/^[0-9a-f]{40}$/.test(commit ?? "")
) {
console.error("usage: node scripts/release-pin.mjs <X.Y.Z> <tag> <commit sha>");
const PIN = ".fabrica/nix/pin.json";
const repo = process.env.IANITOR_REPO
? resolve(process.env.IANITOR_REPO)
: resolve(dirname(fileURLToPath(import.meta.url)), "..");
function git(...args) {
return execFileSync("git", args, { cwd: repo, encoding: "utf8", maxBuffer: 64 << 20 });
}
/// The source tree of a commit: sha256 over `git ls-tree -r --full-tree` without the pin's line.
export function sourceTree(commit) {
const lines = git("ls-tree", "-r", "--full-tree", commit)
.split("\n")
.filter((l) => l && !l.endsWith(`\t${PIN}`));
return createHash("sha256").update(lines.join("\n") + "\n").digest("hex");
}
function fail(msg) {
console.error(msg);
process.exit(1);
}
const args = process.argv.slice(2);
if (args[0] === "--source-tree" && args.length === 2) {
try {
console.log(sourceTree(args[1]));
} catch (e) {
fail(`cannot read the tree of ${args[1]}: ${e.message}`);
}
process.exit(0);
}
const [version, tag, commit] = args;
if (args.length !== 3 || !/^\d+\.\d+\.\d+$/.test(version) || !/^[0-9a-f]{40}$/.test(commit ?? "")) {
console.error("usage: node scripts/release-pin.mjs <X.Y.Z> <tag> <commit sha> | --source-tree <commit>");
process.exit(2);
}
let pin;
try {
pin = JSON.parse(readFileSync(join(repo, ".fabrica/nix/pin.json"), "utf8"));
pin = JSON.parse(git("show", `${commit}:${PIN}`));
} catch (e) {
console.error(`no usable .fabrica/nix/pin.json (run scripts/nix-pin.sh on Linux and commit it): ${e.message}`);
process.exit(1);
fail(`no usable ${PIN} at ${commit} (run scripts/nix-pin.sh on Linux and commit it): ${e.message.split("\n")[0]}`);
}
if (pin.version !== version) {
console.error(`.fabrica/nix/pin.json is for ${pin.version}, the tag is ${version}: run scripts/nix-pin.sh again`);
process.exit(1);
fail(`${PIN} is for ${pin.version}, the tag is ${version}: run scripts/nix-pin.sh again`);
}
if (!/^[0-9a-f]{40}$/.test(pin.commit ?? "") || !/^[0-9a-f]{64}$/.test(pin.sourceTree ?? "")) {
fail(`${PIN} names no commit and source tree (made by an older nix-pin.sh): run scripts/nix-pin.sh again`);
}
for (const attr of ["ianitor", "ianitor-web"]) {
const o = pin.outputs?.[attr];
if (!o || !/^\/nix\/store\/[0-9a-z]{32}-/.test(o.storePath) || !/^sha256[-:][A-Za-z0-9+/=]{43,52}$/.test(o.narHash)) {
console.error(`.fabrica/nix/pin.json: ${attr} has no store path and NAR hash`);
process.exit(1);
fail(`${PIN}: ${attr} has no store path and NAR hash`);
}
}
const here = sourceTree(commit);
if (here !== pin.sourceTree) {
fail(
`${PIN} was made at ${pin.commit}, and ${tag} (${commit}) is not the code of that commit ` +
`(its files differ beyond pin.json): run scripts/nix-pin.sh at the commit to tag`,
);
}
const out = {
name: "Ianitor Domi",
version,
tag,
commit,
flake: `git+https://gitea.marek-novak.cz/mnovak/Ianitor.git?rev=${commit}`,
// The commit the hashes were built from; the tag's own commit differs at most by pin.json.
commit: pin.commit,
taggedCommit: commit,
sourceTree: pin.sourceTree,
flake: `git+https://gitea.marek-novak.cz/mnovak/Ianitor.git?rev=${pin.commit}`,
nixpkgs: pin.nixpkgs ?? null,
system: pin.system,
outputs: pin.outputs,
verify: "docs/verify.md",
};
mkdirSync(join(repo, "target/nix"), { recursive: true });
writeFileSync(join(repo, "target/nix/ianitor-nix.json"), JSON.stringify(out, null, 2) + "\n");
console.log(`target/nix/ianitor-nix.json: ${version} at ${commit}`);
console.log(`target/nix/ianitor-nix.json: ${version}, built from ${pin.commit}, tagged at ${commit}`);