[fabrica] Layers and the verifiable build: the layers pipeline runs all five test layers on a NixOS runner with KVM, verify-nix rebuilds a tag and compares with its pin, the release publishes the Nix pin (ianitor-nix.json) under the signed SHA256SUMS; scripts for conformance, load and the pin; docs/verify.md

This commit is contained in:
2026-11-10 21:23:16 +01:00
parent 4692044099
commit 9ae721b79f
12 changed files with 485 additions and 3 deletions
+39
View File
@@ -0,0 +1,39 @@
# Ianitor Domi: the five test layers (ROADMAP §5) on a push to main, or by hand. Layer 1 (the differential
# suite against Caddy) runs inside the workspace tests; layer 2 is scripts/conformance.sh (h2spec, testssl.sh);
# layer 3 tests/fuzz/run.sh (cargo-fuzz, 2 minutes a target; any crash fails); layer 4 the NixOS VM tests;
# layer 5 scripts/bench.sh (load and a 5-minute soak against Caddy; results kept as artifacts).
# Runner: label `nixos`, on a host with /dev/kvm and Nix's `kvm` system feature (the VM tests; on Hyper-V,
# nested virtualisation on), outbound HTTPS (crates.io, cache.nixos.org) and about 20 GB free. Every tool comes
# from the flake's `ci` shell, so the runner needs only Nix with flakes.
name: layers
on:
push: [main]
manual: true
runner: nixos
env:
CARGO_TERM_COLOR: "never"
CARGO_BUILD_JOBS: "8"
steps:
- id: workspace-tests
run: nix --extra-experimental-features "nix-command flakes" develop .#ci -c cargo test --workspace --no-fail-fast
- id: conformance
needs: [workspace-tests]
run: nix --extra-experimental-features "nix-command flakes" develop .#ci -c scripts/conformance.sh
artifacts: ["bench/conformance/*"]
- id: fuzz
needs: [workspace-tests]
run: nix --extra-experimental-features "nix-command flakes" develop .#ci -c tests/fuzz/run.sh 120
- id: vm-apply-reverts
nix: .#checks.x86_64-linux.vm-apply-reverts
- id: vm-engine-switch
nix: .#checks.x86_64-linux.vm-engine-switch
- id: vm-intermediate-renewal
nix: .#checks.x86_64-linux.vm-intermediate-renewal
- id: vm-control-loopback
nix: .#checks.x86_64-linux.vm-control-loopback
- id: vm-sockets
nix: .#checks.x86_64-linux.vm-sockets
- id: load
needs: [conformance, fuzz]
run: nix --extra-experimental-features "nix-command flakes" develop .#ci -c scripts/bench.sh fabrica-runner
artifacts: ["bench/results/**"]
+9 -1
View File
@@ -6,6 +6,9 @@
# `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.
name: release
on:
tag: "v*"
@@ -29,8 +32,12 @@ steps:
needs: [check, test]
run: node apps/web/scripts/shots.mjs
artifacts: ["target/aula/aula-*.png", "target/aula/aula.json"]
- id: pin
needs: [version]
run: node scripts/release-pin.mjs ${{ version }} ${{ tag }} ${{ commit }}
artifacts: ["target/nix/ianitor-nix.json"]
- id: approve
needs: [version, notes, shots]
needs: [version, notes, shots, pin]
approve: "Publish Ianitor ${{ tag }}: its notes and screenshots?"
- id: publish
needs: [approve]
@@ -41,4 +48,5 @@ steps:
- "**/release-notes.json"
- "**/aula-*.png"
- "**/aula.json"
- "**/ianitor-nix.json"
sums: domi-release
+17
View File
@@ -0,0 +1,17 @@
# 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.
name: verify-nix
on:
tag: "v*"
manual: true
runner: nixos
steps:
- id: ianitor
nix: .#ianitor
- id: web
nix: .#ianitor-web
- id: pin
needs: [ianitor, web]
run: nix --extra-experimental-features "nix-command flakes" develop .#ci -c scripts/nix-pin.sh --check
+4 -1
View File
@@ -9,7 +9,8 @@
rustPlatform.buildRustPackage {
pname = "ianitor";
version = "0.1.0";
# One version, the workspace's (scripts/check-version.mjs checks the rest).
version = (lib.importTOML ../../Cargo.toml).workspace.package.version;
src = lib.fileset.toSource {
root = ../..;
@@ -19,6 +20,8 @@ rustPlatform.buildRustPackage {
../../crates
../../tests/diff
../../tests/support
# The fuzz crate is a workspace member; its cargo-fuzz project is not (own workspace).
(lib.fileset.difference ../../tests/fuzz ../../tests/fuzz/fuzz)
];
};
+1 -1
View File
@@ -8,7 +8,7 @@
stdenv.mkDerivation (finalAttrs: {
pname = "ianitor-web";
version = "0.1.0";
version = (lib.importJSON ../../apps/web/package.json).version;
src = lib.fileset.toSource {
root = ../..;
+2
View File
@@ -0,0 +1,2 @@
untrusted comment: minisign public key ABD87B469ADF4BE4
RWTkS9+aRnvYq1si0VvyJFeEJf7oQ3Dsadl0/fI64nuVIaz286PGiyPe
+78
View File
@@ -0,0 +1,78 @@
# 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.
## 1. The signature
The `domi-release` public key, key id `ABD87B469ADF4BE4` (also in [domi-release.pub](domi-release.pub)):
```text
untrusted comment: minisign public key ABD87B469ADF4BE4
RWTkS9+aRnvYq1si0VvyJFeEJf7oQ3Dsadl0/fI64nuVIaz286PGiyPe
```
Take it from a source you trust more than the release page itself (Custos → *Signing keys* → *Copy minisign.pub*,
or a clone of this repository you already had). Then, in a folder with the release's files:
```sh
minisign -Vm SHA256SUMS -p domi-release.pub # "Signature and comment signature verified"
sha256sum -c --ignore-missing SHA256SUMS # every downloaded file: OK
```
(`nix shell nixpkgs#minisign` if you have no minisign. Custos signs prehashed; minisign 0.10 and later verify it.)
## 2. The build
`ianitor-nix.json` names the commit and the hashes:
```json
{ "version": "1.0.0", "commit": "<40 hex>", "system": "x86_64-linux",
"outputs": { "ianitor": { "storePath": "/nix/store/…-ianitor-1.0.0", "narHash": "sha256-…" }, … } }
```
Build that commit and compare (Linux with Nix and flakes; nothing from Ianitor's own caches is needed):
```sh
c=$(jq -r .commit ianitor-nix.json)
for a in ianitor ianitor-web; do
p=$(nix build "git+https://gitea.marek-novak.cz/mnovak/Ianitor.git?rev=$c#$a" --no-link --print-out-paths)
got=$(nix path-info --json "$p" | jq -r 'if type == "array" then .[0].narHash else .[].narHash end')
want=$(jq -r ".outputs[\"$a\"].narHash" ianitor-nix.json)
[ "$got" = "$want" ] && echo "$a: $got matches" || echo "$a: MISMATCH (got $got, release says $want)"
done
```
The store path matches too (it depends only on the derivation, so it tells you the inputs were the same); the NAR
hash is the content. `nix build --rebuild` builds once more locally and fails if your own two builds differ.
On a server that uses the NixOS module, the running build is `services.ianitor.package`, normally
`ianitor.packages.x86_64-linux.ianitor` from the flake input pinned in the server's `flake.lock`: if that input's
`rev` is the release's commit, `nix path-info --json $(readlink -f /run/current-system/sw/bin/ianitor-edge | sed 's#/bin/.*##')`
gives the same NAR hash.
## What this does and does not prove
- **Proves:** the release's notes, screenshots and pin are the ones Mark approved and Custos signed; the code at the
pinned commit builds to exactly the pinned bytes, on any machine with the same nixpkgs (the flake.lock is part of
the commit).
- **Does not prove:** that the code is good (that is the five test layers' job, ROADMAP §5), nor anything about the
Nix binary cache you build with: a substituted dependency is trusted as Nix trusts it. `nix build --rebuild` and
`--option substitute false` narrow that, at the cost of building everything.
## For Mark: making the pin before a tag
On a Linux machine with Nix (WSL2 Debian works), at the commit to be tagged:
```sh
scripts/nix-pin.sh # builds twice, writes .fabrica/nix/pin.json
git add .fabrica/nix/pin.json && git commit -m "[repo] Release: the Nix pin of X.Y.Z"
```
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.
+25
View File
@@ -28,6 +28,31 @@
inherit self;
};
# The tools of the five test layers (ROADMAP §5), for scripts/*.sh, tests/fuzz/run.sh and the
# `layers` pipeline: `nix develop .#ci -c <command>`.
devShells = forAll (pkgs: {
ci = pkgs.mkShell {
packages = with pkgs; [
cargo
rustc
clippy
rustfmt
cargo-fuzz
cmake
pkg-config
git
jq
caddy
pebble
h2spec
testssl
oha
nodejs_22
pnpm_11
];
};
});
formatter = forAll (pkgs: pkgs.nixfmt-rfc-style);
};
}
+115
View File
@@ -0,0 +1,115 @@
#!/usr/bin/env bash
# This Source Code Form is subject to the terms of the Mozilla Public
# 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/.
#
# ROADMAP §5 layer 5: load and soak against Caddy, reproducible. Ianitor and two Caddys (as Go
# starts it, and GOMAXPROCS=2 to match edge's two Pingora worker threads) serve the same route
# (tests/diff/src/bin/pair.rs) to the same upstream; oha drives each in turn. Results are
# committed as data: bench/results/<date>-<label>.csv and the raw oha JSON beside it.
#
# scripts/bench.sh [label] # needs caddy, oha, jq on PATH
# nix shell nixpkgs#caddy nixpkgs#oha nixpkgs#jq -c scripts/bench.sh wsl2-ryzen
#
# Environment: DURATION (each load run, default 20s), SOAK (the soak run, default 300s; 0 skips
# it), CONNS (default "1 16 64 256"), BUILD (release or debug, default release).
# Everything listens on 127.0.0.1; the load generator shares the machine, so absolute numbers
# say more about the machine than the proxies: compare the rows, not the numbers across machines.
set -euo pipefail
root=$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)
label=${1:-$(hostname -s 2>/dev/null || echo local)}
duration=${DURATION:-20s}
soak=${SOAK:-300}
conns=${CONNS:-"1 16 64 256"}
profile=${BUILD:-release}
for tool in caddy oha jq; do
command -v "$tool" >/dev/null || { echo "missing: $tool" >&2; exit 2; }
done
flag=--release
[ "$profile" = debug ] && flag=
cargo build $flag -q -p ianitor-diff --bin ianitor-pair
bin="${CARGO_TARGET_DIR:-$root/target}/$profile/ianitor-pair"
stamp=$(date -u +%Y-%m-%d)
dir="$root/bench/results"
raw="$dir/$stamp-$label"
mkdir -p "$raw"
csv="$dir/$stamp-$label.csv"
info=$(mktemp)
"$bin" --caddy "$(command -v caddy)" >"$info" &
pair=$!
trap 'kill $pair 2>/dev/null; wait $pair 2>/dev/null; rm -f "$info"' EXIT
for _ in $(seq 1 100); do
[ -s "$info" ] && break
sleep 0.2
done
[ -s "$info" ] || { echo "ianitor-pair did not start" >&2; exit 1; }
# The machine, for the record.
{
echo "label: $label"
echo "date: $(date -u +%Y-%m-%dT%H:%M:%SZ)"
echo "kernel: $(uname -sr)"
grep -m1 'model name' /proc/cpuinfo 2>/dev/null | sed 's/^.*: /cpu: /' || true
echo "cpus: $(nproc)"
grep -m1 MemTotal /proc/meminfo 2>/dev/null | sed 's/^MemTotal: */memory: /' || true
grep -qi microsoft /proc/version 2>/dev/null && echo "virtualisation: WSL2" || true
echo "build: $(jq -r .build "$info"); edge worker threads: $(jq -r .edge_threads "$info")"
echo "caddy: $(jq -r .caddy_version "$info")"
echo "oha: $(oha --version 2>/dev/null | head -1)"
echo "duration: $duration per run; soak: ${soak}s"
} >"$raw/machine.txt"
# The process to sample for memory: edge runs inside ianitor-pair; each Caddy is a child of it.
pid_of() {
local port=$1
ss -Hltnp "sport = :$port" 2>/dev/null | grep -Eo 'pid=[0-9]+' | head -1 | cut -d= -f2
}
rss_kb() { awk '/VmRSS/ {print $2}' "/proc/$1/status" 2>/dev/null || echo 0; }
echo "engine,scenario,connections,duration_s,requests,rps,p50_ms,p90_ms,p99_ms,max_ms,success_rate,non_2xx,rss_kb_after" >"$csv"
run() { # engine scenario conns duration url [oha args...]
local engine=$1 scenario=$2 c=$3 d=$4 url=$5
shift 5
local file="$raw/$engine-$scenario-c$c.json"
oha --no-tui --insecure -j -c "$c" -z "$d" "$@" "$url" >"$file" 2>/dev/null || true
local pid
pid=$(pid_of "$(echo "$url" | sed -E 's#.*:([0-9]+)/.*#\1#')")
jq -r --arg e "$engine" --arg s "$scenario" --arg c "$c" --arg rss "$(rss_kb "${pid:-0}")" '
def ms: if . == null then "" else (. * 1000 * 100 | round / 100 | tostring) end;
[$e, $s, $c,
(.summary.total | . * 100 | round / 100 | tostring),
((.statusCodeDistribution // {}) | to_entries | map(.value) | add // 0 | tostring),
(.summary.requestsPerSec | round | tostring),
(.latencyPercentiles.p50 | ms), (.latencyPercentiles.p90 | ms), (.latencyPercentiles.p99 | ms),
(.summary.slowest | ms),
(.summary.successRate | tostring),
((.statusCodeDistribution // {}) | to_entries | map(select(.key | startswith("2") | not) | .value) | add // 0 | tostring),
$rss] | join(",")' "$file" >>"$csv"
tail -1 "$csv"
}
for engine in ianitor caddy caddy_gomaxprocs2; do
https=$(jq -r ".$engine.https" "$info")
http=$(jq -r ".$engine.http" "$info")
url="https://localhost:${https##*:}/"
for c in $conns; do
run "$engine" https-h1-keepalive "$c" "$duration" "$url"
run "$engine" https-h2 "$c" "$duration" "$url" --http2
done
# A new TLS connection per request: the handshake dominates.
run "$engine" https-h1-new-conn 16 "$duration" "$url" --disable-keepalive
# The plain-HTTP listener's redirect (no upstream).
run "$engine" http-redirect 64 "$duration" "http://localhost:${http##*:}/" --redirect 0
done
if [ "$soak" -gt 0 ]; then
for engine in ianitor caddy; do
https=$(jq -r ".$engine.https" "$info")
run "$engine" soak-https-h1 32 "${soak}s" "https://localhost:${https##*:}/"
done
fi
echo "results: $csv"
+79
View File
@@ -0,0 +1,79 @@
#!/usr/bin/env bash
# This Source Code Form is subject to the terms of the Mozilla Public
# 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/.
#
# ROADMAP §5 layer 2: protocol conformance, Ianitor and Caddy side by side on the same routes
# (tests/diff/src/bin/pair.rs): h2spec (HTTP/2, RFC 9113 and HPACK) and testssl.sh (TLS) against
# each. Raw outputs go to bench/conformance/<engine>-*.{txt,json}; the summary table to stdout.
#
# scripts/conformance.sh # needs caddy, h2spec, testssl.sh, jq on PATH
# nix shell nixpkgs#caddy nixpkgs#h2spec nixpkgs#testssl nixpkgs#jq -c scripts/conformance.sh
#
# Exit status: 1 if Ianitor fails an h2spec case Caddy passes, or testssl.sh rates Ianitor's
# TLS below Caddy's (a regression against the fallback); the rest is reported, not enforced.
# Everything listens on 127.0.0.1.
set -euo pipefail
root=$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)
out="$root/bench/conformance"
mkdir -p "$out"
for tool in caddy h2spec jq; do
command -v "$tool" >/dev/null || { echo "missing: $tool" >&2; exit 2; }
done
testssl=$(command -v testssl.sh || command -v testssl || true)
[ -n "$testssl" ] || { echo "missing: testssl.sh" >&2; exit 2; }
profile=${BUILD:-release}
flag=--release
[ "$profile" = debug ] && flag=
cargo build $flag -q -p ianitor-diff --bin ianitor-pair
bin="${CARGO_TARGET_DIR:-$root/target}/$profile/ianitor-pair"
info=$(mktemp)
"$bin" --caddy "$(command -v caddy)" >"$info" &
pair=$!
trap 'kill $pair 2>/dev/null; wait $pair 2>/dev/null; rm -f "$info"' EXIT
for _ in $(seq 1 100); do
[ -s "$info" ] && break
sleep 0.2
done
[ -s "$info" ] || { echo "ianitor-pair did not start" >&2; exit 1; }
port() { jq -r ".$1.https" "$info" | sed 's/.*://'; }
status=0
printf '%-10s %-8s %s\n' engine tool result
for engine in ianitor caddy; do
p=$(port "$engine")
# h2spec names the host for SNI; `localhost` is the pair's only host.
h2spec -h localhost -p "$p" -t -k -o 5 >"$out/$engine-h2spec.txt" 2>&1 || true
summary=$(grep -Eo '[0-9]+ tests, [0-9]+ passed, [0-9]+ skipped, [0-9]+ failed' "$out/$engine-h2spec.txt" | tail -1)
printf '%-10s %-8s %s\n' "$engine" h2spec "${summary:-no summary (see $out/$engine-h2spec.txt)}"
# The failed cases, by id, for the comparison below.
grep -E '^\s+×' -B0 "$out/$engine-h2spec.txt" | sed -E 's/^\s+× //' | sort >"$out/$engine-h2spec-failed.txt" || true
"$testssl" --quiet --color 0 --warnings off --ip 127.0.0.1 --add-ca "$(jq -r .ca "$info")" \
--jsonfile "$out/$engine-testssl.json" --overwrite "https://localhost:$p" \
>"$out/$engine-testssl.txt" 2>&1 || true
grade=$(jq -r '[.[] | select(.id=="overall_grade")][0].finding // "n/a"' "$out/$engine-testssl.json" 2>/dev/null || echo n/a)
bad=$(jq -r '[.[] | select(.severity=="HIGH" or .severity=="CRITICAL")] | length' "$out/$engine-testssl.json" 2>/dev/null || echo "?")
printf '%-10s %-8s %s\n' "$engine" testssl "grade $grade, $bad findings HIGH or CRITICAL"
done
# A case Caddy passes and Ianitor fails is a regression against the fallback.
regressions=$(comm -23 "$out/ianitor-h2spec-failed.txt" "$out/caddy-h2spec-failed.txt" || true)
if [ -n "$regressions" ]; then
echo "h2spec cases Ianitor fails and Caddy passes:" >&2
echo "$regressions" >&2
status=1
fi
rank() { case "$1" in A+) echo 7;; A) echo 6;; A-) echo 5;; B) echo 4;; C) echo 3;; D) echo 2;; E) echo 1;; *) echo 0;; esac; }
gi=$(jq -r '[.[] | select(.id=="overall_grade")][0].finding // ""' "$out/ianitor-testssl.json" 2>/dev/null || true)
gc=$(jq -r '[.[] | select(.id=="overall_grade")][0].finding // ""' "$out/caddy-testssl.json" 2>/dev/null || true)
if [ "$(rank "$gi")" -lt "$(rank "$gc")" ]; then
echo "testssl.sh grades Ianitor ($gi) below Caddy ($gc)" >&2
status=1
fi
jq -c '{build, caddy_version, edge_threads}' "$info" >"$out/run.json"
exit $status
+59
View File
@@ -0,0 +1,59 @@
#!/usr/bin/env bash
# This Source Code Form is subject to the terms of the Mozilla Public
# 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.
#
# 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
#
# Linux with Nix (flakes). The pin lies outside every package's source, so committing it does not
# change what it pins.
set -euo pipefail
root=$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)
cd "$root"
mode=${1:-write}
pin=.fabrica/nix/pin.json
nf=(--extra-experimental-features "nix-command flakes")
system=$(nix "${nf[@]}" eval --raw --impure --expr builtins.currentSystem)
version=$(sed -n '/^\[workspace.package\]/,/^\[/s/^version = "\(.*\)"/\1/p' Cargo.toml)
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
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"
exit 1
fi
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" \
'{($a): {storePath: $p, narHash: $h, narSize: $s}}')")
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}')
if [ "$mode" = --check ]; then
[ -f "$pin" ] || { echo "no $pin to check" >&2; exit 1; }
if [ "$(jq -S . "$pin")" != "$(jq -S . <<<"$new")" ]; then
echo "the build differs from $pin:" >&2
diff <(jq -S . "$pin") <(jq -S . <<<"$new") >&2 || true
exit 1
fi
echo "matches $pin"
else
mkdir -p "$(dirname "$pin")"
jq -S . <<<"$new" >"$pin"
echo "wrote $pin"
fi
+57
View File
@@ -0,0 +1,57 @@
// This Source Code Form is subject to the terms of the Mozilla Public
// 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 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.
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>");
process.exit(2);
}
let pin;
try {
pin = JSON.parse(readFileSync(join(repo, ".fabrica/nix/pin.json"), "utf8"));
} 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);
}
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);
}
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);
}
}
const out = {
name: "Ianitor Domi",
version,
tag,
commit,
flake: `git+https://gitea.marek-novak.cz/mnovak/Ianitor.git?rev=${commit}`,
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}`);