cuda-release-lab
01cuda-release-lab · 2026-12-05

CUDA releases, from NVIDIA's manifest to a signed Nix cache, decided in Bend

A release pipeline for CUDA in Nix, the job's subject, built small and run whole: NVIDIA's own redist manifests (CUDA 13.4.3 and 13.5.0) go through a watcher, pins, two builders, a signed binary cache and a client that compiles a kernel with nvcc. Seven NixOS VMs on one workstation, on a network with no route out: nothing rented, no remote server. Every decision the pipeline makes (is this release newer, does the tarball match its manifest, did both builders agree, does this toolkit run on that driver, may the channel move) is a function in Bend with laws, proven and rechecked by a Lean-verified kernel; Nix and shell only fetch, build, copy and serve.

7 VMsredist, forge, ci, build1, build2, cache, client: one NixOS test, on olimpo (no /dev/kvm: QEMU emulates)donecuda-release-lab (github.com/hhefesto/cuda-release-lab), nix/lab.nix, infra/topology.nix
5 / 5drills run in the VMs, each a must-fail with its real output (slides 9-10)measuredthe lab's run on olimpo (nix build .#checks.x86_64-linux.lab; result/drills/), 2026-12-05, commit 10a6770, 700 s under QEMU's emulation
44laws of the release logic, proven in Bend and rechecked by BendTT's kernel (--verdict)provedcuda-release-lab (github.com/hhefesto/cuda-release-lab), LAWS.bend, PROOF.bend, spec/Release.bend
3 × same NAReach toolkit (13.4.3, 13.5.0) built on olimpo, build1 and build2: one NAR hash per release, three builds eachmeasuredthe lab's run on olimpo (nix build .#checks.x86_64-linux.lab; result/drills/), 2026-12-05, commit 10a6770, 700 s under QEMU's emulation; nix path-info on olimpo

decided"no rented or remote server (all in a net of local VMs)"; and, olimpo's BIOS having virtualization off: "work with what you currently have".the owner, 2026-12-05

Each claim is marked: done (built and committed), proved (Bend's checker and the BendTT kernel accept it), tested (a check that runs), measured (a run's output, quoted), claimed (a document says so), open, lead (proposed), decided. Keys: → or space for next, ← back, a for all slides.

02The job

What the posting asks, and the part of the lab that shows it

the posting asks forthe lab
Nix packages for the CUDA Toolkit, cuDNN and TensorRT: dependencies, compatibility, reproducibilitynix/toolkit.nix: a toolkit (nvcc, cudart, crt, nvvm, cccl, cuobjdump) built from NVIDIA's linux-x86_64 tarballs, each fixed by its manifest's sha256; ELF files patched to the store (libcuda.so.1, the driver's, the one library allowed missing); two builds compared byte for byte.
Automation from a new release to a generated, tested and delivered packagecrl cycle on ci: sees a new release on redist, diffs its manifest, checks every tarball, writes the pins (pins/X.Y.Z.nix) and pushes them to forge, builds on both builders, compiles the sample, checks the driver, and only then moves the channel on cache.
Clear diagnostics, recovery from failuresFive drills (slides 9-10): a wrong hash, a toolkit too new for a driver, two builders that disagree, an unsigned path, a rollback, each with the message it prints, word for word. Every gate names what failed and why.
Binary caches and artifact repositoriescache: harmonia signing with the lab's key; the client takes nothing else. The channel (current, history) is a file the cache serves, moved only by crl.
CUDA driver and runtime compatibilitycompat in spec/Release.bend: NVIDIA's minor version compatibility (13.x on R580 and newer) and each release's own driver branch, from NVIDIA's manifests, with laws.
Contributing upstream to nixpkgsThe pins are NVIDIA's manifests in nixpkgs' own vocabulary (redistrib_X.Y.Z.json, the same files nixpkgs keeps); the lab's base is the nixpkgs olimpo runs, whose cudaPackages already has 13.5. No PR is opened without the owner's OK.
NVIDIA, JR2029346 (nvidia.wd5.myworkdayjobs.com; discourse.nixos.org/t/81349)

claimedThe posting: remote US, 12+ years, strong nixpkgs experience; binary caches and CUDA driver/runtime compatibility named as pluses. One listing gave Nov 23, 2026 as the date applications were accepted until: whether it is still open is not checked here.NVIDIA, JR2029346 (nvidia.wd5.myworkdayjobs.com; discourse.nixos.org/t/81349)

03The flow

A release, from NVIDIA's site to a client's nvcc

NVIDIAthe lab's pipelinedeliveryredistmanifests, tarballscicrl cycle (Bend)forgegit: the pinsbuild1nix-store --realisebuild2the same derivationcacheharmonia, signedclientdriver R580; nvcc11manifestSTEP 1 / 71. NVIDIA publishes CUDA 13.5.0: redistrib_13.5.0.json and its tarballs appear on redist. crl cycle sees arelease newer than the channel's, reads the manifest (six packages), says what changed, fetches every tarballand checks each against its manifest's sha256. A wrong one stops the release here (drill 1).22pinsSTEP 2 / 72. crl pins writes pins/13.5.0.nix from the manifest; ci commits it and pushes it to forge: the builders buildfrom it.33buildSTEP 3 / 73. Over ssh, build1 realises the toolkit's derivation: its fixed-output fetches go to redist (the tarballs arenot in its store), then the tree is unpacked and patched.44buildSTEP 4 / 74. build2 does the same at the same time. ci compares the two outputs' NAR hashes: different bytes stop therelease (drill 3). build1 also compiles the sample with the new nvcc.55promoteSTEP 5 / 75. Every gate passed and the release is newer: crl moves the channel. The cache copies the toolkit from build1and signs it with the lab's key as it serves it.66signedSTEP 6 / 76. The client reads the channel, checks the toolkit against its driver (13.5 on R580: minor versioncompatibility), fetches it with signatures required, and compiles a kernel to sm_90 SASS.77✕unsignedSTEP 7 / 7 · REFUSED7. build2's harmonia signs nothing: the client refuses its paths (drill 4).
The 7 steps, in words
  1. manifest: NVIDIA publishes CUDA 13.5.0: redistrib_13.5.0.json and its tarballs appear on redist. crl cycle sees a release newer than the channel's, reads the manifest (six packages), says what changed, fetches every tarball and checks each against its manifest's sha256. A wrong one stops the release here (drill 1).
  2. pins: crl pins writes pins/13.5.0.nix from the manifest; ci commits it and pushes it to forge: the builders build from it.
  3. build: Over ssh, build1 realises the toolkit's derivation: its fixed-output fetches go to redist (the tarballs are not in its store), then the tree is unpacked and patched.
  4. build: build2 does the same at the same time. ci compares the two outputs' NAR hashes: different bytes stop the release (drill 3). build1 also compiles the sample with the new nvcc.
  5. promote: Every gate passed and the release is newer: crl moves the channel. The cache copies the toolkit from build1 and signs it with the lab's key as it serves it.
  6. signed: The client reads the channel, checks the toolkit against its driver (13.5 on R580: minor version compatibility), fetches it with signatures required, and compiles a kernel to sm_90 SASS.
  7. unsigned: build2's harmonia signs nothing: the client refuses its paths (drill 4).
cuda-release-lab (github.com/hhefesto/cuda-release-lab), nix/lab.nix, spec/crl.bend

measuredThis flow ran: CUDA 13.4.3, then 13.5.0, went through it in the VMs (slide 8).the lab's run on olimpo (nix build .#checks.x86_64-linux.lab; result/drills/), 2026-12-05, commit 10a6770, 700 s under QEMU's emulation

04The machines

One source of truth: infra/topology.nix

The releases the lab carries, the packages it builds, the clients' driver and the seven machines are written once. flake.nix builds the toolkits and checks the pins from it; nix/lab.nix makes the VMs and the configs crl reads from it.

{ releases = [ "13.4.3" "13.5.0" ];             # NVIDIA's manifests, redist/redistrib_X.Y.Z.json
  packages = [ "cccl" "cuda_crt" "cuda_cudart" "cuda_cuobjdump" "cuda_nvcc" "libnvvm" ];
  clientDriver = "580.95.05";                     # checked by compat (spec/Release.bend)
  vms = { redist = ...; forge = ...; ci = ...; build1 = ...; build2 = ...; cache = ...; client = ...; };
}
VMRAMwhat it runs
redist512 MiBnginx: NVIDIA's layout, redistrib_X.Y.Z.json beside <pkg>/linux-x86_64/<tarball>; redist-publish puts a release on it (or a tampered one).
forge512 MiBgit daemon: the lab's upstream; ci pushes each release's pins.
ci1 GiBcrl cycle, crl build, crl back: the pipeline, in Bend (spec/crl.bend).
build1, build21.5 GiB eachNix builders over ssh: lab-build clones forge, evaluates nix/build.nix with the release's pins (nixpkgs and the build tools are in their stores; the tarballs and the toolkit are not), and builds; harmonia, unsigned.
cache1 GiBharmonia signing with lab-cache-1; nginx serves the channel (current, history).
client1.5 GiBcrl client: takes only paths signed by lab-cache-1 (require-sigs), checks its driver, compiles with nvcc.
cuda-release-lab (github.com/hhefesto/cuda-release-lab), infra/topology.nix, nix/lab.nix

decidedNo KVM: olimpo's BIOS has SVM off ("SVM disabled (by BIOS)" in its kernel log), so QEMU emulates every instruction (TCG). The lab runs anyway, slowly; turning SVM on in the BIOS speeds it up with no change to the lab.olimpo's journalctl -k, 2026-12-05; the owner: "work with what you currently have"

05The package

A toolkit from NVIDIA's tarballs: nix/toolkit.nix

The pins (pins/13.5.0.nix) are what crl pins writes from NVIDIA's manifest: for each package its version, its path under NVIDIA's redist, its sha256 and size. The toolkit fetches each tarball by that hash (from NVIDIA's site, or from the lab's redist: the hash fixes the bytes either way), unpacks all six into one tree, the layout nvcc.profile expects, patches every ELF file to the Nix store, and wraps nvcc with its host compiler.

# Written by `crl pins` from NVIDIA's redistrib_13.5.0.json: do not edit.
{
  release = "13.5.0";
  date = "2026-11-04";
  packages = {
    cccl = { version = "13.3.5.0.6"; path = "cccl/linux-x86_64/cccl-linux-x86_64-13.3.5.0.6-archive.tar.xz"; sha256 = "5139f641e72df6b0c64ee9e68cabaeafa9a5e36a4b1f7d370a1dc0dac62dd72f"; size = 1486800; };
    cuda_crt = { version = "13.5.37"; path = "cuda_crt/linux-x86_64/cuda_crt-linux-x86_64-13.5.37-archive.tar.xz"; sha256 = "0df5c0ca27392152f370751c82b27ff1ab67661e4810cfc7248e2e03479c9ae0"; size = 109348; };
    cuda_cudart = { version = "13.5.37"; path = "cuda_cudart/linux-x86_64/cuda_cudart-linux-x86_64-13.5.37-archive.tar.xz"; sha256 = "26ca1b8963ce1b73e0e77113c711730545cacaaee7233c0526477d96d4c621fe"; size = 1694180; };
    cuda_cuobjdump = { version = "13.5.37"; path = "cuda_cuobjdump/linux-x86_64/cuda_cuobjdump-linux-x86_64-13.5.37-archive.tar.xz"; sha256 = "cef2d02c05b3f6300ac8972ddb960feb899e614575476bf45dbbdf70c330d2ae"; size = 245392; };
… 2 lines cut …
  };
}
stepwhat went wrong first, and the fix
linkld: cannot find -lcudadevrt, -lcudart_static: nvcc.profile links from lib64, the tarballs ship lib. The fix: ln -s lib $out/lib64.
patchautoPatchelfHook finds every library in the store but one: libcuda.so.1, the driver's, which comes from the machine at run time; the only autoPatchelfIgnoreMissingDeps.
licenceCUDA is unfree: allowed for the lab's toolkit by name (allowUnfreePredicate), nothing else.
cuda-release-lab (github.com/hhefesto/cuda-release-lab), nix/toolkit.nix; the first build's log, olimpo 2026-12-05
$ nvcc --version
… 3 lines cut …
Cuda compilation tools, release 13.5, V13.5.37
Build cuda_13.5.r13.5/compiler.39125733_0
$ nvcc -arch=sm_90 -o hello sample/hello.cu && cuobjdump --list-elf hello
ELF file    1: hello.1.sm_90.cubin
ELF file    2: hello.2.sm_90.cubin
$ ./hello
cudart 13050, driver 0, devices 0: CUDA driver version is insufficient for CUDA runtime version

measuredBuilt on olimpo for 13.4.3 and 13.5.0: nvcc reports release 13.4, V13.4.92 and release 13.5, V13.5.37, compiles the sample to sm_90 SASS (cuobjdump lists two sm_90 cubins), and the binary starts: with no GPU and no driver it reports cudart 13050, driver 0. A rebuild of the 13.5.0 toolkit gave the same NAR hash.cuda-release-lab (github.com/hhefesto/cuda-release-lab), nix/sample.nix; .#sample-13_5_0, .#sample-13_4_3, nix build --rebuild .#toolkit-13_5_0

toolkitolimpo (the host)build1 (a VM)build2 (a VM)
13.4.3sha256:11psb4zh…xald6absha256:11psb4zh…xald6absha256:11psb4zh…xald6ab
13.5.0sha256:1pgy9b93…hxb48xm6sha256:1pgy9b93…hxb48xm6sha256:1pgy9b93…hxb48xm6
the lab's run on olimpo (nix build .#checks.x86_64-linux.lab; result/drills/), 2026-12-05, commit 10a6770, 700 s under QEMU's emulation; olimpo's nix path-info, converted to nix32
06Compatibility

Does this toolkit run on that driver? NVIDIA's rules, as a function

Minor version compatibility: an application built with any CUDA 13.x runs on a driver of branch 580 or newer, with a limited feature set (PTX newer than the driver can't be JIT-compiled, so it must carry SASS for its GPU). A toolkit's own features need its own branch. compat answers full, minor, or refused, with the reason, and the client checks it before it fetches anything.

CUDAits own driverthe oldest it runs onwhere from
13.5620.70.06 (R620)580.65.06nixpkgs' copy of NVIDIA's driver manifest redistrib_620.70.06.json (cuda_compat, cuda_variant 13.5)
13.4615.71.10 (R615)580.65.06redistrib_615.71.10.json (cuda_compat, cuda_variant 13.4)
13.3610.43.02580.65.06redistrib_13.3.1.json, nvidia_driver
13.2595.71.05580.65.06redistrib_13.2.2.json, nvidia_driver
13.1590.48.01580.65.06redistrib_13.1.2.json, nvidia_driver
13.0580.65.06580.65.06CUDA 13.0 release notes (13.0 GA)
12.x525.60.13CUDA compatibility guide (minor version compatibility)
NVIDIA's manifests as nixpkgs keeps them (pkgs/development/cuda-modules/_cuda/manifests, nixpkgs c555305); docs.nvidia.com/deploy/cuda-compatibility
$ crl compat 13.5.37 620.70.06
CUDA 13.5.37 on driver 620.70.06: full: every feature of the toolkit
$ crl compat 13.5.37 580.95.05
CUDA 13.5.37 on driver 580.95.05: minor version compatibility only: driver 580.95.05 is older than 620.70.06, CUDA 13.5's own; ship SASS for the GPU (newer PTX can't be JIT-compiled)
$ crl compat 13.5.37 575.57.08                      # exit 1
CUDA 13.5.37 on driver 575.57.08: REFUSED: driver 575.57.08 is older than 580.65.06, the oldest that runs CUDA 13.x

provedSeven laws pin the rules down on NVIDIA's own versions: 13.5 on R620 full, 13.4 on R620 full, 13.5 on R580 minor, 13.5 on R575 refused, 12.9 on R575 minor, an unknown major refused, a driver that isn't a version refused (slide 7).cuda-release-lab (github.com/hhefesto/cuda-release-lab), LAWS.bend

measuredThe three lines above: crl, compiled from spec/crl.bend, on olimpo.cuda-release-lab (github.com/hhefesto/cuda-release-lab), spec/crl.bend; olimpo, 2026-12-05

07The laws

Every decision, as a law: click one for its code

LAWS.bend states them, PROOF.bend proves them, and bend PROOF.bend --verdict checks the proofs twice, the second time with BendTT's kernel, which has a proof in Lean. Most are facts about NVIDIA's real versions, checked by computing both sides; two hold for every input (the first two below).

lawit sayswhat it keeps from happening
failed_gate_holdsFor every gate, reason, other gates and versions: a release whose first gate failed is held.A failure can't be outvoted: no number of passing gates promotes a release with a failed one.
# LAWS.bend, line 133
# for every gate name, reason, other gates and versions: a failed first gate
# holds the release
law failed_gate_holds:
  for n: String
  for w: String
  for gs: List<&2, R.Gate>
  for cur: String
  for new: String
  {R.move.is_hold(R.promote(R.Bad{n, w} <> gs, cur, new)) == True{} : Bool}

# ---- what it uses, from spec/Release.bend ----

type Gate is Data:
  Ok{name: String}
  Bad{name: String, why: String}

def move.is_hold(m: Move) -> Bool:
  match m:
    case Hold{_}:
      True{}
    case _:
      False{}

# promote new over cur only when every gate passed and new is newer
def promote(gs: List<&2, Gate>, +cur: String, +new: String) -> Move:
  move.of(List.append(&2, String, gates.why(gs), newer.why(cur, new)), new)

type Move is Data:
  Promote{to: String}
  Hold{why: List<&2, String>}
  Rollback{to: String}

def move.of(ws: List<&2, String>, new: String) -> Move:
  match ws:
    case Nil{}:
      Promote{new}
    case w <> t:
      Hold{w <> t}

# the reasons of the gates that failed
def gates.why(gs: List<&2, Gate>) -> List<&2, String>:
  match gs:
    case Nil{}:
      Nil{}
    case Ok{_} <> t:
      gates.why(t)
    case Bad{n, w} <> t:
      (n ++ ": " ++ w) <> gates.why(t)

# a release goes forward only: the channel never moves to an older or the
# same version except by a rollback
def newer.why(+cur: String, +new: String) -> List<&2, String>:
  keep.put(Bool.or(String.is_empty(cur), ver.lt(cur, new)),
    "channel: " ++ new ++ " is not newer than the channel's " ++ cur, Nil{})

def keep.put(empty: Bool, h: String, r: List<&2, String>) -> List<&2, String>:
  match empty:
    case True{}:
      r
    case False{}:
      h <> r

def ver.lt(a: String, b: String) -> Bool:
  Cmp.is_lt(ver.order(a, b))

def ver.order(a: String, b: String) -> Cmp:
  ver.cmp(ver.of(a), ver.of(b))

# part by part; a missing part counts as 0 ("13.5" is "13.5.0")
def ver.cmp(a: List<&2, U32>, b: List<&2, U32>) -> Cmp:
  match a:
    case Nil{}:
      Bool.pick(Cmp, ver.zeros(b), EQ{}, LT{})
    case x <> xs:
      match b:
        case Nil{}:
          Bool.pick(Cmp, ver.zeros(x <> xs), EQ{}, GT{})
        case y <> ys:
          ver.then(U32.cmp(x, y), ver.cmp(xs, ys))

def ver.of(s: String) -> List<&2, U32>:
  Maybe.default(&2, List<&2, U32>, ver.read(s), Nil{})

def ver.zeros(xs: List<&2, U32>) -> Bool:
  match xs:
    case Nil{}:
      True{}
    case x <> t:
      Bool.and(U32.is_zero(x), ver.zeros(t))

def ver.then(c: Cmp, r: Cmp) -> Cmp:
  match c:
    case EQ{}:
      r
    case o:
      o

# "13.5.37" [13, 5, 37]; "13.x" None
def ver.read(s: String) -> Maybe<&2, List<&2, U32>>:
  ver.parts(String.split(String.trim(s), '.'))

def ver.parts(ps: List<&2, String>) -> Maybe<&2, List<&2, U32>>:
  match ps:
    case Nil{}:
      Some{Nil{}}
    case h <> t:
      ver.cons(ver.part(h), ver.parts(t))

def ver.cons(m: Maybe<&2, U32>, r: Maybe<&2, List<&2, U32>>) -> Maybe<&2, List<&2, U32>>:
  match m:
    case Some{x}:
      ver.cons2(x, r)
    case None{}:
      None{}

# a part that is not a number (or is empty) makes the whole version None
def ver.part(+s: String) -> Maybe<&2, U32>:
  Bool.pick(Maybe<&2, U32>, String.is_empty(s), None{}, U32.read(s))

def ver.cons2(x: U32, r: Maybe<&2, List<&2, U32>>) -> Maybe<&2, List<&2, U32>>:
  match r:
    case Some{xs}:
      Some{x <> xs}
    case None{}:
      None{}
unsigned_refusedFor every list of trusted keys: an unsigned path is refused.Trusting more keys never lets an unsigned path in.
# LAWS.bend, line 118
# for every list of trusted keys, an unsigned path is refused
law unsigned_refused:
  for ks: List<&2, String>
  {R.accept(None{}, ks) == False{} : Bool}

# ---- what it uses, from spec/Release.bend ----

# signer: the key name of a valid signature on the path, None if unsigned
def accept(signer: Maybe<&2, String>, ks: List<&2, String>) -> Bool:
  match signer:
    case None{}:
      False{}
    case Some{k}:
      trusted(k, ks)

def signer(s: String) -> String:
  ver.major.of(String.split(nth(1n, tokens(s)), ':'))

def trusted(+k: String, ks: List<&2, String>) -> Bool:
  match ks:
    case Nil{}:
      False{}
    case +h <> t:
      Bool.or(String.eq(h, k), trusted(k, t))

def ver.major.of(ps: List<&2, String>) -> String:
  match ps:
    case m <> _:
      m
    case _:
      ""

# the value's n-th word (from 0)
def nth(n: Nat, ws: List<&2, String>) -> String:
  match n:
    case 0n:
      ver.major.of(ws)
    case 1n+m:
      match ws:
        case Nil{}:
          ""
        case _ <> t:
          nth(m, t)

def tokens(s: String) -> List<&2, String>:
  words(String.from_list(spaced(String.to_list(s))))

# a line's words
def words(s: String) -> List<&2, String>:
  nonempty(String.split(s, ' '))

# `nix path-info --sigs`'s line "PATH<space or tab>KEY:SIG ...": the first KEY
def spaced(cs: List<&2, Char>) -> List<&2, Char>:
  match cs:
    case Nil{}:
      Nil{}
    case +c <> t:
      Bool.pick(Char, Char.is_space(c), ' ', c) <> spaced(t)

# the non-empty lines
def nonempty(xs: List<&2, String>) -> List<&2, String>:
  match xs:
    case Nil{}:
      Nil{}
    case +h <> t:
      keep.put(String.is_empty(String.trim(h)), String.trim(h), nonempty(t))

def keep.put(empty: Bool, h: String, r: List<&2, String>) -> List<&2, String>:
  match empty:
    case True{}:
      r
    case False{}:
      h <> r
every_failure_namedA held release lists every failed gate, in order, with its reason.The diagnostic is the whole story: no failure is hidden behind the first.
# LAWS.bend, line 154
law every_failure_named:
  {R.promote([R.Bad{"sha256 cuda_nvcc", "not on the mirror"}, R.Ok{"build"}, R.Bad{"nvcc sample", "exit 1"}], "13.4.3", "13.5.0") ==
    R.Hold{["sha256 cuda_nvcc: not on the mirror", "nvcc sample: exit 1"]} : R.Move}

# ---- what it uses, from spec/Release.bend ----

# promote new over cur only when every gate passed and new is newer
def promote(gs: List<&2, Gate>, +cur: String, +new: String) -> Move:
  move.of(List.append(&2, String, gates.why(gs), newer.why(cur, new)), new)

type Gate is Data:
  Ok{name: String}
  Bad{name: String, why: String}

type Move is Data:
  Promote{to: String}
  Hold{why: List<&2, String>}
  Rollback{to: String}

def move.of(ws: List<&2, String>, new: String) -> Move:
  match ws:
    case Nil{}:
      Promote{new}
    case w <> t:
      Hold{w <> t}

# the reasons of the gates that failed
def gates.why(gs: List<&2, Gate>) -> List<&2, String>:
  match gs:
    case Nil{}:
      Nil{}
    case Ok{_} <> t:
      gates.why(t)
    case Bad{n, w} <> t:
      (n ++ ": " ++ w) <> gates.why(t)

# a release goes forward only: the channel never moves to an older or the
# same version except by a rollback
def newer.why(+cur: String, +new: String) -> List<&2, String>:
  keep.put(Bool.or(String.is_empty(cur), ver.lt(cur, new)),
    "channel: " ++ new ++ " is not newer than the channel's " ++ cur, Nil{})

def keep.put(empty: Bool, h: String, r: List<&2, String>) -> List<&2, String>:
  match empty:
    case True{}:
      r
    case False{}:
      h <> r

def ver.lt(a: String, b: String) -> Bool:
  Cmp.is_lt(ver.order(a, b))

def ver.order(a: String, b: String) -> Cmp:
  ver.cmp(ver.of(a), ver.of(b))

# part by part; a missing part counts as 0 ("13.5" is "13.5.0")
def ver.cmp(a: List<&2, U32>, b: List<&2, U32>) -> Cmp:
  match a:
    case Nil{}:
      Bool.pick(Cmp, ver.zeros(b), EQ{}, LT{})
    case x <> xs:
      match b:
        case Nil{}:
          Bool.pick(Cmp, ver.zeros(x <> xs), EQ{}, GT{})
        case y <> ys:
          ver.then(U32.cmp(x, y), ver.cmp(xs, ys))

def ver.of(s: String) -> List<&2, U32>:
  Maybe.default(&2, List<&2, U32>, ver.read(s), Nil{})

def ver.zeros(xs: List<&2, U32>) -> Bool:
  match xs:
    case Nil{}:
      True{}
    case x <> t:
      Bool.and(U32.is_zero(x), ver.zeros(t))

def ver.then(c: Cmp, r: Cmp) -> Cmp:
  match c:
    case EQ{}:
      r
    case o:
      o

# "13.5.37" [13, 5, 37]; "13.x" None
def ver.read(s: String) -> Maybe<&2, List<&2, U32>>:
  ver.parts(String.split(String.trim(s), '.'))

def ver.parts(ps: List<&2, String>) -> Maybe<&2, List<&2, U32>>:
  match ps:
    case Nil{}:
      Some{Nil{}}
    case h <> t:
      ver.cons(ver.part(h), ver.parts(t))

def ver.cons(m: Maybe<&2, U32>, r: Maybe<&2, List<&2, U32>>) -> Maybe<&2, List<&2, U32>>:
  match m:
    case Some{x}:
      ver.cons2(x, r)
    case None{}:
      None{}

# a part that is not a number (or is empty) makes the whole version None
def ver.part(+s: String) -> Maybe<&2, U32>:
  Bool.pick(Maybe<&2, U32>, String.is_empty(s), None{}, U32.read(s))

def ver.cons2(x: U32, r: Maybe<&2, List<&2, U32>>) -> Maybe<&2, List<&2, U32>>:
  match r:
    case Some{xs}:
      Some{x <> xs}
    case None{}:
      None{}
same_release_holdsThe channel doesn't move to the release it already has.Running the pipeline twice changes nothing.
# LAWS.bend, line 144
law same_release_holds:
  {R.promote([R.Ok{"build"}], "13.5.0", "13.5.0") ==
    R.Hold{["channel: 13.5.0 is not newer than the channel's 13.5.0"]} : R.Move}

# ---- what it uses, from spec/Release.bend ----

# promote new over cur only when every gate passed and new is newer
def promote(gs: List<&2, Gate>, +cur: String, +new: String) -> Move:
  move.of(List.append(&2, String, gates.why(gs), newer.why(cur, new)), new)

type Gate is Data:
  Ok{name: String}
  Bad{name: String, why: String}

type Move is Data:
  Promote{to: String}
  Hold{why: List<&2, String>}
  Rollback{to: String}

def move.of(ws: List<&2, String>, new: String) -> Move:
  match ws:
    case Nil{}:
      Promote{new}
    case w <> t:
      Hold{w <> t}

# the reasons of the gates that failed
def gates.why(gs: List<&2, Gate>) -> List<&2, String>:
  match gs:
    case Nil{}:
      Nil{}
    case Ok{_} <> t:
      gates.why(t)
    case Bad{n, w} <> t:
      (n ++ ": " ++ w) <> gates.why(t)

# a release goes forward only: the channel never moves to an older or the
# same version except by a rollback
def newer.why(+cur: String, +new: String) -> List<&2, String>:
  keep.put(Bool.or(String.is_empty(cur), ver.lt(cur, new)),
    "channel: " ++ new ++ " is not newer than the channel's " ++ cur, Nil{})

def keep.put(empty: Bool, h: String, r: List<&2, String>) -> List<&2, String>:
  match empty:
    case True{}:
      r
    case False{}:
      h <> r

def ver.lt(a: String, b: String) -> Bool:
  Cmp.is_lt(ver.order(a, b))

def ver.order(a: String, b: String) -> Cmp:
  ver.cmp(ver.of(a), ver.of(b))

# part by part; a missing part counts as 0 ("13.5" is "13.5.0")
def ver.cmp(a: List<&2, U32>, b: List<&2, U32>) -> Cmp:
  match a:
    case Nil{}:
      Bool.pick(Cmp, ver.zeros(b), EQ{}, LT{})
    case x <> xs:
      match b:
        case Nil{}:
          Bool.pick(Cmp, ver.zeros(x <> xs), EQ{}, GT{})
        case y <> ys:
          ver.then(U32.cmp(x, y), ver.cmp(xs, ys))

def ver.of(s: String) -> List<&2, U32>:
  Maybe.default(&2, List<&2, U32>, ver.read(s), Nil{})

def ver.zeros(xs: List<&2, U32>) -> Bool:
  match xs:
    case Nil{}:
      True{}
    case x <> t:
      Bool.and(U32.is_zero(x), ver.zeros(t))

def ver.then(c: Cmp, r: Cmp) -> Cmp:
  match c:
    case EQ{}:
      r
    case o:
      o

# "13.5.37" [13, 5, 37]; "13.x" None
def ver.read(s: String) -> Maybe<&2, List<&2, U32>>:
  ver.parts(String.split(String.trim(s), '.'))

def ver.parts(ps: List<&2, String>) -> Maybe<&2, List<&2, U32>>:
  match ps:
    case Nil{}:
      Some{Nil{}}
    case h <> t:
      ver.cons(ver.part(h), ver.parts(t))

def ver.cons(m: Maybe<&2, U32>, r: Maybe<&2, List<&2, U32>>) -> Maybe<&2, List<&2, U32>>:
  match m:
    case Some{x}:
      ver.cons2(x, r)
    case None{}:
      None{}

# a part that is not a number (or is empty) makes the whole version None
def ver.part(+s: String) -> Maybe<&2, U32>:
  Bool.pick(Maybe<&2, U32>, String.is_empty(s), None{}, U32.read(s))

def ver.cons2(x: U32, r: Maybe<&2, List<&2, U32>>) -> Maybe<&2, List<&2, U32>>:
  match r:
    case Some{xs}:
      Some{x <> xs}
    case None{}:
      None{}
older_release_holdsThe channel doesn't move to an older release.A stale or replayed manifest can't take the channel back; only crl back can.
# LAWS.bend, line 148
law older_release_holds:
  {R.move.is_hold(R.promote([R.Ok{"build"}], "13.5.0", "13.4.3")) == True{} : Bool}

# ---- what it uses, from spec/Release.bend ----

def move.is_hold(m: Move) -> Bool:
  match m:
    case Hold{_}:
      True{}
    case _:
      False{}

# promote new over cur only when every gate passed and new is newer
def promote(gs: List<&2, Gate>, +cur: String, +new: String) -> Move:
  move.of(List.append(&2, String, gates.why(gs), newer.why(cur, new)), new)

type Gate is Data:
  Ok{name: String}
  Bad{name: String, why: String}

type Move is Data:
  Promote{to: String}
  Hold{why: List<&2, String>}
  Rollback{to: String}

def move.of(ws: List<&2, String>, new: String) -> Move:
  match ws:
    case Nil{}:
      Promote{new}
    case w <> t:
      Hold{w <> t}

# the reasons of the gates that failed
def gates.why(gs: List<&2, Gate>) -> List<&2, String>:
  match gs:
    case Nil{}:
      Nil{}
    case Ok{_} <> t:
      gates.why(t)
    case Bad{n, w} <> t:
      (n ++ ": " ++ w) <> gates.why(t)

# a release goes forward only: the channel never moves to an older or the
# same version except by a rollback
def newer.why(+cur: String, +new: String) -> List<&2, String>:
  keep.put(Bool.or(String.is_empty(cur), ver.lt(cur, new)),
    "channel: " ++ new ++ " is not newer than the channel's " ++ cur, Nil{})

def keep.put(empty: Bool, h: String, r: List<&2, String>) -> List<&2, String>:
  match empty:
    case True{}:
      r
    case False{}:
      h <> r

def ver.lt(a: String, b: String) -> Bool:
  Cmp.is_lt(ver.order(a, b))

def ver.order(a: String, b: String) -> Cmp:
  ver.cmp(ver.of(a), ver.of(b))

# part by part; a missing part counts as 0 ("13.5" is "13.5.0")
def ver.cmp(a: List<&2, U32>, b: List<&2, U32>) -> Cmp:
  match a:
    case Nil{}:
      Bool.pick(Cmp, ver.zeros(b), EQ{}, LT{})
    case x <> xs:
      match b:
        case Nil{}:
          Bool.pick(Cmp, ver.zeros(x <> xs), EQ{}, GT{})
        case y <> ys:
          ver.then(U32.cmp(x, y), ver.cmp(xs, ys))

def ver.of(s: String) -> List<&2, U32>:
  Maybe.default(&2, List<&2, U32>, ver.read(s), Nil{})

def ver.zeros(xs: List<&2, U32>) -> Bool:
  match xs:
    case Nil{}:
      True{}
    case x <> t:
      Bool.and(U32.is_zero(x), ver.zeros(t))

def ver.then(c: Cmp, r: Cmp) -> Cmp:
  match c:
    case EQ{}:
      r
    case o:
      o

# "13.5.37" [13, 5, 37]; "13.x" None
def ver.read(s: String) -> Maybe<&2, List<&2, U32>>:
  ver.parts(String.split(String.trim(s), '.'))

def ver.parts(ps: List<&2, String>) -> Maybe<&2, List<&2, U32>>:
  match ps:
    case Nil{}:
      Some{Nil{}}
    case h <> t:
      ver.cons(ver.part(h), ver.parts(t))

def ver.cons(m: Maybe<&2, U32>, r: Maybe<&2, List<&2, U32>>) -> Maybe<&2, List<&2, U32>>:
  match m:
    case Some{x}:
      ver.cons2(x, r)
    case None{}:
      None{}

# a part that is not a number (or is empty) makes the whole version None
def ver.part(+s: String) -> Maybe<&2, U32>:
  Bool.pick(Maybe<&2, U32>, String.is_empty(s), None{}, U32.read(s))

def ver.cons2(x: U32, r: Maybe<&2, List<&2, U32>>) -> Maybe<&2, List<&2, U32>>:
  match r:
    case Some{xs}:
      Some{x <> xs}
    case None{}:
      None{}
all_pass_newer_promotesEvery gate passed and the release is newer: promote.A good release isn't held for nothing.
# LAWS.bend, line 141
law all_pass_newer_promotes:
  {R.promote([R.Ok{"sha256"}, R.Ok{"build"}, R.Ok{"nvcc sample"}], "13.4.3", "13.5.0") == R.Promote{"13.5.0"} : R.Move}

# ---- what it uses, from spec/Release.bend ----

# promote new over cur only when every gate passed and new is newer
def promote(gs: List<&2, Gate>, +cur: String, +new: String) -> Move:
  move.of(List.append(&2, String, gates.why(gs), newer.why(cur, new)), new)

type Gate is Data:
  Ok{name: String}
  Bad{name: String, why: String}

type Move is Data:
  Promote{to: String}
  Hold{why: List<&2, String>}
  Rollback{to: String}

def move.of(ws: List<&2, String>, new: String) -> Move:
  match ws:
    case Nil{}:
      Promote{new}
    case w <> t:
      Hold{w <> t}

# the reasons of the gates that failed
def gates.why(gs: List<&2, Gate>) -> List<&2, String>:
  match gs:
    case Nil{}:
      Nil{}
    case Ok{_} <> t:
      gates.why(t)
    case Bad{n, w} <> t:
      (n ++ ": " ++ w) <> gates.why(t)

# a release goes forward only: the channel never moves to an older or the
# same version except by a rollback
def newer.why(+cur: String, +new: String) -> List<&2, String>:
  keep.put(Bool.or(String.is_empty(cur), ver.lt(cur, new)),
    "channel: " ++ new ++ " is not newer than the channel's " ++ cur, Nil{})

def keep.put(empty: Bool, h: String, r: List<&2, String>) -> List<&2, String>:
  match empty:
    case True{}:
      r
    case False{}:
      h <> r

def ver.lt(a: String, b: String) -> Bool:
  Cmp.is_lt(ver.order(a, b))

def ver.order(a: String, b: String) -> Cmp:
  ver.cmp(ver.of(a), ver.of(b))

# part by part; a missing part counts as 0 ("13.5" is "13.5.0")
def ver.cmp(a: List<&2, U32>, b: List<&2, U32>) -> Cmp:
  match a:
    case Nil{}:
      Bool.pick(Cmp, ver.zeros(b), EQ{}, LT{})
    case x <> xs:
      match b:
        case Nil{}:
          Bool.pick(Cmp, ver.zeros(x <> xs), EQ{}, GT{})
        case y <> ys:
          ver.then(U32.cmp(x, y), ver.cmp(xs, ys))

def ver.of(s: String) -> List<&2, U32>:
  Maybe.default(&2, List<&2, U32>, ver.read(s), Nil{})

def ver.zeros(xs: List<&2, U32>) -> Bool:
  match xs:
    case Nil{}:
      True{}
    case x <> t:
      Bool.and(U32.is_zero(x), ver.zeros(t))

def ver.then(c: Cmp, r: Cmp) -> Cmp:
  match c:
    case EQ{}:
      r
    case o:
      o

# "13.5.37" [13, 5, 37]; "13.x" None
def ver.read(s: String) -> Maybe<&2, List<&2, U32>>:
  ver.parts(String.split(String.trim(s), '.'))

def ver.parts(ps: List<&2, String>) -> Maybe<&2, List<&2, U32>>:
  match ps:
    case Nil{}:
      Some{Nil{}}
    case h <> t:
      ver.cons(ver.part(h), ver.parts(t))

def ver.cons(m: Maybe<&2, U32>, r: Maybe<&2, List<&2, U32>>) -> Maybe<&2, List<&2, U32>>:
  match m:
    case Some{x}:
      ver.cons2(x, r)
    case None{}:
      None{}

# a part that is not a number (or is empty) makes the whole version None
def ver.part(+s: String) -> Maybe<&2, U32>:
  Bool.pick(Maybe<&2, U32>, String.is_empty(s), None{}, U32.read(s))

def ver.cons2(x: U32, r: Maybe<&2, List<&2, U32>>) -> Maybe<&2, List<&2, U32>>:
  match r:
    case Some{xs}:
      Some{x <> xs}
    case None{}:
      None{}
rollback_to_previousA rollback goes to the release before the current one.Recovery is one step, to a release that was good.
# LAWS.bend, line 158
law rollback_to_previous:
  {R.rollback(["13.5.0", "13.4.3", "13.3.1"]) == R.Rollback{"13.4.3"} : R.Move}

# ---- what it uses, from spec/Release.bend ----

# history: the channel's releases, newest first; back to the one before
def rollback(hs: List<&2, String>) -> Move:
  match hs:
    case _ <> p <> _:
      Rollback{p}
    case _:
      Hold{["rollback: the channel has no earlier release"]}

type Move is Data:
  Promote{to: String}
  Hold{why: List<&2, String>}
  Rollback{to: String}
no_rollback_from_firstWith one release, there is nothing to roll back to: hold.A rollback can't empty the channel.
# LAWS.bend, line 195
law no_rollback_from_first:
  {R.move.is_hold(R.rollback(["13.4.3"])) == True{} : Bool}

# ---- what it uses, from spec/Release.bend ----

def move.is_hold(m: Move) -> Bool:
  match m:
    case Hold{_}:
      True{}
    case _:
      False{}

# history: the channel's releases, newest first; back to the one before
def rollback(hs: List<&2, String>) -> Move:
  match hs:
    case _ <> p <> _:
      Rollback{p}
    case _:
      Hold{["rollback: the channel has no earlier release"]}

type Move is Data:
  Promote{to: String}
  Hold{why: List<&2, String>}
  Rollback{to: String}
wrong_hash_failsA tarball whose sha256 differs from its manifest's fails, with both hashes.A changed file on the mirror is caught before anything is built from it.
# LAWS.bend, line 91
law wrong_hash_fails:
  {R.gates.why(R.verify(one(), "ffff456789012345678901234567890123456789012345678901234567890123  cuda_crt/a.tar.xz\n")) ==
    ["sha256 cuda_crt: the manifest says 0123456789012345678901234567890123456789012345678901234567890123, the file is ffff456789012345678901234567890123456789012345678901234567890123"] : List<&2, String>}

# ---- what it uses, from spec/Release.bend ----

# the reasons of the gates that failed
def gates.why(gs: List<&2, Gate>) -> List<&2, String>:
  match gs:
    case Nil{}:
      Nil{}
    case Ok{_} <> t:
      gates.why(t)
    case Bad{n, w} <> t:
      (n ++ ": " ++ w) <> gates.why(t)

def verify(m: Manifest, sums: String) -> List<&2, Gate>:
  verify.go(String.lines(sums), man.entries(m))

# ---- what it uses, from LAWS.bend ----

def one() -> R.Manifest:
  R.man.parse("release\t13.5.0\td\npkg\tcuda_crt\t13.5.37\tcuda_crt/a.tar.xz\t0123456789012345678901234567890123456789012345678901234567890123\t9\n")

# ---- what it uses, from spec/Release.bend ----

type Gate is Data:
  Ok{name: String}
  Bad{name: String, why: String}

type Manifest is Data:
  Manifest{release: String, date: String, entries: List<&2, Entry>}

def verify.go(+ls: List<&2, String>, es: List<&2, Entry>) -> List<&2, Gate>:
  match es:
    case Nil{}:
      Nil{}
    case e <> t:
      verify.entry(ls, e) <> verify.go(ls, t)

def man.entries(m: Manifest) -> List<&2, Entry>:
  match m:
    case Manifest{_, _, es}:
      es

def man.parse(s: String) -> Manifest:
  man.parse.go(String.lines(s))

type Entry is Data:
  Entry{name: String, version: String, path: String, sha: String, size: String}

def verify.entry(+ls: List<&2, String>, e: Entry) -> Gate:
  match e:
    case Entry{n, _, +p, s, _}:
      verify.pick(n, s, sum.of(p, ls))

def man.parse.go(ls: List<&2, String>) -> Manifest:
  match ls:
    case Nil{}:
      man.empty()
    case h <> t:
      man.line(String.split(h, '\t'), man.parse.go(t))

def verify.pick(+n: String, +want: String, +got: String) -> Gate:
  Bool.pick(Gate, String.is_empty(got), Bad{"sha256 " ++ n, "not on the mirror"},
    Bool.pick(Gate, String.eq(want, got), Ok{"sha256 " ++ n},
      Bad{"sha256 " ++ n, "the manifest says " ++ want ++ ", the file is " ++ got}))

# A tarball against its manifest entry: sums are sha256sum's lines
# ("<sha256>  <path>"), the mirror's own files.
def sum.of(+p: String, ls: List<&2, String>) -> String:
  match ls:
    case Nil{}:
      ""
    case +l <> t:
      Bool.pick(String, Bool.or(String.ends_with(l, "  " ++ p), String.ends_with(l, "/" ++ p)),
        String.take(l, 64n), sum.of(p, t))

def man.empty() -> Manifest:
  Manifest{"", "", Nil{}}

def man.line(f: List<&2, String>, m: Manifest) -> Manifest:
  match f:
    case "release" <> r <> d <> _:
      man.set(r, d, m)
    case "pkg" <> n <> v <> p <> s <> z <> _:
      man.add(Entry{n, v, p, s, z}, m)
    case _:
      m

def man.set(r: String, d: String, m: Manifest) -> Manifest:
  match m:
    case Manifest{_, _, es}:
      Manifest{r, d, es}

def man.add(e: Entry, m: Manifest) -> Manifest:
  match m:
    case Manifest{r, d, es}:
      Manifest{r, d, e <> es}
missing_file_failsA package with no file on the mirror fails.A half-published release can't pass.
# LAWS.bend, line 95
law missing_file_fails:
  {R.gates.why(R.verify(one(), "")) == ["sha256 cuda_crt: not on the mirror"] : List<&2, String>}

# ---- what it uses, from spec/Release.bend ----

# the reasons of the gates that failed
def gates.why(gs: List<&2, Gate>) -> List<&2, String>:
  match gs:
    case Nil{}:
      Nil{}
    case Ok{_} <> t:
      gates.why(t)
    case Bad{n, w} <> t:
      (n ++ ": " ++ w) <> gates.why(t)

def verify(m: Manifest, sums: String) -> List<&2, Gate>:
  verify.go(String.lines(sums), man.entries(m))

# ---- what it uses, from LAWS.bend ----

def one() -> R.Manifest:
  R.man.parse("release\t13.5.0\td\npkg\tcuda_crt\t13.5.37\tcuda_crt/a.tar.xz\t0123456789012345678901234567890123456789012345678901234567890123\t9\n")

# ---- what it uses, from spec/Release.bend ----

type Gate is Data:
  Ok{name: String}
  Bad{name: String, why: String}

type Manifest is Data:
  Manifest{release: String, date: String, entries: List<&2, Entry>}

def verify.go(+ls: List<&2, String>, es: List<&2, Entry>) -> List<&2, Gate>:
  match es:
    case Nil{}:
      Nil{}
    case e <> t:
      verify.entry(ls, e) <> verify.go(ls, t)

def man.entries(m: Manifest) -> List<&2, Entry>:
  match m:
    case Manifest{_, _, es}:
      es

def man.parse(s: String) -> Manifest:
  man.parse.go(String.lines(s))

type Entry is Data:
  Entry{name: String, version: String, path: String, sha: String, size: String}

def verify.entry(+ls: List<&2, String>, e: Entry) -> Gate:
  match e:
    case Entry{n, _, +p, s, _}:
      verify.pick(n, s, sum.of(p, ls))

def man.parse.go(ls: List<&2, String>) -> Manifest:
  match ls:
    case Nil{}:
      man.empty()
    case h <> t:
      man.line(String.split(h, '\t'), man.parse.go(t))

def verify.pick(+n: String, +want: String, +got: String) -> Gate:
  Bool.pick(Gate, String.is_empty(got), Bad{"sha256 " ++ n, "not on the mirror"},
    Bool.pick(Gate, String.eq(want, got), Ok{"sha256 " ++ n},
      Bad{"sha256 " ++ n, "the manifest says " ++ want ++ ", the file is " ++ got}))

# A tarball against its manifest entry: sums are sha256sum's lines
# ("<sha256>  <path>"), the mirror's own files.
def sum.of(+p: String, ls: List<&2, String>) -> String:
  match ls:
    case Nil{}:
      ""
    case +l <> t:
      Bool.pick(String, Bool.or(String.ends_with(l, "  " ++ p), String.ends_with(l, "/" ++ p)),
        String.take(l, 64n), sum.of(p, t))

def man.empty() -> Manifest:
  Manifest{"", "", Nil{}}

def man.line(f: List<&2, String>, m: Manifest) -> Manifest:
  match f:
    case "release" <> r <> d <> _:
      man.set(r, d, m)
    case "pkg" <> n <> v <> p <> s <> z <> _:
      man.add(Entry{n, v, p, s, z}, m)
    case _:
      m

def man.set(r: String, d: String, m: Manifest) -> Manifest:
  match m:
    case Manifest{_, _, es}:
      Manifest{r, d, es}

def man.add(e: Entry, m: Manifest) -> Manifest:
  match m:
    case Manifest{r, d, es}:
      Manifest{r, d, e <> es}
different_nar_notTwo builds with different NAR hashes fail, naming both.Nothing reaches the cache that only one machine can make.
# LAWS.bend, line 110
law different_nar_not:
  {R.gates.why([R.repro("cuda_nvcc", "sha256-a", "sha256-b")]) ==
    ["reproducible cuda_nvcc: build1 gave sha256-a, build2 gave sha256-b"] : List<&2, String>}

# ---- what it uses, from spec/Release.bend ----

# the reasons of the gates that failed
def gates.why(gs: List<&2, Gate>) -> List<&2, String>:
  match gs:
    case Nil{}:
      Nil{}
    case Ok{_} <> t:
      gates.why(t)
    case Bad{n, w} <> t:
      (n ++ ": " ++ w) <> gates.why(t)

# Reproducibility: the same derivation built on build1 and on build2
# (a builder with no hash built nothing: that fails too)
def repro(+n: String, +h1: String, +h2: String) -> Gate:
  Bool.pick(Gate, Bool.or(String.is_empty(h1), String.is_empty(h2)),
    Bad{"reproducible " ++ n, "no NAR hash from " ++ Bool.pick(String, String.is_empty(h1), "build1", "build2")},
    Bool.pick(Gate, String.eq(h1, h2), Ok{"reproducible " ++ n},
      Bad{"reproducible " ++ n, "build1 gave " ++ h1 ++ ", build2 gave " ++ h2}))

type Gate is Data:
  Ok{name: String}
  Bad{name: String, why: String}
changes_13_4_to_13_5A new manifest's changes: bumped, kept, added and dropped, package by package.The release note is computed, not written.
# LAWS.bend, line 69
law changes_13_4_to_13_5:
  {R.changes.show(R.changes(old13_4(), new13_5())) ==
    [ "bumped  cuda_nvcc 13.4.92 -> 13.5.37"
    , "kept    cuda_cudart 13.4.92"
    , "added   libnvvm 13.5.37"
    , "dropped cuda_gone 1.0" ] : List<&2, String>}

# ---- what it uses, from spec/Release.bend ----

def changes.show(cs: List<&2, Change>) -> List<&2, String>:
  match cs:
    case Nil{}:
      Nil{}
    case c <> t:
      change.show(c) <> changes.show(t)

# every package of the new manifest, then every package it no longer has
def changes(old: Manifest, new: Manifest) -> List<&2, Change>:
  +o = man.entries(old)
  +n = man.entries(new)
  List.append(&2, Change, changes.new(o, n), changes.gone(o, n))

# ---- what it uses, from LAWS.bend ----

def old13_4() -> R.Manifest:
  R.man.parse("release\t13.4.3\t2026-10-13\npkg\tcuda_nvcc\t13.4.92\tn4\tx\t1\npkg\tcuda_cudart\t13.4.92\tc4\ty\t2\npkg\tcuda_gone\t1.0\tg\tz\t3\n")

def new13_5() -> R.Manifest:
  R.man.parse("release\t13.5.0\t2026-11-04\npkg\tcuda_nvcc\t13.5.37\tn5\tx\t1\npkg\tcuda_cudart\t13.4.92\tc4\ty\t2\npkg\tlibnvvm\t13.5.37\tv5\tw\t4\n")

# ---- what it uses, from spec/Release.bend ----

type Change is Data:
  Added{name: String, to: String}
  Bumped{name: String, from: String, to: String}
  Kept{name: String, at: String}
  Back{name: String, from: String, to: String}
  Dropped{name: String, from: String}

def change.show(c: Change) -> String:
  match c:
    case Added{n, v}:
      "added   " ++ n ++ " " ++ v
    case Bumped{n, o, v}:
      "bumped  " ++ n ++ " " ++ o ++ " -> " ++ v
    case Kept{n, v}:
      "kept    " ++ n ++ " " ++ v
    case Back{n, o, v}:
      "BACK    " ++ n ++ " " ++ o ++ " -> " ++ v ++ " (older than the pinned one)"
    case Dropped{n, o}:
      "dropped " ++ n ++ " " ++ o

type Manifest is Data:
  Manifest{release: String, date: String, entries: List<&2, Entry>}

def man.entries(m: Manifest) -> List<&2, Entry>:
  match m:
    case Manifest{_, _, es}:
      es

def changes.new(+olds: List<&2, Entry>, news: List<&2, Entry>) -> List<&2, Change>:
  match news:
    case Nil{}:
      Nil{}
    case Entry{+n, +v, _, _, _} <> t:
      change.of(n, v, entry.find(n, olds)) <> changes.new(olds, t)

def changes.gone(olds: List<&2, Entry>, +news: List<&2, Entry>) -> List<&2, Change>:
  match olds:
    case Nil{}:
      Nil{}
    case Entry{+n, o, _, _, _} <> t:
      dropped.put(n, o, Maybe.is_none(&2, Entry, entry.find(n, news)), changes.gone(t, news))

def man.parse(s: String) -> Manifest:
  man.parse.go(String.lines(s))

type Entry is Data:
  Entry{name: String, version: String, path: String, sha: String, size: String}

def change.of(+n: String, +v: String, m: Maybe<&2, Entry>) -> Change:
  match m:
    case None{}:
      Added{n, v}
    case Some{Entry{_, +o, _, _, _}}:
      change.pick(n, o, v, ver.order(o, v))

def entry.find(+n: String, es: List<&2, Entry>) -> Maybe<&2, Entry>:
  match es:
    case Nil{}:
      None{}
    case +e <> t:
      Bool.pick(Maybe<&2, Entry>, entry.is(n, e), Some{e}, entry.find(n, t))

def dropped.put(n: String, o: String, gone: Bool, r: List<&2, Change>) -> List<&2, Change>:
  match gone:
    case True{}:
      Dropped{n, o} <> r
    case False{}:
      r

def man.parse.go(ls: List<&2, String>) -> Manifest:
  match ls:
    case Nil{}:
      man.empty()
    case h <> t:
      man.line(String.split(h, '\t'), man.parse.go(t))

def change.pick(n: String, o: String, v: String, c: Cmp) -> Change:
  match c:
    case LT{}:
      Bumped{n, o, v}
    case EQ{}:
      Kept{n, v}
    case GT{}:
      Back{n, o, v}

def ver.order(a: String, b: String) -> Cmp:
  ver.cmp(ver.of(a), ver.of(b))

def entry.is(+n: String, e: Entry) -> Bool:
  String.eq(entry.name(e), n)

def man.empty() -> Manifest:
  Manifest{"", "", Nil{}}

def man.line(f: List<&2, String>, m: Manifest) -> Manifest:
  match f:
    case "release" <> r <> d <> _:
      man.set(r, d, m)
    case "pkg" <> n <> v <> p <> s <> z <> _:
      man.add(Entry{n, v, p, s, z}, m)
    case _:
      m

# part by part; a missing part counts as 0 ("13.5" is "13.5.0")
def ver.cmp(a: List<&2, U32>, b: List<&2, U32>) -> Cmp:
  match a:
    case Nil{}:
      Bool.pick(Cmp, ver.zeros(b), EQ{}, LT{})
    case x <> xs:
      match b:
        case Nil{}:
          Bool.pick(Cmp, ver.zeros(x <> xs), EQ{}, GT{})
        case y <> ys:
          ver.then(U32.cmp(x, y), ver.cmp(xs, ys))

def ver.of(s: String) -> List<&2, U32>:
  Maybe.default(&2, List<&2, U32>, ver.read(s), Nil{})

def entry.name(e: Entry) -> String:
  match e:
    case Entry{n, _, _, _, _}:
      n

def man.set(r: String, d: String, m: Manifest) -> Manifest:
  match m:
    case Manifest{_, _, es}:
      Manifest{r, d, es}

def man.add(e: Entry, m: Manifest) -> Manifest:
  match m:
    case Manifest{r, d, es}:
      Manifest{r, d, e <> es}

def ver.zeros(xs: List<&2, U32>) -> Bool:
  match xs:
    case Nil{}:
      True{}
    case x <> t:
      Bool.and(U32.is_zero(x), ver.zeros(t))

def ver.then(c: Cmp, r: Cmp) -> Cmp:
  match c:
    case EQ{}:
      r
    case o:
      o

# "13.5.37" [13, 5, 37]; "13.x" None
def ver.read(s: String) -> Maybe<&2, List<&2, U32>>:
  ver.parts(String.split(String.trim(s), '.'))

def ver.parts(ps: List<&2, String>) -> Maybe<&2, List<&2, U32>>:
  match ps:
    case Nil{}:
      Some{Nil{}}
    case h <> t:
      ver.cons(ver.part(h), ver.parts(t))

def ver.cons(m: Maybe<&2, U32>, r: Maybe<&2, List<&2, U32>>) -> Maybe<&2, List<&2, U32>>:
  match m:
    case Some{x}:
      ver.cons2(x, r)
    case None{}:
      None{}

# a part that is not a number (or is empty) makes the whole version None
def ver.part(+s: String) -> Maybe<&2, U32>:
  Bool.pick(Maybe<&2, U32>, String.is_empty(s), None{}, U32.read(s))

def ver.cons2(x: U32, r: Maybe<&2, List<&2, U32>>) -> Maybe<&2, List<&2, U32>>:
  match r:
    case Some{xs}:
      Some{x <> xs}
    case None{}:
      None{}
back_is_seenA manifest that takes a package back to an older version is seen.A downgrade inside a release can't slip through as a bump.
# LAWS.bend, line 77
# a manifest that takes a package back is seen
law back_is_seen:
  {R.changes.backs(R.changes(new13_5(), old13_4())) ==
    [True{}, False{}, False{}, False{}] : List<&2, Bool>}

# ---- what it uses, from spec/Release.bend ----

def changes.backs(cs: List<&2, Change>) -> List<&2, Bool>:
  match cs:
    case Nil{}:
      Nil{}
    case c <> t:
      change.is_back(c) <> changes.backs(t)

# every package of the new manifest, then every package it no longer has
def changes(old: Manifest, new: Manifest) -> List<&2, Change>:
  +o = man.entries(old)
  +n = man.entries(new)
  List.append(&2, Change, changes.new(o, n), changes.gone(o, n))

# ---- what it uses, from LAWS.bend ----

def new13_5() -> R.Manifest:
  R.man.parse("release\t13.5.0\t2026-11-04\npkg\tcuda_nvcc\t13.5.37\tn5\tx\t1\npkg\tcuda_cudart\t13.4.92\tc4\ty\t2\npkg\tlibnvvm\t13.5.37\tv5\tw\t4\n")

def old13_4() -> R.Manifest:
  R.man.parse("release\t13.4.3\t2026-10-13\npkg\tcuda_nvcc\t13.4.92\tn4\tx\t1\npkg\tcuda_cudart\t13.4.92\tc4\ty\t2\npkg\tcuda_gone\t1.0\tg\tz\t3\n")

# ---- what it uses, from spec/Release.bend ----

type Change is Data:
  Added{name: String, to: String}
  Bumped{name: String, from: String, to: String}
  Kept{name: String, at: String}
  Back{name: String, from: String, to: String}
  Dropped{name: String, from: String}

def change.is_back(c: Change) -> Bool:
  match c:
    case Back{_, _, _}:
      True{}
    case _:
      False{}

type Manifest is Data:
  Manifest{release: String, date: String, entries: List<&2, Entry>}

def man.entries(m: Manifest) -> List<&2, Entry>:
  match m:
    case Manifest{_, _, es}:
      es

def changes.new(+olds: List<&2, Entry>, news: List<&2, Entry>) -> List<&2, Change>:
  match news:
    case Nil{}:
      Nil{}
    case Entry{+n, +v, _, _, _} <> t:
      change.of(n, v, entry.find(n, olds)) <> changes.new(olds, t)

def changes.gone(olds: List<&2, Entry>, +news: List<&2, Entry>) -> List<&2, Change>:
  match olds:
    case Nil{}:
      Nil{}
    case Entry{+n, o, _, _, _} <> t:
      dropped.put(n, o, Maybe.is_none(&2, Entry, entry.find(n, news)), changes.gone(t, news))

def man.parse(s: String) -> Manifest:
  man.parse.go(String.lines(s))

type Entry is Data:
  Entry{name: String, version: String, path: String, sha: String, size: String}

def change.of(+n: String, +v: String, m: Maybe<&2, Entry>) -> Change:
  match m:
    case None{}:
      Added{n, v}
    case Some{Entry{_, +o, _, _, _}}:
      change.pick(n, o, v, ver.order(o, v))

def entry.find(+n: String, es: List<&2, Entry>) -> Maybe<&2, Entry>:
  match es:
    case Nil{}:
      None{}
    case +e <> t:
      Bool.pick(Maybe<&2, Entry>, entry.is(n, e), Some{e}, entry.find(n, t))

def dropped.put(n: String, o: String, gone: Bool, r: List<&2, Change>) -> List<&2, Change>:
  match gone:
    case True{}:
      Dropped{n, o} <> r
    case False{}:
      r

def man.parse.go(ls: List<&2, String>) -> Manifest:
  match ls:
    case Nil{}:
      man.empty()
    case h <> t:
      man.line(String.split(h, '\t'), man.parse.go(t))

def change.pick(n: String, o: String, v: String, c: Cmp) -> Change:
  match c:
    case LT{}:
      Bumped{n, o, v}
    case EQ{}:
      Kept{n, v}
    case GT{}:
      Back{n, o, v}

def ver.order(a: String, b: String) -> Cmp:
  ver.cmp(ver.of(a), ver.of(b))

def entry.is(+n: String, e: Entry) -> Bool:
  String.eq(entry.name(e), n)

def man.empty() -> Manifest:
  Manifest{"", "", Nil{}}

def man.line(f: List<&2, String>, m: Manifest) -> Manifest:
  match f:
    case "release" <> r <> d <> _:
      man.set(r, d, m)
    case "pkg" <> n <> v <> p <> s <> z <> _:
      man.add(Entry{n, v, p, s, z}, m)
    case _:
      m

# part by part; a missing part counts as 0 ("13.5" is "13.5.0")
def ver.cmp(a: List<&2, U32>, b: List<&2, U32>) -> Cmp:
  match a:
    case Nil{}:
      Bool.pick(Cmp, ver.zeros(b), EQ{}, LT{})
    case x <> xs:
      match b:
        case Nil{}:
          Bool.pick(Cmp, ver.zeros(x <> xs), EQ{}, GT{})
        case y <> ys:
          ver.then(U32.cmp(x, y), ver.cmp(xs, ys))

def ver.of(s: String) -> List<&2, U32>:
  Maybe.default(&2, List<&2, U32>, ver.read(s), Nil{})

def entry.name(e: Entry) -> String:
  match e:
    case Entry{n, _, _, _, _}:
      n

def man.set(r: String, d: String, m: Manifest) -> Manifest:
  match m:
    case Manifest{_, _, es}:
      Manifest{r, d, es}

def man.add(e: Entry, m: Manifest) -> Manifest:
  match m:
    case Manifest{r, d, es}:
      Manifest{r, d, e <> es}

def ver.zeros(xs: List<&2, U32>) -> Bool:
  match xs:
    case Nil{}:
      True{}
    case x <> t:
      Bool.and(U32.is_zero(x), ver.zeros(t))

def ver.then(c: Cmp, r: Cmp) -> Cmp:
  match c:
    case EQ{}:
      r
    case o:
      o

# "13.5.37" [13, 5, 37]; "13.x" None
def ver.read(s: String) -> Maybe<&2, List<&2, U32>>:
  ver.parts(String.split(String.trim(s), '.'))

def ver.parts(ps: List<&2, String>) -> Maybe<&2, List<&2, U32>>:
  match ps:
    case Nil{}:
      Some{Nil{}}
    case h <> t:
      ver.cons(ver.part(h), ver.parts(t))

def ver.cons(m: Maybe<&2, U32>, r: Maybe<&2, List<&2, U32>>) -> Maybe<&2, List<&2, U32>>:
  match m:
    case Some{x}:
      ver.cons2(x, r)
    case None{}:
      None{}

# a part that is not a number (or is empty) makes the whole version None
def ver.part(+s: String) -> Maybe<&2, U32>:
  Bool.pick(Maybe<&2, U32>, String.is_empty(s), None{}, U32.read(s))

def ver.cons2(x: U32, r: Maybe<&2, List<&2, U32>>) -> Maybe<&2, List<&2, U32>>:
  match r:
    case Some{xs}:
      Some{x <> xs}
    case None{}:
      None{}
ten_after_nine13.10 comes after 13.9: versions order as numbers, not as text.The watcher won't think 13.10 is older than 13.9.
# LAWS.bend, line 15
# not as text: "13.10" sorts before "13.9" as text, after it as a version
law ten_after_nine:
  {R.ver.order("13.10.0", "13.9.9") == GT{} : Cmp}

# ---- what it uses, from spec/Release.bend ----

def ver.order(a: String, b: String) -> Cmp:
  ver.cmp(ver.of(a), ver.of(b))

# part by part; a missing part counts as 0 ("13.5" is "13.5.0")
def ver.cmp(a: List<&2, U32>, b: List<&2, U32>) -> Cmp:
  match a:
    case Nil{}:
      Bool.pick(Cmp, ver.zeros(b), EQ{}, LT{})
    case x <> xs:
      match b:
        case Nil{}:
          Bool.pick(Cmp, ver.zeros(x <> xs), EQ{}, GT{})
        case y <> ys:
          ver.then(U32.cmp(x, y), ver.cmp(xs, ys))

def ver.of(s: String) -> List<&2, U32>:
  Maybe.default(&2, List<&2, U32>, ver.read(s), Nil{})

def ver.zeros(xs: List<&2, U32>) -> Bool:
  match xs:
    case Nil{}:
      True{}
    case x <> t:
      Bool.and(U32.is_zero(x), ver.zeros(t))

def ver.then(c: Cmp, r: Cmp) -> Cmp:
  match c:
    case EQ{}:
      r
    case o:
      o

# "13.5.37" [13, 5, 37]; "13.x" None
def ver.read(s: String) -> Maybe<&2, List<&2, U32>>:
  ver.parts(String.split(String.trim(s), '.'))

def ver.parts(ps: List<&2, String>) -> Maybe<&2, List<&2, U32>>:
  match ps:
    case Nil{}:
      Some{Nil{}}
    case h <> t:
      ver.cons(ver.part(h), ver.parts(t))

def ver.cons(m: Maybe<&2, U32>, r: Maybe<&2, List<&2, U32>>) -> Maybe<&2, List<&2, U32>>:
  match m:
    case Some{x}:
      ver.cons2(x, r)
    case None{}:
      None{}

# a part that is not a number (or is empty) makes the whole version None
def ver.part(+s: String) -> Maybe<&2, U32>:
  Bool.pick(Maybe<&2, U32>, String.is_empty(s), None{}, U32.read(s))

def ver.cons2(x: U32, r: Maybe<&2, List<&2, U32>>) -> Maybe<&2, List<&2, U32>>:
  match r:
    case Some{xs}:
      Some{x <> xs}
    case None{}:
      None{}
r575_refuses_13CUDA 13.5 on driver 575.57.08 (a 12.x branch): refused.No client is handed a toolkit its driver can't run.
# LAWS.bend, line 45
# R575 is a 12.x driver: no 13.x on it
law r575_refuses_13:
  {R.fit.tag(R.compat("13.5.37", "575.57.08")) == "refused" : String}

# ---- what it uses, from spec/Release.bend ----

def fit.tag(f: Fit) -> String:
  match f:
    case Full{}:
      "full"
    case Minor{_}:
      "minor"
    case Refused{_}:
      "refused"

def compat(+toolkit: String, +driver: String) -> Fit:
  +maj = ver.major(toolkit)
  Bool.pick(Fit, ver.valid(driver),
    compat.min.fit(maj, ver.mm(toolkit), driver, table.get(maj, compat.min())),
    Refused{"\"" ++ driver ++ "\" is not a driver version"})

type Fit is Data:
  Full{}
  Minor{why: String}
  Refused{why: String}

# "13.5.37": "13"
def ver.major(s: String) -> String:
  ver.major.of(String.split(String.trim(s), '.'))

def ver.valid(s: String) -> Bool:
  Maybe.is_some(&2, List<&2, U32>, ver.read(s))

def compat.min.fit(+maj: String, +mm: String, +d: String, +min: String) -> Fit:
  Bool.pick(Fit, String.is_empty(min), Refused{"CUDA " ++ maj ++ ".x is not in the compatibility table"},
    Bool.pick(Fit, ver.lt(d, min),
      Refused{"driver " ++ d ++ " is older than " ++ min ++ ", the oldest that runs CUDA " ++ maj ++ ".x"},
      compat.own.fit(mm, d, table.get(mm, compat.own()))))

# "13.5.37": "13.5"
def ver.mm(s: String) -> String:
  ver.mm.of(String.split(String.trim(s), '.'))

def table.get(+k: String, rs: List<&2, Row>) -> String:
  match rs:
    case Nil{}:
      ""
    case Row{+a, b} <> t:
      Bool.pick(String, String.eq(a, k), b, table.get(k, t))

# the oldest driver a major version runs on, under minor version compatibility
def compat.min() -> List<&2, Row>:
  [Row{"12", "525.60.13"}, Row{"13", "580.65.06"}]

def ver.major.of(ps: List<&2, String>) -> String:
  match ps:
    case m <> _:
      m
    case _:
      ""

# "13.5.37" [13, 5, 37]; "13.x" None
def ver.read(s: String) -> Maybe<&2, List<&2, U32>>:
  ver.parts(String.split(String.trim(s), '.'))

def ver.lt(a: String, b: String) -> Bool:
  Cmp.is_lt(ver.order(a, b))

def compat.own.fit(+mm: String, +d: String, +own: String) -> Fit:
  Bool.pick(Fit, String.is_empty(own), Minor{"no driver branch is known for CUDA " ++ mm},
    Bool.pick(Fit, ver.le(own, d), Full{},
      Minor{"driver " ++ d ++ " is older than " ++ own ++ ", CUDA " ++ mm ++ "'s own; ship SASS for the GPU (newer PTX can't be JIT-compiled)"}))

# the driver each minor version was released with: its features need it
def compat.own() -> List<&2, Row>:
  [ Row{"13.0", "580.65.06"}
  , Row{"13.1", "590.48.01"}
  , Row{"13.2", "595.71.05"}
  , Row{"13.3", "610.43.02"}
  , Row{"13.4", "615.71.10"}
  , Row{"13.5", "620.70.06"} ]

def ver.mm.of(ps: List<&2, String>) -> String:
  match ps:
    case m <> n <> _:
      m ++ "." ++ n
    case _:
      ""

type Row is Data:
  Row{key: String, val: String}

def ver.parts(ps: List<&2, String>) -> Maybe<&2, List<&2, U32>>:
  match ps:
    case Nil{}:
      Some{Nil{}}
    case h <> t:
      ver.cons(ver.part(h), ver.parts(t))

def ver.order(a: String, b: String) -> Cmp:
  ver.cmp(ver.of(a), ver.of(b))

def ver.le(a: String, b: String) -> Bool:
  Cmp.is_le(ver.order(a, b))

def ver.cons(m: Maybe<&2, U32>, r: Maybe<&2, List<&2, U32>>) -> Maybe<&2, List<&2, U32>>:
  match m:
    case Some{x}:
      ver.cons2(x, r)
    case None{}:
      None{}

# a part that is not a number (or is empty) makes the whole version None
def ver.part(+s: String) -> Maybe<&2, U32>:
  Bool.pick(Maybe<&2, U32>, String.is_empty(s), None{}, U32.read(s))

# part by part; a missing part counts as 0 ("13.5" is "13.5.0")
def ver.cmp(a: List<&2, U32>, b: List<&2, U32>) -> Cmp:
  match a:
    case Nil{}:
      Bool.pick(Cmp, ver.zeros(b), EQ{}, LT{})
    case x <> xs:
      match b:
        case Nil{}:
          Bool.pick(Cmp, ver.zeros(x <> xs), EQ{}, GT{})
        case y <> ys:
          ver.then(U32.cmp(x, y), ver.cmp(xs, ys))

def ver.of(s: String) -> List<&2, U32>:
  Maybe.default(&2, List<&2, U32>, ver.read(s), Nil{})

def ver.cons2(x: U32, r: Maybe<&2, List<&2, U32>>) -> Maybe<&2, List<&2, U32>>:
  match r:
    case Some{xs}:
      Some{x <> xs}
    case None{}:
      None{}

def ver.zeros(xs: List<&2, U32>) -> Bool:
  match xs:
    case Nil{}:
      True{}
    case x <> t:
      Bool.and(U32.is_zero(x), ver.zeros(t))

def ver.then(c: Cmp, r: Cmp) -> Cmp:
  match c:
    case EQ{}:
      r
    case o:
      o
r580_runs_13_5_minorCUDA 13.5 on driver 580.95.05: minor version compatibility only.The limit (SASS needed, no newer PTX) is said, not hidden.
# LAWS.bend, line 41
# an R580 driver runs 13.5 under minor version compatibility only
law r580_runs_13_5_minor:
  {R.fit.tag(R.compat("13.5.37", "580.95.05")) == "minor" : String}

# ---- what it uses, from spec/Release.bend ----

def fit.tag(f: Fit) -> String:
  match f:
    case Full{}:
      "full"
    case Minor{_}:
      "minor"
    case Refused{_}:
      "refused"

def compat(+toolkit: String, +driver: String) -> Fit:
  +maj = ver.major(toolkit)
  Bool.pick(Fit, ver.valid(driver),
    compat.min.fit(maj, ver.mm(toolkit), driver, table.get(maj, compat.min())),
    Refused{"\"" ++ driver ++ "\" is not a driver version"})

type Fit is Data:
  Full{}
  Minor{why: String}
  Refused{why: String}

# "13.5.37": "13"
def ver.major(s: String) -> String:
  ver.major.of(String.split(String.trim(s), '.'))

def ver.valid(s: String) -> Bool:
  Maybe.is_some(&2, List<&2, U32>, ver.read(s))

def compat.min.fit(+maj: String, +mm: String, +d: String, +min: String) -> Fit:
  Bool.pick(Fit, String.is_empty(min), Refused{"CUDA " ++ maj ++ ".x is not in the compatibility table"},
    Bool.pick(Fit, ver.lt(d, min),
      Refused{"driver " ++ d ++ " is older than " ++ min ++ ", the oldest that runs CUDA " ++ maj ++ ".x"},
      compat.own.fit(mm, d, table.get(mm, compat.own()))))

# "13.5.37": "13.5"
def ver.mm(s: String) -> String:
  ver.mm.of(String.split(String.trim(s), '.'))

def table.get(+k: String, rs: List<&2, Row>) -> String:
  match rs:
    case Nil{}:
      ""
    case Row{+a, b} <> t:
      Bool.pick(String, String.eq(a, k), b, table.get(k, t))

# the oldest driver a major version runs on, under minor version compatibility
def compat.min() -> List<&2, Row>:
  [Row{"12", "525.60.13"}, Row{"13", "580.65.06"}]

def ver.major.of(ps: List<&2, String>) -> String:
  match ps:
    case m <> _:
      m
    case _:
      ""

# "13.5.37" [13, 5, 37]; "13.x" None
def ver.read(s: String) -> Maybe<&2, List<&2, U32>>:
  ver.parts(String.split(String.trim(s), '.'))

def ver.lt(a: String, b: String) -> Bool:
  Cmp.is_lt(ver.order(a, b))

def compat.own.fit(+mm: String, +d: String, +own: String) -> Fit:
  Bool.pick(Fit, String.is_empty(own), Minor{"no driver branch is known for CUDA " ++ mm},
    Bool.pick(Fit, ver.le(own, d), Full{},
      Minor{"driver " ++ d ++ " is older than " ++ own ++ ", CUDA " ++ mm ++ "'s own; ship SASS for the GPU (newer PTX can't be JIT-compiled)"}))

# the driver each minor version was released with: its features need it
def compat.own() -> List<&2, Row>:
  [ Row{"13.0", "580.65.06"}
  , Row{"13.1", "590.48.01"}
  , Row{"13.2", "595.71.05"}
  , Row{"13.3", "610.43.02"}
  , Row{"13.4", "615.71.10"}
  , Row{"13.5", "620.70.06"} ]

def ver.mm.of(ps: List<&2, String>) -> String:
  match ps:
    case m <> n <> _:
      m ++ "." ++ n
    case _:
      ""

type Row is Data:
  Row{key: String, val: String}

def ver.parts(ps: List<&2, String>) -> Maybe<&2, List<&2, U32>>:
  match ps:
    case Nil{}:
      Some{Nil{}}
    case h <> t:
      ver.cons(ver.part(h), ver.parts(t))

def ver.order(a: String, b: String) -> Cmp:
  ver.cmp(ver.of(a), ver.of(b))

def ver.le(a: String, b: String) -> Bool:
  Cmp.is_le(ver.order(a, b))

def ver.cons(m: Maybe<&2, U32>, r: Maybe<&2, List<&2, U32>>) -> Maybe<&2, List<&2, U32>>:
  match m:
    case Some{x}:
      ver.cons2(x, r)
    case None{}:
      None{}

# a part that is not a number (or is empty) makes the whole version None
def ver.part(+s: String) -> Maybe<&2, U32>:
  Bool.pick(Maybe<&2, U32>, String.is_empty(s), None{}, U32.read(s))

# part by part; a missing part counts as 0 ("13.5" is "13.5.0")
def ver.cmp(a: List<&2, U32>, b: List<&2, U32>) -> Cmp:
  match a:
    case Nil{}:
      Bool.pick(Cmp, ver.zeros(b), EQ{}, LT{})
    case x <> xs:
      match b:
        case Nil{}:
          Bool.pick(Cmp, ver.zeros(x <> xs), EQ{}, GT{})
        case y <> ys:
          ver.then(U32.cmp(x, y), ver.cmp(xs, ys))

def ver.of(s: String) -> List<&2, U32>:
  Maybe.default(&2, List<&2, U32>, ver.read(s), Nil{})

def ver.cons2(x: U32, r: Maybe<&2, List<&2, U32>>) -> Maybe<&2, List<&2, U32>>:
  match r:
    case Some{xs}:
      Some{x <> xs}
    case None{}:
      None{}

def ver.zeros(xs: List<&2, U32>) -> Bool:
  match xs:
    case Nil{}:
      True{}
    case x <> t:
      Bool.and(U32.is_zero(x), ver.zeros(t))

def ver.then(c: Cmp, r: Cmp) -> Cmp:
  match c:
    case EQ{}:
      r
    case o:
      o
own_driver_fullCUDA 13.5 on its own driver, 620.70.06: full.The table matches NVIDIA's manifests.
# LAWS.bend, line 34
# CUDA 13.5's own driver: every feature
law own_driver_full:
  {R.fit.tag(R.compat("13.5.37", "620.70.06")) == "full" : String}

# ---- what it uses, from spec/Release.bend ----

def fit.tag(f: Fit) -> String:
  match f:
    case Full{}:
      "full"
    case Minor{_}:
      "minor"
    case Refused{_}:
      "refused"

def compat(+toolkit: String, +driver: String) -> Fit:
  +maj = ver.major(toolkit)
  Bool.pick(Fit, ver.valid(driver),
    compat.min.fit(maj, ver.mm(toolkit), driver, table.get(maj, compat.min())),
    Refused{"\"" ++ driver ++ "\" is not a driver version"})

type Fit is Data:
  Full{}
  Minor{why: String}
  Refused{why: String}

# "13.5.37": "13"
def ver.major(s: String) -> String:
  ver.major.of(String.split(String.trim(s), '.'))

def ver.valid(s: String) -> Bool:
  Maybe.is_some(&2, List<&2, U32>, ver.read(s))

def compat.min.fit(+maj: String, +mm: String, +d: String, +min: String) -> Fit:
  Bool.pick(Fit, String.is_empty(min), Refused{"CUDA " ++ maj ++ ".x is not in the compatibility table"},
    Bool.pick(Fit, ver.lt(d, min),
      Refused{"driver " ++ d ++ " is older than " ++ min ++ ", the oldest that runs CUDA " ++ maj ++ ".x"},
      compat.own.fit(mm, d, table.get(mm, compat.own()))))

# "13.5.37": "13.5"
def ver.mm(s: String) -> String:
  ver.mm.of(String.split(String.trim(s), '.'))

def table.get(+k: String, rs: List<&2, Row>) -> String:
  match rs:
    case Nil{}:
      ""
    case Row{+a, b} <> t:
      Bool.pick(String, String.eq(a, k), b, table.get(k, t))

# the oldest driver a major version runs on, under minor version compatibility
def compat.min() -> List<&2, Row>:
  [Row{"12", "525.60.13"}, Row{"13", "580.65.06"}]

def ver.major.of(ps: List<&2, String>) -> String:
  match ps:
    case m <> _:
      m
    case _:
      ""

# "13.5.37" [13, 5, 37]; "13.x" None
def ver.read(s: String) -> Maybe<&2, List<&2, U32>>:
  ver.parts(String.split(String.trim(s), '.'))

def ver.lt(a: String, b: String) -> Bool:
  Cmp.is_lt(ver.order(a, b))

def compat.own.fit(+mm: String, +d: String, +own: String) -> Fit:
  Bool.pick(Fit, String.is_empty(own), Minor{"no driver branch is known for CUDA " ++ mm},
    Bool.pick(Fit, ver.le(own, d), Full{},
      Minor{"driver " ++ d ++ " is older than " ++ own ++ ", CUDA " ++ mm ++ "'s own; ship SASS for the GPU (newer PTX can't be JIT-compiled)"}))

# the driver each minor version was released with: its features need it
def compat.own() -> List<&2, Row>:
  [ Row{"13.0", "580.65.06"}
  , Row{"13.1", "590.48.01"}
  , Row{"13.2", "595.71.05"}
  , Row{"13.3", "610.43.02"}
  , Row{"13.4", "615.71.10"}
  , Row{"13.5", "620.70.06"} ]

def ver.mm.of(ps: List<&2, String>) -> String:
  match ps:
    case m <> n <> _:
      m ++ "." ++ n
    case _:
      ""

type Row is Data:
  Row{key: String, val: String}

def ver.parts(ps: List<&2, String>) -> Maybe<&2, List<&2, U32>>:
  match ps:
    case Nil{}:
      Some{Nil{}}
    case h <> t:
      ver.cons(ver.part(h), ver.parts(t))

def ver.order(a: String, b: String) -> Cmp:
  ver.cmp(ver.of(a), ver.of(b))

def ver.le(a: String, b: String) -> Bool:
  Cmp.is_le(ver.order(a, b))

def ver.cons(m: Maybe<&2, U32>, r: Maybe<&2, List<&2, U32>>) -> Maybe<&2, List<&2, U32>>:
  match m:
    case Some{x}:
      ver.cons2(x, r)
    case None{}:
      None{}

# a part that is not a number (or is empty) makes the whole version None
def ver.part(+s: String) -> Maybe<&2, U32>:
  Bool.pick(Maybe<&2, U32>, String.is_empty(s), None{}, U32.read(s))

# part by part; a missing part counts as 0 ("13.5" is "13.5.0")
def ver.cmp(a: List<&2, U32>, b: List<&2, U32>) -> Cmp:
  match a:
    case Nil{}:
      Bool.pick(Cmp, ver.zeros(b), EQ{}, LT{})
    case x <> xs:
      match b:
        case Nil{}:
          Bool.pick(Cmp, ver.zeros(x <> xs), EQ{}, GT{})
        case y <> ys:
          ver.then(U32.cmp(x, y), ver.cmp(xs, ys))

def ver.of(s: String) -> List<&2, U32>:
  Maybe.default(&2, List<&2, U32>, ver.read(s), Nil{})

def ver.cons2(x: U32, r: Maybe<&2, List<&2, U32>>) -> Maybe<&2, List<&2, U32>>:
  match r:
    case Some{xs}:
      Some{x <> xs}
    case None{}:
      None{}

def ver.zeros(xs: List<&2, U32>) -> Bool:
  match xs:
    case Nil{}:
      True{}
    case x <> t:
      Bool.and(U32.is_zero(x), ver.zeros(t))

def ver.then(c: Cmp, r: Cmp) -> Cmp:
  match c:
    case EQ{}:
      r
    case o:
      o
signer_of_path_infoThe signer is read from nix path-info --sigs's line.The client's check reads the real signature, not a guess.
# LAWS.bend, line 183
law signer_of_path_info:
  {R.signer("/nix/store/abc-cuda-lab-toolkit-13.5.0\tlab-cache-1:AAAA==\n") == "lab-cache-1" : String}

# ---- what it uses, from spec/Release.bend ----

def signer(s: String) -> String:
  ver.major.of(String.split(nth(1n, tokens(s)), ':'))

def ver.major.of(ps: List<&2, String>) -> String:
  match ps:
    case m <> _:
      m
    case _:
      ""

# the value's n-th word (from 0)
def nth(n: Nat, ws: List<&2, String>) -> String:
  match n:
    case 0n:
      ver.major.of(ws)
    case 1n+m:
      match ws:
        case Nil{}:
          ""
        case _ <> t:
          nth(m, t)

def tokens(s: String) -> List<&2, String>:
  words(String.from_list(spaced(String.to_list(s))))

# a line's words
def words(s: String) -> List<&2, String>:
  nonempty(String.split(s, ' '))

# `nix path-info --sigs`'s line "PATH<space or tab>KEY:SIG ...": the first KEY
def spaced(cs: List<&2, Char>) -> List<&2, Char>:
  match cs:
    case Nil{}:
      Nil{}
    case +c <> t:
      Bool.pick(Char, Char.is_space(c), ' ', c) <> spaced(t)

# the non-empty lines
def nonempty(xs: List<&2, String>) -> List<&2, String>:
  match xs:
    case Nil{}:
      Nil{}
    case +h <> t:
      keep.put(String.is_empty(String.trim(h)), String.trim(h), nonempty(t))

def keep.put(empty: Bool, h: String, r: List<&2, String>) -> List<&2, String>:
  match empty:
    case True{}:
      r
    case False{}:
      h <> r
cuda-release-lab (github.com/hhefesto/cuda-release-lab), LAWS.bend, PROOF.bend, spec/Release.bend

provedAll 44 laws: bend PROOF.bend --verdict prints ALL PROOFS CHECK. A law changed to a false claim (13.5 on R575 as minor) makes it print SOME PROOFS FAIL, naming it: the laws are computed, not assumed.cuda-release-lab (github.com/hhefesto/cuda-release-lab), checks.proofs; the negative check run on olimpo, 2026-12-05

08The run

Two releases through the seven VMs

The NixOS test boots the seven VMs, publishes CUDA 13.4.3 on redist, runs crl cycle on ci and then the client; then the same for 13.5.0, after drill 1 (slide 9). Below: 13.5.0 going through, and the client taking it. The output is the run's own, cut only where it says so.

$ crl cycle /etc/lab/ci.conf    # on ci
crl: CUDA 13.5.0 is on redist; the channel has 13.4.3
bumped  cccl 13.3.4.3.1 -> 13.3.5.0.6
bumped  cuda_crt 13.4.92 -> 13.5.37
bumped  cuda_cudart 13.4.92 -> 13.5.37
bumped  cuda_cuobjdump 13.4.92 -> 13.5.37
bumped  cuda_nvcc 13.4.92 -> 13.5.37
bumped  libnvvm 13.4.92 -> 13.5.37
crl: building cuda-lab-toolkit-13.5.0 on build1 and build2 (each evaluates nix/build.nix with forge's pins)
crl: build1: nix: these 7 derivations will be built: ... lab-build: toolkit of 13.5.0: /nix/store/f58jwkib21fdc4xvk6hd16al55hs9wqd-cuda-lab-toolkit-13.5.0.drv
crl: build2: nix: these 7 derivations will be built: ... lab-build: toolkit of 13.5.0: /nix/store/f58jwkib21fdc4xvk6hd16al55hs9wqd-cuda-lab-toolkit-13.5.0.drv
crl: cuda-lab-toolkit-13.5.0: /nix/store/qhzhh8fxanfadvp1dyrylrf55ypypqz9-cuda-lab-toolkit-13.5.0
crl: NAR hashes: sha256:1pgy9b93lqkjy0ph006gkj89nkv74h4jwvr0mq0k8xjrhxb48xm6 (build1), sha256:1pgy9b93lqkjy0ph006gkj89nkv74h4jwvr0mq0k8xjrhxb48xm6 (build2)
crl: the sample on build1
crl: CUDA 13.5.37 on the clients' driver 580.95.05: minor version compatibility only: driver 580.95.05 is older than 620.70.06, CUDA 13.5's own; ship SASS for the GPU (newer PTX can't be JIT-compiled)
pass  manifest
pass  fetch cccl
pass  fetch cuda_crt
pass  fetch cuda_cudart
pass  fetch cuda_cuobjdump
pass  fetch cuda_nvcc
pass  fetch libnvvm
pass  sha256 cccl
pass  sha256 cuda_crt
pass  sha256 cuda_cudart
pass  sha256 cuda_cuobjdump
pass  sha256 cuda_nvcc
pass  sha256 libnvvm
pass  pins pushed to forge
pass  build cuda-lab-toolkit-13.5.0 on build1
pass  build cuda-lab-toolkit-13.5.0 on build2
pass  reproducible cuda-lab-toolkit-13.5.0
pass  nvcc compiles the sample (sm_90 SASS)
pass  driver 580.95.05: minor
promote 13.5.0
pass  channel 13.5.0 on cache

[exit 0, 181 s]
$ crl client /etc/lab/client.conf    # on client
crl: the channel has CUDA 13.5.0 (nvcc 13.5.37); this driver is 580.95.05
minor version compatibility only: driver 580.95.05 is older than 620.70.06, CUDA 13.5's own; ship SASS for the GPU (newer PTX can't be JIT-compiled)
crl: fetching /nix/store/qhzhh8fxanfadvp1dyrylrf55ypypqz9-cuda-lab-toolkit-13.5.0 from http://cache:5000 (signatures required)
pass  fetched, signed by a trusted key
pass  signer lab-cache-1 is trusted
pass  profile /nix/var/nix/profiles/cuda
pass  nvcc -arch=sm_90 hello.cu
ELF file    1: hello.1.sm_90.cubin
ELF file    2: hello.2.sm_90.cubin
cudart 13050, driver 0, devices 0: CUDA driver version is insufficient for CUDA runtime version

[exit 0, 45 s]
steptime
boot7 VMs in 141 s
01-release-13.4.3202 s
02-client-13.4.373 s
d1-wrong-hash5 s
03-release-13.5.0181 s
04-client-13.5.045 s
05-nothing-new0 s
d3-old-driver0 s
d4-not-reproducible15 s
d5-unsigned2 s
d6-rollback5 s
06-client-after-rollback22 s
07-forge-log0 s
the lab's run on olimpo (nix build .#checks.x86_64-linux.lab; result/drills/), 2026-12-05, commit 10a6770, 700 s under QEMU's emulation

measuredTimes are under QEMU's emulation (no KVM), the slowest way this lab can run.the lab's run on olimpo (nix build .#checks.x86_64-linux.lab; result/drills/), 2026-12-05, commit 10a6770, 700 s under QEMU's emulation

09Drills

Must-fail: each failure, and what the pipeline says

Each drill makes one thing go wrong on purpose. The test asserts it fails, and how; the output is the VMs' own.

$ crl cycle /etc/lab/ci.conf    # on ci
crl: CUDA 13.5.0 is on redist; the channel has 13.4.3
bumped  cccl 13.3.4.3.1 -> 13.3.5.0.6
bumped  cuda_crt 13.4.92 -> 13.5.37
bumped  cuda_cudart 13.4.92 -> 13.5.37
bumped  cuda_cuobjdump 13.4.92 -> 13.5.37
bumped  cuda_nvcc 13.4.92 -> 13.5.37
bumped  libnvvm 13.4.92 -> 13.5.37
pass  manifest
pass  fetch cccl
pass  fetch cuda_crt
pass  fetch cuda_cudart
pass  fetch cuda_cuobjdump
pass  fetch cuda_nvcc
pass  fetch libnvvm
pass  sha256 cccl
FAIL  sha256 cuda_crt: the manifest says 0df5c0ca27392152f370751c82b27ff1ab67661e4810cfc7248e2e03479c9ae0, the file is 392fb9b3af3ce7f421352e53dc32daeb61b4c73674755e979e59d68cc952462e
pass  sha256 cuda_cudart
pass  sha256 cuda_cuobjdump
pass  sha256 cuda_nvcc
pass  sha256 libnvvm
crl: the tarballs failed: nothing is built
hold
  sha256 cuda_crt: the manifest says 0df5c0ca27392152f370751c82b27ff1ab67661e4810cfc7248e2e03479c9ae0, the file is 392fb9b3af3ce7f421352e53dc32daeb61b4c73674755e979e59d68cc952462e

[exit 1, 5 s]
$ crl client /etc/lab/client.conf 575.57.08    # on client
crl: the channel has CUDA 13.5.0 (nvcc 13.5.37); this driver is 575.57.08
REFUSED: driver 575.57.08 is older than 580.65.06, the oldest that runs CUDA 13.x

[exit 1, 0 s]

measuredDrill 1: CUDA 13.5.0 published with one byte added to cuda_crt's tarball: held before anything was built; the channel stayed on 13.4.3. Drill 2: the client with an R575 driver refuses 13.5 before fetching it.the lab's run on olimpo (nix build .#checks.x86_64-linux.lab; result/drills/), 2026-12-05, commit 10a6770, 700 s under QEMU's emulation

10Drills

Builders that disagree, an unsigned path, a rollback

$ crl build /etc/lab/ci.conf lab-nondet - nondet    # on ci
crl: building lab-nondet on build1 and build2 (each evaluates nix/build.nix with forge's pins)
crl: build1: nix: this derivation will be built: ... 
crl: build2: nix: this derivation will be built: ... 
crl: lab-nondet: /nix/store/n99p5x8hi2j3md6a1snj2s91w10fgqpb-lab-nondet
crl: NAR hashes: sha256:0h1vqw1s9km63ia5zqfg48bjqyvrpqqh22scdmqpama9vvmiy98q (build1), sha256:0np2wajip97fiyimniw6xjbp74g51airdrnb9k7q3sq1nrz77r0f (build2)
pass  build lab-nondet on build1
pass  build lab-nondet on build2
FAIL  reproducible lab-nondet: build1 gave sha256:0h1vqw1s9km63ia5zqfg48bjqyvrpqqh22scdmqpama9vvmiy98q, build2 gave sha256:0np2wajip97fiyimniw6xjbp74g51airdrnb9k7q3sq1nrz77r0f

[exit 1, 15 s]
$ nix copy --from http://build2:5000 /nix/store/n99p5x8hi2j3md6a1snj2s91w10fgqpb-lab-nondet    # on client
copying 1 paths...
error: cannot add path '/nix/store/n99p5x8hi2j3md6a1snj2s91w10fgqpb-lab-nondet' because it lacks a signature by a trusted key

[exit 1, 2 s]
$ crl back /etc/lab/ci.conf    # on ci
rollback 13.4.3
pass  channel back to 13.4.3

[exit 0, 5 s]

$ crl client /etc/lab/client.conf    # on client
crl: the channel has CUDA 13.4.3 (nvcc 13.4.92); this driver is 580.95.05
minor version compatibility only: driver 580.95.05 is older than 615.71.10, CUDA 13.4's own; ship SASS for the GPU (newer PTX can't be JIT-compiled)
crl: fetching /nix/store/1924h4ijqmjvs2nw4abyphh5vamhqmjj-cuda-lab-toolkit-13.4.3 from http://cache:5000 (signatures required)
… 5 lines cut …
ELF file    2: hello.2.sm_90.cubin
cudart 13040, driver 0, devices 0: CUDA driver version is insufficient for CUDA runtime version

[exit 0, 22 s]

measuredDrill 3: a derivation that writes the time into its output, built on both builders: the NAR hashes differ and the gate names both. Drill 4: build2's unsigned harmonia: Nix refuses the path. Drill 5: crl back takes the channel from 13.5.0 to 13.4.3, and the client follows.the lab's run on olimpo (nix build .#checks.x86_64-linux.lab; result/drills/), 2026-12-05, commit 10a6770, 700 s under QEMU's emulation

openNot yet a drill: a library missing from a closure (a broken RPATH caught by a check, not at run time on a GPU machine).cuda-release-lab (github.com/hhefesto/cuda-release-lab), PLAN.md

11Limits

What this lab is not

  • No GPU: the sample compiles to SASS and starts, but no kernel runs; compat is NVIDIA's rules as data, not a test on hardware.
  • No KVM: QEMU emulates (olimpo's SVM is off in the BIOS). Every time on these slides is the slow case.
  • The builders evaluate the lab's own nix/build.nix against a pinned nixpkgs with the forge's pins, not a nixpkgs PR branch: the toolkit is the lab's small derivation, not cudaPackages.
  • Six packages of NVIDIA's ~40 per release; no cuDNN or TensorRT yet (their manifests are the same shape: redistrib_9.27.0.json, redistrib_11.4.0.json in nixpkgs).
  • The lab's keys are made at build time and are not secret: a lab key, never used elsewhere.

leadNext: cuDNN and TensorRT through the same cycle, with their own compatibility rows; the missing-library drill; the same cycle against nixpkgs' own cudaPackages, as a PR branch would be; KVM.cuda-release-lab (github.com/hhefesto/cuda-release-lab), PLAN.md

12This deck

Made with bend-frp

The slides are data in Bend (deck/Deck.bend); bend-frp runs the page; the navigation is a small pure machine (Nav.bend), the same as directo-devops.hhefesto.dev's. The drills' outputs are copied from the lab's run (deck/Drills.bend). Each law's code is generated from the lab's sources (deck/lawcode.sh), and nix flake check fails while it is out of date.

provedThe deck's own laws: moving never changes the number of slides, next then back returns where you were, the keys and addresses mean what this page says, every claim, table, card and animation names a source, and every animation can be drawn. bend PROOF.bend --verdict in deck/ prints ALL PROOFS CHECK.cuda-release-lab (github.com/hhefesto/cuda-release-lab), deck/LAWS.bend, deck/PROOF.bend