From 1bd85805af5a34a278374f3b42278773a791280e Mon Sep 17 00:00:00 2001 From: WitteShadovv Date: Wed, 25 Nov 2026 09:38:57 +0100 Subject: [PATCH 01/13] feat(distro): point the mirror seam at the assets repository The owner created WitteShadovv/nails-test-images for the test images no upstream publishes. mirrors.nix now names its release-download root, so a pinned mirror entry is fetched from images-/ there. images.nix and ci/distro_images.py check a mirror pin: it needs its family, names its asset and its SRI sha256 together or neither, and can only be enabled once pinned. The weekly link check probes the asset a mirror entry pins, reading base and tagFor out of mirrors.nix, and lists an entry with no asset as not checked. repin moves a mirror entry to the newest build that its release's -latest.json names. An entry can set firmware to uefi. distro-vm.nix then boots it with OVMF through nix-vm-test's QEMU_OPTS, in the sandboxed test and in the host drivers, so an image whose only boot loader is systemd-boot starts from its ESP's fallback loader. The arch-install entry sets it. --- ci/distro_images.py | 188 +++++++++++++++++++++-- ci/tests/test_distro_images.py | 233 +++++++++++++++++++++++++++-- nix/distro-tests/images.json | 1 + nix/distro-tests/images.nix | 33 +++- nix/distro-tests/lib/distro-vm.nix | 53 +++++-- nix/distro-tests/mirrors.nix | 24 +-- nix/e2e-tests/README.md | 8 +- 7 files changed, 489 insertions(+), 51 deletions(-) diff --git a/ci/distro_images.py b/ci/distro_images.py index 860dd597c..4dc9f53a5 100644 --- a/ci/distro_images.py +++ b/ci/distro_images.py @@ -22,6 +22,12 @@ its own ``/images.json``, at the revision ``flake.lock`` locks, and the upstream mirror can prune it like any other build. The link check reads that list and probes the URL; a newer nix-vm-test lock is what repins such an entry. + +A ``mirror`` entry is an image the project builds itself and publishes to the +assets repository that ``nix/distro-tests/mirrors.nix`` names (the archinstall +image). The link check probes the asset it pins there, and ``repin`` moves it +to the newest build, which the release's ``-latest.json`` manifest +names. """ from __future__ import annotations @@ -42,6 +48,7 @@ REPO = Path(__file__).resolve().parents[1] TABLE_PATH = REPO / "nix" / "distro-tests" / "images.json" LOCK_PATH = REPO / "flake.lock" +MIRRORS_PATH = REPO / "nix" / "distro-tests" / "mirrors.nix" # The placeholder hash an entry carries until it is pinned for real. It is the # well-known Nix "fake" SHA256, so an enabled entry that still has it is caught @@ -51,6 +58,7 @@ KNOWN_OS_IDS = frozenset({"debian", "ubuntu", "fedora", "arch"}) KNOWN_PREPARE = frozenset({"nix-vm-test", "fedora", "archlinux"}) KNOWN_KINDS = frozenset({"nix-vm-test", "upstream", "mirror", "pending"}) +KNOWN_FIRMWARE = frozenset({"bios", "uefi"}) # How far before an entry's upstreamUntil the link check starts failing, so # there is time to repin before the image drops off its download mirror. @@ -77,6 +85,50 @@ class LinkError(Exception): """The URL an entry pins could not be worked out.""" +# --- mirror ------------------------------------------------------------------- + +# mirrors.nix keeps `base` and the shape of `tagFor` as plain strings, so that +# this module reads the same values the Nix side fetches from. +_MIRROR_BASE = re.compile(r'^\s*base = "(?P[^"$]*)";', re.MULTILINE) +_MIRROR_TAG = re.compile( + r'^\s*tagFor = family: "(?P[^"$]*)\$\{family\}";', re.MULTILINE +) + + +@dataclass(frozen=True) +class Mirror: + """The assets repository's download root and its per-family tag prefix.""" + + base: str + tag_prefix: str + + def configured(self) -> bool: + return self.base != "" + + def url_for(self, family: str, asset: str) -> str: + """The download URL of one asset, as mirrors.nix's urlFor builds it.""" + return f"{self.base}/{self.tag_prefix}{family}/{asset}" + + def latest_url(self, family: str) -> str: + """The manifest of a family's newest build, beside its assets.""" + return self.url_for(family, f"{family}-latest.json") + + +def load_mirror(path: Path = MIRRORS_PATH) -> Mirror: + """Read the mirror seam out of mirrors.nix.""" + try: + text = path.read_text(encoding="utf-8") + except OSError as error: + raise LinkError(f"cannot read {path.name}: {error}") from None + base = _MIRROR_BASE.search(text) + tag = _MIRROR_TAG.search(text) + if base is None or tag is None: + raise LinkError( + f"{path.name} names no plain-string base and tagFor; see its header" + ) + return Mirror(base=base.group("base").rstrip("/"), tag_prefix=tag.group("prefix")) + + def load_table(path: Path = TABLE_PATH) -> dict[str, dict]: """Read the image table from JSON.""" with path.open(encoding="utf-8") as handle: @@ -132,6 +184,9 @@ def _problems_for_entry(name: str, entry: object) -> list[str]: datetime.date.fromisoformat(str(until)) except ValueError: out.append(f"{name}: upstreamUntil must be null or YYYY-MM-DD") + firmware = entry.get("firmware", "bios") + if firmware not in KNOWN_FIRMWARE: + out.append(f"{name}: unknown firmware {firmware!r}") out.extend(_source_problems(name, entry, entry["source"])) out.extend(_known_failed_problems(name, entry.get("knownFailedUnits"))) return out @@ -214,6 +269,8 @@ def _source_problems(name: str, entry: Mapping, source: object) -> list[str]: for field in ("url", "name", "sha256"): if not source.get(field): out.append(f"{name}: an upstream source needs {field!r}") + elif kind == "mirror": + out.extend(_mirror_problems(name, entry, source)) enabled = bool(entry.get("enabled")) if enabled and kind == "pending": out.append(f"{name}: a pending source cannot be enabled") @@ -222,6 +279,35 @@ def _source_problems(name: str, entry: Mapping, source: object) -> list[str]: return out +def _is_asset_name(asset: object) -> bool: + return ( + isinstance(asset, str) + and asset not in ("", ".", "..") + and "/" not in asset + and not any(char.isspace() for char in asset) + ) + + +def _mirror_problems(name: str, entry: Mapping, source: Mapping) -> list[str]: + """A mirror pin names its family's asset and that asset's hash, or neither.""" + out: list[str] = [] + family = source.get("family") + if not isinstance(family, str) or not family: + out.append(f"{name}: a mirror source needs 'family'") + asset, sha256 = source.get("asset"), source.get("sha256") + if (asset is None) != (sha256 is None): + out.append(f"{name}: a mirror source names its asset and its sha256 together") + if asset is not None and not _is_asset_name(asset): + out.append(f"{name}: a mirror asset must be a plain file name") + if sha256 is not None and not ( + isinstance(sha256, str) and sha256.startswith("sha256-") + ): + out.append(f"{name}: a mirror sha256 must be an SRI hash (sha256-...)") + if entry.get("enabled") and asset is None: + out.append(f"{name}: a mirror source cannot be enabled before it is pinned") + return out + + def validate(table: Mapping[str, object]) -> list[str]: """Return every schema problem in the table, most useful first.""" problems: list[str] = [] @@ -348,6 +434,7 @@ def link_check( offline: bool = False, url_ok: Callable[[str], bool] = _url_ok, pin_url: Callable[[Mapping], str] | None = None, + mirror: Mirror | None = None, ) -> LinkReport: """Check the pin of every entry, the staged ones as well as the enabled. @@ -359,13 +446,17 @@ def link_check( revision ``flake.lock`` locks). A staged (disabled) entry stays out of the smoke matrix until a change enables it, and the probes boot the Fedora and Arch ones before then; its pin lapses all the same, so it is checked like - an enabled one. A run that could check no enabled entry fails as well: a - pass would claim a check of the images CI boots that never happened, - whatever it found for the staged ones. + an enabled one. A mirror entry is probed at the asset it pins in the + assets repository (``mirror``, by default read from mirrors.nix); one that + pins no asset yet, or a mirror with no base, is listed as not checked. A + run that could check no enabled entry fails as well: a pass would claim a + check of the images CI boots that never happened, whatever it found for + the staged ones. """ today = today or datetime.date.today() resolve = pin_url or _locked_nix_vm_test_url() report = LinkReport() + no_probe: dict[str, str] = {} checked_enabled = False for name, entry in table.items(): enabled = bool(entry.get("enabled")) @@ -389,21 +480,34 @@ def link_check( f"{label}: upstream pin lapses {until}" f" (within {LEAD_DAYS} days or past); repin it" ) + url: str | None = None if not offline and kind in ("upstream", "nix-vm-test"): try: url = _pinned_url(source, resolve) except LinkError as error: done.append("its pin unreadable") report.failures.append(f"{label}: {error}") + elif not offline and kind == "mirror": + try: + mirror = mirror or load_mirror() + except LinkError as error: + done.append("its mirror unreadable") + report.failures.append(f"{label}: {error}") else: - done.append(f"probed {url}") - if not url_ok(url): - report.failures.append(f"{label}: image URL is unreachable: {url}") + url, why = _mirror_url(source, mirror) + if url is None: + no_probe[name] = why + if url is not None: + done.append(f"probed {url}") + if not url_ok(url): + report.failures.append(f"{label}: image URL is unreachable: {url}") if done: report.checked.append(f"{label}: {', '.join(done)}") checked_enabled = checked_enabled or enabled - elif kind in ("upstream", "nix-vm-test"): + elif offline and kind in ("upstream", "nix-vm-test", "mirror"): report.unchecked.append(f"{label}: offline, and no upstreamUntil") + elif name in no_probe: + report.unchecked.append(f"{label}: {no_probe[name]}") else: report.unchecked.append(f"{label}: a {kind} source has no URL to probe") if not checked_enabled: @@ -414,6 +518,16 @@ def link_check( return report +def _mirror_url(source: Mapping, mirror: Mirror) -> tuple[str | None, str]: + """The URL a mirror source pins, or None and why there is none to probe.""" + if not mirror.configured(): + return None, "the mirror is not configured yet" + asset = source.get("asset") + if asset is None: + return None, "a mirror source that pins no asset yet" + return mirror.url_for(str(source.get("family")), str(asset)), "" + + # --- repin -------------------------------------------------------------------- # A directory listing (the mirrors' autoindex) links each file and dated build @@ -485,20 +599,58 @@ def resolve_arch_boxes(release: str, fetch: Fetcher) -> dict[str, str]: } -def repin_entry(entry: dict, fetch: Fetcher) -> bool: - """Resolve and write an entry's upstream pin. True when it changed.""" +def resolve_mirror(family: str, mirror: Mirror, fetch: Fetcher) -> dict[str, str]: + """The newest build of a mirrored family, from its latest-build manifest. + + The test-images workflow uploads each build under a name of its own and + then replaces ``-latest.json`` with that build's manifest, which + names the asset and its SHA-256 in the SRI form. + """ + if not mirror.configured(): + raise RepinError("the mirror is not configured yet (mirrors.nix base)") + url = mirror.latest_url(family) + try: + manifest = json.loads(fetch(url)) + asset, sha256 = manifest["asset"], manifest["sha256"] + except (KeyError, TypeError, ValueError): + raise RepinError(f"{url} is no manifest with an asset and a sha256") from None + if not _is_asset_name(asset) or not str(asset).startswith(f"{family}-"): + raise RepinError(f"{url} names no asset of {family}: {asset!r}") + if not isinstance(sha256, str) or not sha256.startswith("sha256-"): + raise RepinError(f"{url} names no SRI sha256 for {asset}") + return {"asset": asset, "sha256": sha256} + + +def repin_entry(entry: dict, fetch: Fetcher, mirror: Mirror | None = None) -> bool: + """Resolve and write an entry's pin. True when it changed. + + An upstream entry gets the newest upstream build; a mirror entry stays a + mirror entry and gets the newest build in the assets repository. + """ source = entry.get("source", {}) family = str(source.get("family")) - resolver = RESOLVERS.get(family) - if resolver is None: - raise RepinError(f"no upstream resolver for family {family!r}") - resolved = resolver(str(source.get("release", "")), fetch) + if source.get("kind") == "mirror": + resolved = resolve_mirror(family, mirror or load_mirror_for_repin(), fetch) + else: + resolver = RESOLVERS.get(family) + if resolver is None: + raise RepinError(f"no upstream resolver for family {family!r}") + resolved = resolver(str(source.get("release", "")), fetch) changed = any(source.get(key) != value for key, value in resolved.items()) source.update(resolved) - source["kind"] = "upstream" + if source.get("kind") != "mirror": + source["kind"] = "upstream" return changed +def load_mirror_for_repin() -> Mirror: + """mirrors.nix's seam, with a failure to read it as a repin failure.""" + try: + return load_mirror() + except LinkError as error: + raise RepinError(str(error)) from None + + @dataclass class RepinResult: """The entries a repin changed, and those it could not resolve, with why.""" @@ -515,7 +667,8 @@ def repin( ) -> RepinResult: """Repin the named entries, or with no names every pinned resolvable one. - Without names, a pending entry is left out: it is declared before its + A mirror entry is resolvable: it moves to the newest build its family's + release holds. Without names, a pending entry is left out: it is declared before its release exists (Fedora 45 before it ships), so its upstream has nothing to pin yet, and it is pinned for the first time by naming it. An entry that does not resolve is recorded in ``failed`` and the others are still @@ -529,7 +682,10 @@ def repin( names = [ name for name, entry in table.items() - if str(entry.get("source", {}).get("family")) in RESOLVERS + if ( + str(entry.get("source", {}).get("family")) in RESOLVERS + or entry.get("source", {}).get("kind") == "mirror" + ) and entry.get("source", {}).get("kind") != "pending" ] result = RepinResult() diff --git a/ci/tests/test_distro_images.py b/ci/tests/test_distro_images.py index a10fc7362..68235fa7f 100644 --- a/ci/tests/test_distro_images.py +++ b/ci/tests/test_distro_images.py @@ -46,6 +46,33 @@ def upstream_entry(**overrides: object) -> dict: return entry +# The mirror mirrors.nix names, and an archinstall entry pinned to it. +MIRROR = di.Mirror( + base="https://github.com/WitteShadovv/nails-test-images/releases/download", + tag_prefix="images-", +) +MIRROR_ASSET = "arch-install-2026.11.01-20261125-1.qcow2" + + +def mirror_entry(**source: object) -> dict: + pin: dict = { + "kind": "mirror", + "family": "arch-install", + "release": "rolling", + "asset": MIRROR_ASSET, + "sha256": EMPTY_SRI, + } + pin.update(source) + return upstream_entry( + osId="arch", + prepare="archlinux", + enabled=False, + upstreamUntil=None, + firmware="uefi", + source=pin, + ) + + class SriTest(unittest.TestCase): def test_hex_to_sri(self) -> None: self.assertEqual(di.sri_from_hex(EMPTY_HEX), EMPTY_SRI) @@ -79,6 +106,45 @@ def test_enabled_placeholder_hash_is_rejected(self) -> None: problems = di.validate({"fedora-44": entry}) self.assertTrue(any("placeholder" in p for p in problems), problems) + def test_firmware_is_bios_or_uefi(self) -> None: + self.assertEqual(di.validate({"x": upstream_entry(firmware="uefi")}), []) + self.assertEqual(di.validate({"x": upstream_entry(firmware="bios")}), []) + problems = di.validate({"x": upstream_entry(firmware="coreboot")}) + self.assertEqual(problems, ["x: unknown firmware 'coreboot'"]) + + def test_a_pinned_and_an_unpinned_mirror_entry_are_well_formed(self) -> None: + self.assertEqual(di.validate({"a": mirror_entry()}), []) + self.assertEqual(di.validate({"a": mirror_entry(asset=None, sha256=None)}), []) + + def test_a_mirror_pin_names_its_asset_and_hash_together(self) -> None: + for source in ({"asset": None}, {"sha256": None}): + problems = di.validate({"a": mirror_entry(**source)}) + self.assertEqual( + problems, + ["a: a mirror source names its asset and its sha256 together"], + ) + + def test_a_mirror_pin_is_a_plain_asset_and_an_sri_hash(self) -> None: + problems = di.validate({"a": mirror_entry(asset="../x.qcow2")}) + self.assertEqual(problems, ["a: a mirror asset must be a plain file name"]) + problems = di.validate({"a": mirror_entry(sha256=EMPTY_HEX)}) + self.assertEqual( + problems, ["a: a mirror sha256 must be an SRI hash (sha256-...)"] + ) + problems = di.validate({"a": mirror_entry(family="")}) + self.assertEqual(problems, ["a: a mirror source needs 'family'"]) + + def test_an_unpinned_mirror_entry_cannot_be_enabled(self) -> None: + entry = mirror_entry(asset=None, sha256=None) + entry["enabled"] = True + problems = di.validate({"a": entry}) + self.assertEqual( + problems, ["a: a mirror source cannot be enabled before it is pinned"] + ) + pinned = mirror_entry() + pinned["enabled"] = True + self.assertEqual(di.validate({"a": pinned}), []) + def test_bad_upstream_until_is_flagged(self) -> None: problems = di.validate({"x": upstream_entry(upstreamUntil="soon")}) self.assertTrue(any("upstreamUntil" in p for p in problems), problems) @@ -211,6 +277,43 @@ def nvt_entry(distro: str, image: str, **overrides: object) -> dict: } +class MirrorTest(unittest.TestCase): + def test_reads_the_shipped_seam(self) -> None: + mirror = di.load_mirror() + self.assertEqual(mirror, MIRROR) + self.assertTrue(mirror.configured()) + self.assertEqual( + mirror.url_for("arch-install", "a.qcow2"), + f"{MIRROR.base}/images-arch-install/a.qcow2", + ) + self.assertEqual( + mirror.latest_url("arch-install"), + f"{MIRROR.base}/images-arch-install/arch-install-latest.json", + ) + + def write(self, text: str) -> pathlib.Path: + tmp = tempfile.TemporaryDirectory() + self.addCleanup(tmp.cleanup) + path = pathlib.Path(tmp.name) / "mirrors.nix" + path.write_text(text, encoding="utf-8") + return path + + def test_an_empty_base_is_not_configured(self) -> None: + path = self.write( + 'rec {\n base = "";\n tagFor = family: "images-${family}";\n}\n' + ) + mirror = di.load_mirror(path) + self.assertFalse(mirror.configured()) + self.assertEqual(mirror.tag_prefix, "images-") + + def test_a_seam_that_is_no_plain_string_fails(self) -> None: + path = self.write('rec {\n base = lib.mkDefault "x";\n}\n') + with self.assertRaisesRegex(di.LinkError, "no plain-string base"): + di.load_mirror(path) + with self.assertRaisesRegex(di.LinkError, "cannot read"): + di.load_mirror(path.parent / "missing.nix") + + class LinkCheckTest(unittest.TestCase): def test_offline_shipped_table_checks_the_dates_alone(self) -> None: # Debian and Ubuntu are nix-vm-test pins with no lapse date: offline, @@ -231,8 +334,9 @@ def test_offline_shipped_table_checks_the_dates_alone(self) -> None: self.assertEqual(report.failures, []) def test_shipped_table_probes_every_pin_that_names_a_url(self) -> None: - # Every upstream and nix-vm-test pin is probed, the staged ones too; - # pending and mirror entries name no URL. + # Every upstream and nix-vm-test pin is probed, the staged ones too, + # and so is every mirror entry that pins an asset; a pending entry + # names no URL. probed: list[str] = [] def url_ok(url: str) -> bool: @@ -255,6 +359,7 @@ def url_ok(url: str) -> bool: name for name, entry in table.items() if entry["source"]["kind"] in ("upstream", "nix-vm-test") + or entry["source"].get("asset") is not None ] self.assertEqual(len(probed), len(pinned)) staged = [name for name in pinned if not table[name]["enabled"]] @@ -480,19 +585,79 @@ def test_the_nix_vm_test_list_needs_a_github_lock(self) -> None: with self.assertRaisesRegex(di.LinkError, "locks no nix-vm-test"): di.nix_vm_test_list_url({"nodes": {}}, "debian") - def test_a_mirror_entry_is_listed_as_not_checked(self) -> None: - mirror = upstream_entry( - upstreamUntil=None, - source={"kind": "mirror", "family": "arch-install", "asset": "a"}, - ) - table = { + def mirror_table(self, **source: object) -> dict: + return { "fedora-44": upstream_entry(upstreamUntil="2099-01-01"), - "arch-install": mirror, + "arch-install": mirror_entry(**source), } - report = di.link_check(table, today=THE_DAY, url_ok=lambda _url: True) + + def test_a_mirror_pin_is_probed_at_its_asset(self) -> None: + probed: list[str] = [] + + def url_ok(url: str) -> bool: + probed.append(url) + return True + + report = di.link_check( + self.mirror_table(), today=THE_DAY, url_ok=url_ok, mirror=MIRROR + ) + url = f"{MIRROR.base}/images-arch-install/{MIRROR_ASSET}" + self.assertEqual(report.failures, []) + self.assertIn(url, probed) + self.assertIn(f"arch-install (staged): probed {url}", report.checked) + + def test_a_missing_mirror_asset_fails(self) -> None: + url = f"{MIRROR.base}/images-arch-install/{MIRROR_ASSET}" + report = di.link_check( + self.mirror_table(), + today=THE_DAY, + url_ok=lambda probed: probed != url, + mirror=MIRROR, + ) + self.assertEqual( + report.failures, + [f"arch-install (staged): image URL is unreachable: {url}"], + ) + + def test_a_mirror_entry_without_an_asset_is_listed_as_not_checked(self) -> None: + report = di.link_check( + self.mirror_table(asset=None, sha256=None), + today=THE_DAY, + url_ok=lambda _url: True, + mirror=MIRROR, + ) + self.assertEqual(report.failures, []) + self.assertEqual( + report.unchecked, + ["arch-install (staged): a mirror source that pins no asset yet"], + ) + + def test_a_mirror_that_is_not_configured_is_listed_as_not_checked(self) -> None: + report = di.link_check( + self.mirror_table(), + today=THE_DAY, + url_ok=lambda _url: True, + mirror=di.Mirror(base="", tag_prefix="images-"), + ) self.assertEqual(report.failures, []) self.assertEqual( - report.unchecked, ["arch-install: a mirror source has no URL to probe"] + report.unchecked, + ["arch-install (staged): the mirror is not configured yet"], + ) + + def test_offline_a_mirror_entry_is_not_checked(self) -> None: + def url_ok(url: str) -> bool: + raise AssertionError(f"probed {url} offline") + + report = di.link_check( + self.mirror_table(), + today=THE_DAY, + offline=True, + url_ok=url_ok, + mirror=MIRROR, + ) + self.assertIn( + "arch-install (staged): offline, and no upstreamUntil", report.unchecked ) @@ -676,6 +841,52 @@ def test_one_entry_that_does_not_resolve_holds_back_no_other(self) -> None: self.assertEqual(result.changed, ["fedora-44"]) self.assertEqual(list(result.failed), ["arch-boxes"]) + def latest(self, **manifest: object) -> di.Fetcher: + body = {"asset": MIRROR_ASSET, "sha256": EMPTY_SRI, "size": 1} + body.update(manifest) + return fetcher({MIRROR.latest_url("arch-install"): json.dumps(body)}) + + def test_resolve_mirror_reads_the_latest_manifest(self) -> None: + pin = di.resolve_mirror("arch-install", MIRROR, self.latest()) + self.assertEqual(pin, {"asset": MIRROR_ASSET, "sha256": EMPTY_SRI}) + + def test_resolve_mirror_refuses_a_bad_manifest(self) -> None: + bad = ( + ({"asset": "fedora-44.qcow2"}, "names no asset of arch-install"), + ({"asset": "arch-install/../x"}, "names no asset of arch-install"), + ({"sha256": EMPTY_HEX}, "names no SRI sha256"), + ) + for manifest, message in bad: + with self.assertRaisesRegex(di.RepinError, message): + di.resolve_mirror("arch-install", MIRROR, self.latest(**manifest)) + url = MIRROR.latest_url("arch-install") + with self.assertRaisesRegex(di.RepinError, "no manifest"): + di.resolve_mirror("arch-install", MIRROR, fetcher({url: "[]"})) + with self.assertRaisesRegex(di.RepinError, "not configured"): + di.resolve_mirror("arch-install", di.Mirror("", "images-"), not_found) + + def test_repin_moves_a_mirror_entry_to_the_newest_build(self) -> None: + table = { + "arch-install": mirror_entry(asset="arch-install-old.qcow2"), + "fedora-44": upstream_entry(source=dict(PINNED_44)), + } + fetch = self.latest() + with mock.patch.object(di, "load_mirror", return_value=MIRROR): + result = di.repin(table, [], fetch=fetch) + self.assertEqual(result.changed, ["arch-install"]) + self.assertIn("fedora-44", result.failed) + source = table["arch-install"]["source"] + self.assertEqual(source["kind"], "mirror") + self.assertEqual(source["asset"], MIRROR_ASSET) + self.assertEqual(source["sha256"], EMPTY_SRI) + + def test_a_mirror_entry_without_a_manifest_fails_alone(self) -> None: + table = {"arch-install": mirror_entry()} + with mock.patch.object(di, "load_mirror", return_value=MIRROR): + result = di.repin(table, ["arch-install"], fetch=not_found) + self.assertEqual(result.changed, []) + self.assertIn("404", result.failed["arch-install"]) + def test_repin_unknown_family_is_reported(self) -> None: source = {"kind": "upstream", "family": "gentoo", "release": "1"} table = {"x": upstream_entry(source=source)} diff --git a/nix/distro-tests/images.json b/nix/distro-tests/images.json index dbe875d9d..34a8e5aee 100644 --- a/nix/distro-tests/images.json +++ b/nix/distro-tests/images.json @@ -142,6 +142,7 @@ "memory": 2048, "enabled": false, "upstreamUntil": null, + "firmware": "uefi", "prepare": "archlinux", "source": { "kind": "mirror", diff --git a/nix/distro-tests/images.nix b/nix/distro-tests/images.nix index e1a4082af..c597247f7 100644 --- a/nix/distro-tests/images.nix +++ b/nix/distro-tests/images.nix @@ -30,6 +30,9 @@ # weekly link check probes the URL nix-vm-test pins at the # locked revision, and a newer lock repins it. A self-hosted # mirror asset carries no date; +# firmware optional: "uefi" boots the image with OVMF, for an image +# that has no BIOS boot loader (the archinstall image's +# systemd-boot); absent or "bios", QEMU's default SeaBIOS; # prepare which image-preparation path builds the bootable qcow2 # ("nix-vm-test" for a pinned nix-vm-test release, "fedora" or # "archlinux" for nix-vm-test's per-family prepare function); @@ -65,8 +68,12 @@ # fixed by the flake.lock pin of it; # { kind = "upstream"; url; name; sha256; } a hash-pinned upstream cloud image # fetched with `fetchurl`; -# { kind = "mirror"; asset; sha256; } an image with no upstream URL, from -# the assets-repo mirror (mirrors.nix); +# { kind = "mirror"; family; asset; sha256; } +# an image with no upstream URL, from +# the assets-repo mirror (mirrors.nix): +# the release of `family` holds the +# asset. `asset` and `sha256` are both +# null until it is first pinned; # { kind = "pending"; } declared but not pinned yet (a # pre-release distro, or an image the # hosting does not produce yet). @@ -87,6 +94,10 @@ let "fedora" "archlinux" ]; + knownFirmware = [ + "bios" + "uefi" + ]; knownKinds = [ "nix-vm-test" "upstream" @@ -178,6 +189,9 @@ let assert lib.assertMsg ( entry.upstreamUntil == null || builtins.isString entry.upstreamUntil ) "distro image ${name}: upstreamUntil must be null or a YYYY-MM-DD string"; + assert lib.assertMsg (builtins.elem (entry.firmware or "bios") + knownFirmware + ) "distro image ${name}: firmware must be one of ${lib.concatStringsSep ", " knownFirmware}"; # A pin that is still the placeholder hash may not be in the matrix: it # would fail its own fetch. This is what keeps an unpinned image `enabled` # from slipping through. @@ -188,6 +202,21 @@ let "distro image ${name}: still has the placeholder hash; run `python3 -m ci.distro_images repin ${name}` before enabling it"; assert (kind == "upstream") -> (requires "url" && requires "name" && requires "sha256"); assert (kind == "nix-vm-test") -> (requires "distro" && requires "image"); + # A mirror pin names its asset and that asset's hash together, or neither + # while the image is not hosted yet; only a pinned one may be enabled. + assert (kind == "mirror") -> requires "family"; + assert lib.assertMsg ( + kind != "mirror" + || ((entry.source.asset or null) == null) == ((entry.source.sha256 or null) == null) + ) "distro image ${name}: a mirror source names its asset and its sha256 together, or neither"; + assert lib.assertMsg ( + kind != "mirror" + || (entry.source.sha256 or null) == null + || lib.hasPrefix "sha256-" entry.source.sha256 + ) "distro image ${name}: a mirror sha256 must be an SRI hash (sha256-...)"; + assert lib.assertMsg ( + !(entry.enabled && kind == "mirror" && (entry.source.asset or null) == null) + ) "distro image ${name}: a mirror source cannot be enabled before its asset is pinned"; assert checkKnownFailed name (entry.knownFailedUnits or null); entry; in diff --git a/nix/distro-tests/lib/distro-vm.nix b/nix/distro-tests/lib/distro-vm.nix index 0b4e9b9f3..fe3034ada 100644 --- a/nix/distro-tests/lib/distro-vm.nix +++ b/nix/distro-tests/lib/distro-vm.nix @@ -143,6 +143,38 @@ let else throw "distro image ${entry.osId} ${entry.release}: no prepare function for '${entry.prepare}'"; + # The QEMU options an entry's firmware needs, or null for QEMU's default + # SeaBIOS. nix-vm-test starts QEMU with no firmware option and appends + # $QEMU_OPTS to its command line, so an image whose only boot loader is a + # UEFI one (the archinstall image's systemd-boot) gets OVMF through it. The + # combined OVMF image keeps no boot entries from one boot to the next, so the + # firmware starts the ESP's fallback loader, EFI/BOOT/BOOTX64.EFI, every time. + firmwareOpts = + entry: if (entry.firmware or "bios") == "uefi" then "-bios ${vmPkgs.OVMF.fd}/FV/OVMF.fd" else null; + + # Hand a built test its firmware: the sandboxed derivation gets QEMU_OPTS in + # its build environment, and a host driver a wrapper that sets it (before + # whatever QEMU_OPTS the caller set) and runs the driver. + withFirmware = + entry: target: test: + let + opts = firmwareOpts entry; + in + if opts == null then + test + else if target == "sandboxed" then + test.overrideAttrs (_: { + QEMU_OPTS = opts; + }) + else + (vmPkgs.writeShellScriptBin "test-driver" '' + export QEMU_OPTS="${opts}''${QEMU_OPTS:+ $QEMU_OPTS}" + exec ${test}/bin/test-driver "$@" + '').overrideAttrs + (_: { + passthru = test.passthru or { }; + }); + # Evaluates, but refuses to build, so `nix eval` of every entry still succeeds # while an unpinned or unhosted image cannot be booted by accident. unavailable = @@ -218,14 +250,15 @@ in if originalImage == null then unavailable entry "source kind '${kind}' is not pinned or hosted yet" else - (generic.makeVmTest { - name = "vm-test-${entry.osId}-${entry.release}"; - inherit - system - testScript - sharedDirs - memorySize - ; - image = prepareImage entry originalImage; - }).${target}; + withFirmware entry target + (generic.makeVmTest { + name = "vm-test-${entry.osId}-${entry.release}"; + inherit + system + testScript + sharedDirs + memorySize + ; + image = prepareImage entry originalImage; + }).${target}; } diff --git a/nix/distro-tests/mirrors.nix b/nix/distro-tests/mirrors.nix index 9adfef4a9..66c12694d 100644 --- a/nix/distro-tests/mirrors.nix +++ b/nix/distro-tests/mirrors.nix @@ -1,8 +1,8 @@ # Where a prepared test image is fetched from, and the one place that knows it. # # The desktop test images are not committed to this repository: they are built -# every night in CI from the pinned upstream cloud image plus a pinned package -# snapshot, and each result is published as a release asset of a separate public +# every night in CI from pinned inputs (an upstream cloud image or installer +# ISO, and a package snapshot), and each result is published as a release asset of a separate public # assets repository (every asset stays under the 2 GiB release-asset limit). # An entry whose own upstream carries a bootable cloud image (Debian and Ubuntu # through nix-vm-test, Fedora and arch-boxes through a hash-pinned `fetchurl`) @@ -10,18 +10,20 @@ # archinstall image, which is assembled rather than downloaded -- can only come # from this mirror. # -# `base` is the release-download root of that assets repository. It is empty -# until the assets repository exists, and the `distro-images` check reads an -# empty base as "mirror not configured yet" rather than as an error, so the seam -# can land before the hosting does. The weekly link check probes no mirror -# asset: it lists every mirror entry as not checked. Fill it with -# "https://github.com///releases/download" -# once the repository is created; nothing else moves. +# `base` is the release-download root of that assets repository, +# WitteShadovv/nails-test-images. The test-images workflow +# (.github/workflows/test-images.yml) builds each image every night and uploads +# it there under a name of its own, so a pin in images.json keeps naming the +# same file while newer builds land beside it. ci/distro_images.py reads `base` +# and the tag shape below out of this file, for the weekly link check and for +# `repin`, so both stay written as plain strings. An empty base would read as +# "mirror not configured yet": no mirror entry is then fetched or checked. rec { - base = ""; + base = "https://github.com/WitteShadovv/nails-test-images/releases/download"; # The release tag that holds a family's nightly assets. One rolling tag per - # family keeps a stable download URL while the asset behind it is refreshed. + # family keeps every build of it under one release, beside the + # `-latest.json` manifest that names the newest. tagFor = family: "images-${family}"; # The download URL for one mirrored asset, or null when no mirror is set or diff --git a/nix/e2e-tests/README.md b/nix/e2e-tests/README.md index c573d4943..009590681 100644 --- a/nix/e2e-tests/README.md +++ b/nix/e2e-tests/README.md @@ -1033,7 +1033,13 @@ The scenario fails when: Once a distribution's backend and detection have landed, add one entry to `nix/distro-tests/images.json` with `enabled` set to `true`; an upstream Fedora -or Arch image is pinned with `python3 -m ci.distro_images repin `. The +or Arch image is pinned with `python3 -m ci.distro_images repin `. An +image that no upstream publishes, such as the archinstall image, is a `mirror` +entry instead: `.github/workflows/test-images.yml` builds it every night and +publishes each build to the assets repository that +`nix/distro-tests/mirrors.nix` names, and the same `repin ` pins the +newest build. An image whose only boot loader is a UEFI one sets `firmware` to +`uefi`, and its VMs boot with OVMF. The scenario, the flake's `e2e-distro` attribute and the CI matrix are all derived by mapping over this table, so nothing else changes. Once its runs have printed the failed units of every listing, give it a `knownFailedUnits`, with an empty From 2014dc644949b86cedfa58e486b36e4c43f09e8a Mon Sep 17 00:00:00 2001 From: WitteShadovv Date: Wed, 25 Nov 2026 09:39:37 +0100 Subject: [PATCH 02/13] feat(distro): build and publish the archinstall test image nightly No upstream publishes an archinstall image, so the project builds it. nix/distro-tests/arch-install is the builder (the flake's arch-install-image-builder): it boots the kernel of the Arch ISO that inputs.json pins by hash under OVMF, with a blank disk on IDE as the harness boots it, and the ISO's automated-script hook runs install.sh. That pins the mirrorlist to the Arch Linux Archive snapshot of the ISO's day and runs the ISO's archinstall unattended with its own default btrfs layout (1 GiB ESP at /boot, @, @home, @log and @pkg, compress=zstd), systemd-boot loader entries, zram, a user arch and the ISO's network setup. It adds console=ttyS0 to the loader entries, empties the package cache, checks the layout, boots the result once to its login prompt and writes the compressed qcow2 with its sha256 and a manifest. test-images.yml runs it nightly and on dispatch, uploads each build under a name of its own to the release images-arch-install of WitteShadovv/nails-test-images, replaces arch-install-latest.json, prunes the old builds that no images.json of main, next or the commit pins, and checks the public download against the build's hash. Only its upload step reads NAILS_TEST_IMAGES_TOKEN, and no pull request publishes. inputs.json joins images.json in the detect-secrets exclusions: its hash is an SRI digest, not a secret. --- .github/workflows/test-images.yml | 317 ++++++++++++++++++ .pre-commit-config.yaml | 2 +- docs/ci.md | 18 +- flake.nix | 3 + nix/distro-tests/arch-install/build.sh | 168 ++++++++++ nix/distro-tests/arch-install/default.nix | 55 +++ nix/distro-tests/arch-install/disk_layout.py | 79 +++++ nix/distro-tests/arch-install/inputs.json | 15 + nix/distro-tests/arch-install/install.sh | 142 ++++++++ .../arch-install/user_configuration.json | 31 ++ .../arch-install/user_credentials.json | 10 + nix/distro-tests/probe/README.md | 3 +- 12 files changed, 838 insertions(+), 5 deletions(-) create mode 100644 .github/workflows/test-images.yml create mode 100644 nix/distro-tests/arch-install/build.sh create mode 100644 nix/distro-tests/arch-install/default.nix create mode 100644 nix/distro-tests/arch-install/disk_layout.py create mode 100644 nix/distro-tests/arch-install/inputs.json create mode 100644 nix/distro-tests/arch-install/install.sh create mode 100644 nix/distro-tests/arch-install/user_configuration.json create mode 100644 nix/distro-tests/arch-install/user_credentials.json diff --git a/.github/workflows/test-images.yml b/.github/workflows/test-images.yml new file mode 100644 index 000000000..24ed2fe81 --- /dev/null +++ b/.github/workflows/test-images.yml @@ -0,0 +1,317 @@ +name: Test images + +# Builds the test images that no upstream publishes and publishes them to the +# assets repository that nix/distro-tests/mirrors.nix names, +# WitteShadovv/nails-test-images: today the archinstall image, the +# `arch-install` entry of nix/distro-tests/images.json. +# +# build runs nix/distro-tests/arch-install (the arch-install-image-builder +# flake attribute) on a hosted KVM runner: the ISO that inputs.json +# pins by hash boots under UEFI, archinstall installs from the +# package snapshot it names, the result boots once to a login +# prompt, and the compressed qcow2 (under 2 GiB) is kept as an +# artifact with its SHA-256 and manifest +# publish uploads them to the release images-arch-install (created when it +# is missing; an asset of the same name is replaced), replaces +# arch-install-latest.json with the new manifest, and deletes the +# older builds beyond the newest three that no images.json of +# main, next or this commit pins +# verify downloads the asset from its public URL and checks its SHA-256 +# +# Every build gets a name of its own (the ISO version, the UTC date and the +# run ID), so a nightly build never replaces the asset that images.json pins; +# a re-run of the same run replaces its own upload. `python3 -m ci.distro_images +# repin arch-install` moves the pin to the newest build, which the latest +# manifest names. +# +# nightly schedule build, publish and verify (runs on main only) +# dispatch the same on any branch, unless `publish` is off +# pull request build only, when the builder or this file changes +# +# The upload token, NAILS_TEST_IMAGES_TOKEN, is a fine-grained token with +# Contents read and write on the assets repository alone. Only the upload step +# of the publish job sees it; that job runs no code of the build, and it never +# runs for a pull request. + +on: + schedule: + # Nightly at 01:23 UTC, before the NixOS (02:17) and distro (03:41) lanes. + - cron: "23 1 * * *" + pull_request: + branches: [main, next] + paths: + - nix/distro-tests/arch-install/** + - .github/workflows/test-images.yml + workflow_dispatch: + inputs: + publish: + description: Upload the image to the assets repository after it built + type: boolean + default: true + +permissions: + contents: read + +concurrency: + # A new push to a pull request cancels its build in progress; a scheduled or + # dispatched run waits for the one before it, so two uploads never prune + # each other's assets. + group: test-images-${{ github.event_name == 'pull_request' && format('pr-{0}', github.event.pull_request.number) || 'publish' }} + cancel-in-progress: ${{ github.event_name == 'pull_request' }} + +defaults: + run: + shell: bash + +env: + ASSETS_REPO: WitteShadovv/nails-test-images + FAMILY: arch-install + RELEASE_TAG: images-arch-install + # The newest builds a prune keeps, besides the ones an images.json pins. + KEEP_BUILDS: 3 + +jobs: + build: + name: Build the archinstall image + runs-on: ubuntu-26.04 + # Booting the ISO and installing from the Arch Linux Archive takes 15 to + # 40 minutes, depending on the archive's speed. + timeout-minutes: 120 + outputs: + asset: ${{ steps.name.outputs.asset }} + sha256: ${{ steps.result.outputs.sha256 }} + sha256-hex: ${{ steps.result.outputs.sha256-hex }} + + steps: + - name: Checkout repository + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 + with: + persist-credentials: false + + # install-nix-action (inside setup-nix) opens /dev/kvm to the runner user + # on hosted runners, which the install VM needs. + - name: Set up Nix + uses: ./.github/actions/setup-nix + + - name: Name the build + id: name + env: + RUN_ID: ${{ github.run_id }} + run: | + iso=$(jq -er .iso.version nix/distro-tests/arch-install/inputs.json) + asset="$FAMILY-$iso-$(date -u +%Y%m%d)-$RUN_ID.qcow2" + echo "asset=$asset" >> "$GITHUB_OUTPUT" + echo "Building $asset" + + - name: Build the image + env: + ASSET: ${{ steps.name.outputs.asset }} + run: nix run -L .#arch-install-image-builder -- "$RUNNER_TEMP/image" "$ASSET" + + - name: Record the result + id: result + env: + ASSET: ${{ steps.name.outputs.asset }} + run: | + manifest="$RUNNER_TEMP/image/$ASSET.json" + sri=$(jq -er .sha256 "$manifest") + hex=$(jq -er .sha256Hex "$manifest") + size=$(jq -er .size "$manifest") + echo "sha256=$sri" >> "$GITHUB_OUTPUT" + echo "sha256-hex=$hex" >> "$GITHUB_OUTPUT" + { + echo "## archinstall image" + echo + echo "| | |" + echo "|---|---|" + echo "| Asset | \`$ASSET\` |" + echo "| Size | $size bytes |" + echo "| SHA-256 | \`$hex\` |" + echo "| images.json sha256 | \`$sri\` |" + echo "| ISO | \`$(jq -r .iso.name "$manifest")\` |" + echo "| Packages | $(jq -r .packages.snapshot "$manifest") snapshot, $(jq -r '.installed | length' "$manifest") installed |" + echo "| archinstall | \`$(jq -r .archinstall "$manifest")\` |" + } >> "$GITHUB_STEP_SUMMARY" + echo "sha256 $hex ($sri)" + + - name: Keep the image + uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2 + with: + name: arch-install-image + path: | + ${{ runner.temp }}/image/*.qcow2 + ${{ runner.temp }}/image/*.qcow2.sha256 + ${{ runner.temp }}/image/*.qcow2.json + retention-days: 3 + compression-level: 0 + if-no-files-found: error + + - name: Keep the logs + if: ${{ !cancelled() }} + uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2 + with: + name: arch-install-logs + path: ${{ runner.temp }}/image/logs/ + retention-days: 14 + if-no-files-found: warn + + publish: + name: Publish the archinstall image + needs: build + # Only a run of this repository's own branches publishes: the nightly + # schedule, which runs on main, and a dispatch, from any branch. Never a + # pull request. + if: >- + github.repository == 'WitteShadovv/nails' + && startsWith(github.ref, 'refs/heads/') + && (github.event_name == 'schedule' + || (github.event_name == 'workflow_dispatch' && inputs.publish)) + runs-on: ubuntu-26.04 + timeout-minutes: 30 + permissions: + contents: read + + steps: + - name: Fetch the image + uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v6.0.0 + with: + name: arch-install-image + path: ${{ runner.temp }}/image + + - name: Check the image against the build + env: + ASSET: ${{ needs.build.outputs.asset }} + SHA256_HEX: ${{ needs.build.outputs.sha256-hex }} + working-directory: ${{ runner.temp }}/image + run: | + sha256sum -c "$ASSET.sha256" + [ "$(sha256sum "$ASSET" | cut -d' ' -f1)" = "$SHA256_HEX" ] + size=$(stat -c %s "$ASSET") + [ "$size" -lt $((2 * 1024 * 1024 * 1024)) ] + cp "$ASSET.json" "$FAMILY-latest.json" + + # The assets a prune must keep: the one each images.json of main, next + # and this commit pins, read from the public repository without a token. + - name: List the pinned assets + env: + REPOSITORY: ${{ github.repository }} + SHA: ${{ github.sha }} + run: | + : > "$RUNNER_TEMP/pinned" + for ref in main next "$SHA"; do + url="https://raw.githubusercontent.com/$REPOSITORY/$ref/nix/distro-tests/images.json" + if table=$(curl -fsSL --retry 3 "$url"); then + jq -r --arg family "$FAMILY" \ + '.[] | .source | select(.kind == "mirror" and .family == $family and .asset != null) | .asset' \ + <<< "$table" >> "$RUNNER_TEMP/pinned" + else + echo "::warning::Could not read images.json of $ref; its pin is not protected from the prune." + fi + done + sort -u -o "$RUNNER_TEMP/pinned" "$RUNNER_TEMP/pinned" + echo "Pinned assets:" + cat "$RUNNER_TEMP/pinned" + + # The one step that holds the upload token. It runs gh alone, on the + # files the build job produced and their checked hash. + - name: Upload to the assets repository + env: + GH_TOKEN: ${{ secrets.NAILS_TEST_IMAGES_TOKEN }} # zizmor: ignore[secrets-outside-env] + ASSET: ${{ needs.build.outputs.asset }} + working-directory: ${{ runner.temp }}/image + run: | + if [ -z "$GH_TOKEN" ]; then + echo "::error::NAILS_TEST_IMAGES_TOKEN is not set." + exit 1 + fi + if ! gh release view "$RELEASE_TAG" --repo "$ASSETS_REPO" --json tagName > /dev/null 2>&1; then + gh release create "$RELEASE_TAG" --repo "$ASSETS_REPO" \ + --title "$FAMILY test images" \ + --notes "Nightly builds of the $FAMILY test image of WitteShadovv/nails (nix/distro-tests/arch-install). Each build is a qcow2 with its .sha256 and .json manifest; $FAMILY-latest.json names the newest. Test data, not a release of NAILS." \ + --latest=false + fi + gh release upload "$RELEASE_TAG" --repo "$ASSETS_REPO" --clobber \ + "$ASSET" "$ASSET.sha256" "$ASSET.json" + gh release upload "$RELEASE_TAG" --repo "$ASSETS_REPO" --clobber \ + "$FAMILY-latest.json" + + # Prune: keep the newest builds and every pinned one. + release_id=$(gh api "repos/$ASSETS_REPO/releases/tags/$RELEASE_TAG" --jq .id) + gh api --paginate "repos/$ASSETS_REPO/releases/$release_id/assets" \ + --jq '.[] | [.id, .name, .created_at] | @tsv' > "$RUNNER_TEMP/assets" + grep -P '\t'"$FAMILY"'-[^\t]+\.qcow2\t' "$RUNNER_TEMP/assets" \ + | sort -t "$(printf '\t')" -k3,3r | cut -f2 > "$RUNNER_TEMP/builds" || true + tail -n +"$((KEEP_BUILDS + 1))" "$RUNNER_TEMP/builds" | while read -r build; do + if [ "$build" = "$ASSET" ] || grep -qxF "$build" "$RUNNER_TEMP/pinned"; then + continue + fi + for name in "$build" "$build.sha256" "$build.json"; do + id=$(awk -F '\t' -v n="$name" '$2 == n { print $1 }' "$RUNNER_TEMP/assets") + if [ -n "$id" ]; then + echo "Deleting $name" + gh api -X DELETE "repos/$ASSETS_REPO/releases/assets/$id" + fi + done + done + + verify: + name: Verify the published image + needs: [build, publish] + runs-on: ubuntu-26.04 + timeout-minutes: 20 + + steps: + - name: Download and check the published asset + env: + ASSET: ${{ needs.build.outputs.asset }} + SHA256: ${{ needs.build.outputs.sha256 }} + SHA256_HEX: ${{ needs.build.outputs.sha256-hex }} + run: | + base="https://github.com/$ASSETS_REPO/releases/download/$RELEASE_TAG" + cd "$RUNNER_TEMP" + curl -fsSL --retry 5 -o "$ASSET" "$base/$ASSET" + hex=$(sha256sum "$ASSET" | cut -d' ' -f1) + if [ "$hex" != "$SHA256_HEX" ]; then + echo "::error::The published $ASSET has SHA-256 $hex, the build $SHA256_HEX." + exit 1 + fi + curl -fsSL --retry 5 -o latest.json "$base/$FAMILY-latest.json" + [ "$(jq -r .asset latest.json)" = "$ASSET" ] + [ "$(jq -r .sha256 latest.json)" = "$SHA256" ] + { + echo "## Published" + echo + echo "$base/$ASSET" + echo + echo "SHA-256 \`$hex\` matches the build. To pin it in nix/distro-tests/images.json:" + echo + echo " \"asset\": \"$ASSET\"," + echo " \"sha256\": \"$SHA256\"" + } >> "$GITHUB_STEP_SUMMARY" + echo "published $base/$ASSET sha256 $hex" + + # A nightly nobody watches: a red one opens or comments on the + # 'CI red: Test images' issue, and the next green run closes it. Only runs + # of main report; a dispatch on another branch is watched by whoever + # started it. + report-status: + name: Report status + needs: [build, publish, verify] + if: ${{ !cancelled() && github.event_name == 'schedule' && github.ref == 'refs/heads/main' }} + runs-on: ubuntu-26.04 + timeout-minutes: 5 + permissions: + contents: read + issues: write # open, comment on and close the tracking issue + + steps: + - name: Checkout the report action + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 + with: + persist-credentials: false + sparse-checkout: .github/actions/report-status + + - name: Report status + uses: ./.github/actions/report-status + with: + needs: ${{ toJSON(needs) }} diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 798c93e08..7c51235f0 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -35,7 +35,7 @@ repos: rev: v1.5.0 hooks: - id: detect-secrets - exclude: (.*\.lock|^fuzz/seeds/.*|^nails-base/src/state/golden/.*|^nix/distro-tests/images\.json$|^nix/distro-tests/rpms/[^/]+\.json$|^ci/tests/test_distro_images\.py$|^docs/assets/screenshots/status-json\.txt$)$ + exclude: (.*\.lock|^fuzz/seeds/.*|^nails-base/src/state/golden/.*|^nix/distro-tests/images\.json$|^nix/distro-tests/arch-install/inputs\.json$|^nix/distro-tests/rpms/[^/]+\.json$|^ci/tests/test_distro_images\.py$|^docs/assets/screenshots/status-json\.txt$)$ additional_dependencies: ["pyyaml", "gibberish-detector"] # Local hooks for Nix, shell and project-specific checks diff --git a/docs/ci.md b/docs/ci.md index aef11fa44..764c828f0 100644 --- a/docs/ci.md +++ b/docs/ci.md @@ -23,6 +23,7 @@ Tier 3 is everything a contributor must pass to merge. The informational `fuzz` | `.github/workflows/pr-title.yml` | Pull request opened, edited, synchronized, reopened | `pr-title` | 3 | `ubuntu-26.04` | the commit-msg hook | | `.github/workflows/e2e.yml` | PRs to `main` and `next`, push to either, nightly, dispatch, `workflow_call` | `e2e-result` | 3 (affected) and 4 (nightly full) | `runner` input, default `ubuntu-26.04` | `just e2e` | | `.github/workflows/distro-e2e.yml` | Nightly, PRs to `main` and `next` (the records and refusal jobs when the change touches what they are built from, the smoke scenarios too with the `distro-e2e` label), dispatch, `workflow_call` | — (`distro-result` fails on a records or refusal job; the smoke scenarios, the probes and the staged suite are informational) | 3 (records and refusal on pull requests, outside its budget) and 4 | `runner` input, default `ubuntu-26.04` (KVM) | `nix build .#legacyPackages.x86_64-linux.e2e-distro.`; a records scenario, a refusal, a probe or a staged driver runs its driver ([details](../nix/e2e-tests/README.md#running-and-ci), [probes](../nix/distro-tests/probe/README.md#regenerating)) | +| `.github/workflows/test-images.yml` | Nightly, dispatch, PRs to `main` and `next` that change the image builder (build only) | — | 4 | `ubuntu-26.04` (KVM) | `nix run .#arch-install-image-builder -- ` ([details](#the-test-images-test-imagesyml)) | | `.github/workflows/next-nightly.yml` | Nightly, dispatch: starts the nightly `e2e.yml` and `distro-e2e.yml` runs of `next` | — | 4 | `ubuntu-26.04` | — | | `.github/workflows/oracle-real-nightly.yml` | Nightly, dispatch | — (informational) | 4 | produce and produce-btrfs on `ubuntu-26.04` (KVM), scan, scan-btrfs, scan-btrfs-real and btrfs-wtmp-extents on `ubuntu-24.04` | `nix build .#legacyPackages.x86_64-linux.e2e.oracle-images.driver`, its `bin/nixos-test-driver -o `, then `sudo env ORACLE_IMAGES_DIR=/forensics ci/oracle/run-scan.sh `; for the btrfs disks, the `e2e-distro."-oracle-images"` driver's `bin/test-driver` with `NAILS_ORACLE_OUT=` ([details](#the-forensic-oracle-nightly)) | | `.github/workflows/scheduled.yml` | Weekly, twice-weekly and monthly schedules, dispatch with a `task` input | — | 4 | `ubuntu-26.04` | `just deny-full`, `just stress`, `cargo bench`, `just mutants`, `just kani` | @@ -96,7 +97,7 @@ The policy is compiled in, so `cargo build`, clippy and every editor enforce it ### Tracking issues for unattended runs -Runs nobody watches end in a job that calls the `.github/actions/report-status` composite action: `ci.yml` on pushes to `main`, `e2e.yml` on pushes to `main` and nightly, `scheduled.yml`, `fuzz.yml` on its schedules, `scorecard.yml`, `codeql.yml`, `oracle-real-nightly.yml` and `soak.yml` on `main`, and `release.yml`. It keeps one open issue per workflow and label in step with the latest run: +Runs nobody watches end in a job that calls the `.github/actions/report-status` composite action: `ci.yml` on pushes to `main`, `e2e.yml` on pushes to `main` and nightly, `scheduled.yml`, `fuzz.yml` on its schedules, `scorecard.yml`, `codeql.yml`, `oracle-real-nightly.yml`, `soak.yml` and `test-images.yml` on `main`, and `release.yml`. It keeps one open issue per workflow and label in step with the latest run: - A failed or cancelled job opens the issue (label `ci-red`, title `CI red: `; `CI red: main` for `ci.yml`), or comments on it with the run link and the red jobs when it is already open. The runs of `next` keep issues of their own, and so does `next-nightly.yml`, which starts them (see [The integration branch `next`](#the-integration-branch-next)). - A run in which every reported job passed closes the issue. A run that skipped some jobs without a failure (for example a manual dispatch of a single `scheduled.yml` task) leaves it as it is. @@ -158,9 +159,19 @@ There used to be a second, per-PR container lane (`distro-smoke` in `ci.yml`). I - **Staged scenarios.** A dispatch or call with `suite` set to `staged` runs the scenarios of each image staged for its family's admission (`stagedImages` in `nix/distro-tests/default.nix`, today `arch-boxes`, not every disabled entry of the image table) instead of the other suites: the image's smoke scenario and its login- and boot-record scenario, each with a test-only build of `nails` that admits the family (`nix/distro-tests/lib/admitted.nix`) and is never released. `distros` then names them, such as `arch-boxes-smoke` and `arch-boxes-records`; empty runs every one. Each is a derivation that `nix build` runs in the Nix build sandbox, as a smoke scenario is, in a job of its own, and its failure only warns. No nightly or pull request runs them. The commit that admits a family takes its image out of that list and enables it in the image table, which also makes the oracle nightly's driver run the release binary on it. - **Staged drivers.** The staged suite also runs the drivers of Fedora's admission gate (`nix/distro-tests/fedora-gate.nix`), for each pinned Fedora image: `-rpms`, which resolves the closure of tuned, firewalld and ABRT on the image itself from the release's own repository; `-gate`, the gate scenario on the image booted with SELinux enforcing, with the release binary and the locked closure installed offline; `-gate-noda`, the same with the policy's dontaudit rules off; and `-btrfs`, the btrfs scan controls on the stock image ([details](../nix/e2e-tests/README.md#the-admission-gate-of-fedora)). `distros` names them as it names the staged scenarios, such as `fedora-44-gate`; empty runs every one whose image is pinned, with every staged scenario. Each driver is one job, and at most `max-jobs` of the suite's jobs run at once. A staged driver is a host driver, built and run as a probe is, with `NAILS_GATE_OUT` naming where it writes. The job uploads the `staged-` artifact, kept 30 days, with what the driver wrote and its log, also when the driver failed, and then fails with the driver's exit status; that failure only warns, as a staged scenario's does. - **Adding a distribution** is one entry in `nix/distro-tests/images.json`, which `nix/distro-tests/images.nix` checks; see `nix/e2e-tests/README.md`. The image hashes and the `nix-vm-test` lock are pinned on a networked KVM host, not in the sandbox. -- **Image links.** The weekly `distro-images` task of `scheduled.yml` runs `python3 -m ci.distro_images link-check` over every entry of `nix/distro-tests/images.json`, the disabled ones too: a disabled image stays out of the smoke matrix until a change enables it, and the probes (`nix/distro-tests/probe.nix`) boot the Arch ones before then, but its pin lapses all the same. It fails 14 days before an entry's `upstreamUntil` date, and when the image URL an entry pins no longer answers: an upstream entry's own URL, or for a `nix-vm-test` entry the dated Debian or Ubuntu URL that `nix-vm-test` pins at the revision `flake.lock` locks, read from its image list. A pending or mirror entry names no URL, so only a date it carries is checked. It names each entry it checked, marking each disabled one `(staged)`, and fails when it could check no enabled entry, whatever it found for the disabled ones. Of those, only the images `stagedImages` lists run in the staged suite. `python3 -m ci.distro_images repin` bumps the upstream pins; `--all` leaves out a pending entry, which is pinned the first time by naming it, and an entry that does not resolve fails the command without holding back the others. +- **Image links.** The weekly `distro-images` task of `scheduled.yml` runs `python3 -m ci.distro_images link-check` over every entry of `nix/distro-tests/images.json`, the disabled ones too: a disabled image stays out of the smoke matrix until a change enables it, and the probes (`nix/distro-tests/probe.nix`) boot the Arch ones before then, but its pin lapses all the same. It fails 14 days before an entry's `upstreamUntil` date, and when the image URL an entry pins no longer answers: an upstream entry's own URL, or for a `nix-vm-test` entry the dated Debian or Ubuntu URL that `nix-vm-test` pins at the revision `flake.lock` locks, read from its image list. A `mirror` entry is probed at the asset it pins in the assets repository that `nix/distro-tests/mirrors.nix` names (see [The test images](#the-test-images-test-imagesyml)); one that pins no asset yet is listed as not checked. A pending entry names no URL, so only a date it carries is checked. It names each entry it checked, marking each disabled one `(staged)`, and fails when it could check no enabled entry, whatever it found for the disabled ones. Of those, only the images `stagedImages` lists run in the staged suite. `python3 -m ci.distro_images repin` bumps the upstream pins, and moves a mirror entry to the newest build its release's `-latest.json` names; `--all` leaves out a pending entry, which is pinned the first time by naming it, and an entry that does not resolve fails the command without holding back the others. - **Concurrency.** The runs of a pull request share a concurrency group, so a new push, or adding the `distro-e2e` label, cancels the run in progress, and the cancelled run reports nothing: `distro-result` runs only in a run that was not cancelled. Every label added to a pull request starts a run, but only a run for the `distro-e2e` label tests anything. A run for any other label skips `plan` and the VM jobs, passes, and gets a group of its own, so it can neither cancel a run that tests nor be cancelled. Such a run's `distro-result` passes without testing anything, under the same name as a run that tests, so revisit this before `distro-result` becomes a required check. A draft that becomes ready runs nothing again. A scheduled or dispatched run never cancels a run in progress: it waits for an earlier run of the same event and ref, and since GitHub keeps only one waiting run per group, a newer run replaces one that has not started. A dispatch of one suite waits in a group of its own, so it neither waits for a run of every suite on the same branch nor replaces one. A call counts as its caller's event, so call the workflow from a scheduled, dispatched or push-triggered workflow, not from a pull request one. +### The test images (`test-images.yml`) + +The archinstall image (the `arch-install` entry of `nix/distro-tests/images.json`) has no upstream that publishes it, so `test-images.yml` builds it every night from pinned inputs and publishes it as a release asset of the public assets repository `WitteShadovv/nails-test-images`, the `base` of `nix/distro-tests/mirrors.nix`. Each family has one release, `images-` (`tagFor`), and every asset stays under GitHub's 2 GiB limit, so none is split. + +- **Build.** The `build` job runs `nix run .#arch-install-image-builder` (`nix/distro-tests/arch-install/`) on a hosted `ubuntu-26.04` runner for KVM. It boots the kernel of the Arch ISO that `inputs.json` pins by hash under UEFI (OVMF), with a blank 16 GiB disk on IDE, the bus the test harness boots it from. The ISO's own automated-script hook runs `install.sh`, which points the mirrorlist at the dated Arch Linux Archive snapshot of the same day and runs the ISO's archinstall unattended: archinstall's own default layout for one btrfs disk (a 1 GiB ESP at `/boot`, the `@`, `@home`, `@log` and `@pkg` subvolumes, `compress=zstd`), systemd-boot with loader entries, zram, the minimal profile, the network setup of the ISO, a user `arch` (password `arch`, in `wheel`) and no root password. Then it adds `console=ttyS0` to the loader entries for the serial line the test driver reads, empties the package cache and checks the layout. It boots the result once more under UEFI with no saved boot entries, as the harness does, and fails unless the login prompt appears on the serial line. The compressed qcow2, its `.sha256` and its `.json` manifest (the hash in the SRI form `images.json` takes, the inputs and every installed package) are the `arch-install-image` artifact, and the serial logs and archinstall's log the `arch-install-logs` artifact. The image is rebuilt from the same inputs every night, but not bit for bit: the file system UUIDs, the keyring and the timestamps differ, so every build has a hash of its own. +- **Publish.** On the nightly schedule, which runs on `main`, and on a dispatch from any branch (unless its `publish` input is off), the `publish` job checks the artifact against the hash the build reported and uploads it to `images-arch-install`, creating the release when it is missing. Every build is named `arch-install---.qcow2`, so a nightly never replaces the asset that `images.json` pins; an asset of the same name, from a re-run of the same run, is replaced. It then replaces `arch-install-latest.json` with the new manifest and deletes the builds beyond the newest three that the `images.json` of `main`, of `next` and of the run's commit do not pin. No pull request publishes: a pull request that changes the builder or the workflow runs the build alone. +- **Verify.** The `verify` job downloads the asset from its public URL and fails unless its SHA-256 is the build's and `arch-install-latest.json` names it. Its summary shows the `asset` and `sha256` to pin. +- **Pinning.** `images.json` pins one build by its `asset` and `sha256` (`python3 -m ci.distro_images repin arch-install` takes the newest), so a test fetches exactly that file and Nix checks its hash. Its `firmware` is `uefi`, so `nix/distro-tests/lib/distro-vm.nix` boots it with OVMF. The entry stays disabled until the Arch admission enables it; the probe and refusal suites of `distro-e2e.yml` boot it already. +- **The token.** `NAILS_TEST_IMAGES_TOKEN` is a fine-grained token with Contents read and write on the assets repository alone. Only the upload step of the `publish` job reads it, a job that runs no code of the build and no pull request ever starts. + ### The forensic oracle nightly `oracle-real-nightly.yml` runs the forensic oracle ([ci/oracle/README.md](../ci/oracle/README.md)) every night over real decoy disk images. It is informational and gates no merge. @@ -360,7 +371,7 @@ GitHub settings that the workflows assume but cannot set themselves: - **`next`.** While the integration branch exists, a ruleset of its own targets `next`. It requires the same checks as the ruleset for `main`, each from GitHub Actions, blocks deletion and force pushes, and has no bypass list, so a commit becomes the tip of `next` only once its checks have passed in a pull request. To rebase `next` onto `main`, a maintainer turns the ruleset off for that one push. - **Tag ruleset.** Protect `v*` tags to annotated tags only, and enable immutable releases. - **Environments.** `dependency-updates` holds `DEPENDENCY_UPDATE_TOKEN` and needs no required reviewers. The `hetzner-pr` and `hetzner` environments are no longer used: delete them, with the `hetzner` environment's secrets `HCLOUD_TOKEN`, `HCLOUD_SSH_KEY_ID` and `RUNNER_REGISTRATION`. -- **Secrets.** `CACHIX_AUTH_TOKEN` as an Actions secret (see [Setting up the cache](#setting-up-the-cache)); never add it as a Dependabot secret. +- **Secrets.** `CACHIX_AUTH_TOKEN` as an Actions secret (see [Setting up the cache](#setting-up-the-cache)); never add it as a Dependabot secret. `NAILS_TEST_IMAGES_TOKEN` as an Actions secret: a fine-grained token with Contents read and write on `WitteShadovv/nails-test-images` alone, the assets repository `test-images.yml` publishes to. - **CodeQL.** The `main` branch ruleset requires code scanning results from the tool CodeQL, with the alerts threshold at errors and the security alerts threshold at high or higher; `codeql.yml` provides them. Code scanning refuses the results of `codeql.yml` while CodeQL's default setup is on. Turn the default setup off: Settings, Advanced Security, the menu of the "CodeQL analysis" row, **Switch to advanced**, then **Disable CodeQL** in the pop-up. Commit nothing from the workflow editor that opens next; the workflow is already in the repository. - **Schedules.** GitHub disables a workflow's schedule after 60 days without repository activity; a quiet period needs a manual dispatch of `scheduled.yml` (or any push) to re-arm it. @@ -369,6 +380,7 @@ GitHub settings that the workflows assume but cannot set themselves: - `CACHIX_AUTH_TOKEN` is optional. With it, `e2e.yml`, the `plan`, `distro` and `gating` jobs of `distro-e2e.yml`, the `produce` and `produce-btrfs` jobs of `oracle-real-nightly.yml` and the `nix-build` job of `ci.yml` push build results to the project binary cache for trusted events (see [Nix setup and binary cache](#nix-setup-and-binary-cache)). Store it as an Actions secret only. - `DEPENDENCY_UPDATE_TOKEN` is optional and used only by the Cargo.lock refresh in `scheduled.yml`, so the pull request it opens starts CI. Without it the job prints the diff to the run summary. - No E2E lane needs any other secret. The retired `hetzner-pr` approval environment and the `hetzner` environment with its secrets (`HCLOUD_TOKEN`, `HCLOUD_SSH_KEY_ID`, `RUNNER_REGISTRATION`) are no longer used and can be deleted. +- `NAILS_TEST_IMAGES_TOKEN` is used only by the upload step of the `publish` job of `test-images.yml`, which uploads the test images to the assets repository and prunes its old builds (see [The test images](#the-test-images-test-imagesyml)). It never reaches a pull request run. - `next-nightly.yml` needs no secret: its `dispatch` job starts the runs of `next` with the job's own token, which gets `actions: write` for that. - Release attestations are signed with the `attest` job's OIDC identity (`id-token: write`); no long-lived signing secret exists. - `scorecard.yml` needs no secret either: its Scorecard job signs the result it publishes with its OIDC identity (`id-token: write`) and uploads the SARIF to code scanning with `security-events: write` (see [OpenSSF Scorecard](#openssf-scorecard)). diff --git a/flake.nix b/flake.nix index 8e123362f..ec8fab9c6 100644 --- a/flake.nix +++ b/flake.nix @@ -416,6 +416,9 @@ e2e-metadata = e2eTestMetadata; e2e-distro = distroTests; e2e-distro-metadata = distroMetadata; + # The program that builds the archinstall test image, which the + # test-images workflow runs and publishes (needs KVM and the network). + arch-install-image-builder = import ./nix/distro-tests/arch-install { inherit pkgs; }; }; checks.${system} = import ./nix/checks.nix { diff --git a/nix/distro-tests/arch-install/build.sh b/nix/distro-tests/arch-install/build.sh new file mode 100644 index 000000000..e2f8fd015 --- /dev/null +++ b/nix/distro-tests/arch-install/build.sh @@ -0,0 +1,168 @@ +# shellcheck shell=bash +# Build the archinstall test image (see default.nix, which wraps this script and +# sets ISO, GUEST, INPUTS, OVMF_CODE, OVMF_VARS and OVMF_FD). +# +# build-arch-install-image +# +# It boots the pinned Arch ISO's own kernel in QEMU under UEFI (OVMF) with a +# blank disk, and the ISO's automated-script hook runs install.sh there, which +# installs Arch with archinstall from the pinned package snapshot. Then it +# boots the installed disk once under UEFI as the test harness does and waits +# for its login prompt on the serial line, and writes into : +# +# the image, a compressed qcow2 under 2 GiB +# .sha256 its SHA-256 in sha256sum's format +# .json the manifest: the hash in Nix's SRI form, the size, +# the pinned inputs and the installed packages +# logs/ both serial logs and what install.sh wrote +# +# Needs /dev/kvm. Nothing here reads a secret. +set -euo pipefail + +die() { + echo "build-arch-install-image: $*" >&2 + exit 1 +} + +[ "$#" -eq 2 ] || die "usage: build-arch-install-image " +asset=$2 +case "$asset" in + arch-install-*.qcow2) ;; + *) die "the asset name must be arch-install-.qcow2, not '$asset'" ;; +esac +case "$asset" in + */* | *[[:space:]]*) die "the asset name must be a plain file name" ;; +esac +if ! [ -r /dev/kvm ] || ! [ -w /dev/kvm ]; then + die "/dev/kvm is not usable" +fi + +mkdir -p "$1/logs" +out=$(realpath "$1") +logs=$out/logs +work=$(mktemp -d "${TMPDIR:-/tmp}/arch-install.XXXXXX") +http_pid= +boot_pid= +cleanup() { + [ -z "$http_pid" ] || kill "$http_pid" 2>/dev/null || true + [ -z "$boot_pid" ] || kill "$boot_pid" 2>/dev/null || true + rm -rf "$work" +} +trap cleanup EXIT +export MTOOLS_SKIP_CHECK=1 + +# The live system's kernel and initramfs, booted directly so that the kernel +# command line can carry `script=`. archiso finds its root by the ISO's volume +# UUID, which is the build time of the ISO. +mkdir "$work/iso" +bsdtar -xf "$ISO" -C "$work/iso" arch/boot/x86_64/vmlinuz-linux arch/boot/x86_64/initramfs-linux.img +iso_uuid=$(blkid -o value -s UUID "$ISO") +[ -n "$iso_uuid" ] || die "the ISO has no volume UUID" +live_options="archisobasedir=arch archisosearchuuid=$iso_uuid" + +# What the live system fetches: install.sh and its files, and a mirrorlist +# that names the snapshot alone. +mkdir "$work/serve" +cp "$GUEST"/* "$work/serve/" +printf 'Server = %s\n' "$(jq -er .packages.server "$INPUTS")" >"$work/serve/mirrorlist" +port=$(python3 -c 'import socket; s = socket.socket(); s.bind(("127.0.0.1", 0)); print(s.getsockname()[1])') +python3 -m http.server --bind 127.0.0.1 --directory "$work/serve" "$port" >"$logs/http.log" 2>&1 & +http_pid=$! + +qemu-img create -q -f qcow2 "$work/disk.qcow2" "$(jq -er .disk.size "$INPUTS")" +truncate -s 64M "$work/out.img" +mkfs.vfat -n NAILSOUT "$work/out.img" >/dev/null +install -m 0644 "$OVMF_VARS" "$work/vars.fd" + +# The machine the harness boots (nix-vm-test): the default i440fx machine, the +# root disk on IDE, so that the initramfs archinstall builds for this machine +# holds the drivers the test VMs need. +common=( + -machine "pc,accel=kvm" + -cpu max + -m 4096 + -smp "$(nproc)" + -device virtio-rng-pci + -netdev "user,id=net0" + -device "virtio-net-pci,netdev=net0" + -display none + -monitor none + -no-reboot +) + +echo "Installing from $(basename "$ISO") (live system $iso_uuid)" +timeout 5400 qemu-system-x86_64 "${common[@]}" \ + -drive if=pflash,format=raw,readonly=on,file="$OVMF_CODE" \ + -drive if=pflash,format=raw,file="$work/vars.fd" \ + -kernel "$work/iso/arch/boot/x86_64/vmlinuz-linux" \ + -initrd "$work/iso/arch/boot/x86_64/initramfs-linux.img" \ + -append "$live_options console=tty0 console=ttyS0,115200 script=http://10.0.2.2:$port/install.sh" \ + -drive file="$ISO",media=cdrom,if=ide,readonly=on \ + -drive file="$work/disk.qcow2",format=qcow2,if=ide,discard=unmap \ + -drive file="$work/out.img",format=raw,if=virtio \ + -serial file:"$logs/install-serial.log" || + die "the install VM failed or timed out (see logs/install-serial.log)" + +mcopy -s -n -i "$work/out.img" '::*' "$logs/" || true +status=$(cat "$logs/status" 2>/dev/null || echo "no status written") +[ "$status" = ok ] || { + tail -n 80 "$logs/install-serial.log" >&2 || true + die "the install did not finish: $status" +} + +# One boot of the result under UEFI, the way the harness boots it: OVMF with +# no saved boot entries, so systemd-boot starts from the ESP's fallback path. +echo "Booting the installed image" +qemu-system-x86_64 "${common[@]}" \ + -bios "$OVMF_FD" \ + -drive file="$work/disk.qcow2",format=qcow2,if=ide,snapshot=on \ + -serial file:"$logs/boot-serial.log" & +boot_pid=$! +booted= +for _ in $(seq 300); do + if grep -q 'login:' "$logs/boot-serial.log" 2>/dev/null; then + booted=yes + break + fi + kill -0 "$boot_pid" 2>/dev/null || break + sleep 1 +done +kill "$boot_pid" 2>/dev/null || true +wait "$boot_pid" 2>/dev/null || true +boot_pid= +[ -n "$booted" ] || { + tail -n 80 "$logs/boot-serial.log" >&2 || true + die "the installed image did not reach a login prompt (see logs/boot-serial.log)" +} + +echo "Compressing" +qemu-img convert -c -O qcow2 "$work/disk.qcow2" "$out/$asset" +size=$(stat -c %s "$out/$asset") +limit=$((2 * 1024 * 1024 * 1024)) +[ "$size" -lt "$limit" ] || die "$asset is $size bytes, not under the 2 GiB release-asset limit" + +hex=$(sha256sum "$out/$asset" | cut -d' ' -f1) +printf '%s %s\n' "$hex" "$asset" >"$out/$asset.sha256" +sri=$(python3 -c 'import base64, sys; print("sha256-" + base64.b64encode(bytes.fromhex(sys.argv[1])).decode())' "$hex") +jq -n \ + --arg asset "$asset" \ + --arg sha256 "$sri" \ + --arg sha256Hex "$hex" \ + --argjson size "$size" \ + --arg built "$(date -u +%Y-%m-%dT%H:%M:%SZ)" \ + --arg archinstall "$(cat "$logs/archinstall-version.txt")" \ + --slurpfile inputs "$INPUTS" \ + --rawfile packages "$logs/packages.txt" \ + '{ + asset: $asset, + sha256: $sha256, + sha256Hex: $sha256Hex, + size: $size, + built: $built, + iso: $inputs[0].iso, + packages: $inputs[0].packages, + archinstall: $archinstall, + installed: ($packages | split("\n") | map(select(. != ""))) + }' >"$out/$asset.json" + +echo "Built $asset: $size bytes, sha256 $hex ($sri)" diff --git a/nix/distro-tests/arch-install/default.nix b/nix/distro-tests/arch-install/default.nix new file mode 100644 index 000000000..cfbd02a74 --- /dev/null +++ b/nix/distro-tests/arch-install/default.nix @@ -0,0 +1,55 @@ +# The builder of the archinstall test image (the `arch-install` entry of +# ../images.json), which no upstream publishes. +# +# `nix run .#arch-install-image-builder -- ` boots the +# Arch ISO that inputs.json pins by hash under UEFI, runs archinstall in it +# from the package snapshot inputs.json names, and writes the compressed image, +# its SHA-256 and a manifest (build.sh). It needs KVM and the network, so it is +# a program, not a derivation: the test-images workflow runs it on a hosted +# runner every night and publishes the image to the mirror (../mirrors.nix). +{ pkgs }: +let + inherit (pkgs) lib; + + inputs = lib.importJSON ./inputs.json; + + iso = pkgs.fetchurl { + inherit (inputs.iso) url name; + hash = inputs.iso.sha256; + }; + + # What the live system fetches from the build's HTTP server. + guest = lib.fileset.toSource { + root = ./.; + fileset = lib.fileset.unions [ + ./install.sh + ./disk_layout.py + ./user_configuration.json + ./user_credentials.json + ]; + }; +in +pkgs.writeShellApplication { + name = "build-arch-install-image"; + runtimeInputs = with pkgs; [ + coreutils + dosfstools + gnugrep + jq + libarchive + mtools + python3 + qemu_kvm + util-linux + ]; + runtimeEnv = { + ISO = iso; + GUEST = guest; + INPUTS = ./inputs.json; + OVMF_CODE = "${pkgs.OVMF.fd}/FV/OVMF_CODE.fd"; + OVMF_VARS = "${pkgs.OVMF.fd}/FV/OVMF_VARS.fd"; + OVMF_FD = "${pkgs.OVMF.fd}/FV/OVMF.fd"; + }; + text = builtins.readFile ./build.sh; + passthru = { inherit iso inputs; }; +} diff --git a/nix/distro-tests/arch-install/disk_layout.py b/nix/distro-tests/arch-install/disk_layout.py new file mode 100644 index 000000000..b4de7150d --- /dev/null +++ b/nix/distro-tests/arch-install/disk_layout.py @@ -0,0 +1,79 @@ +"""Print the disk layout archinstall suggests for one disk, as its config JSON. + +Runs inside the Arch live ISO, with the archinstall the ISO ships. It calls +archinstall's own `suggest_single_disk_layout`, the code its menu runs for +"Use a best-effort default partition layout", and gives it the answers a user +gives there for btrfs: the default subvolume structure, and compression. The +two prompts are answered here instead of on a screen; everything else (the +1 GiB ESP at /boot, the btrfs root over the rest of the disk, the @, @home, +@log and @pkg subvolumes, the sizes and alignment) is archinstall's own. + + python3 disk_layout.py /dev/sda > disk_config.json +""" + +import asyncio +import json +import sys +from pathlib import Path + +from archinstall.lib.disk import default_layouts +from archinstall.lib.disk.device_handler import device_handler +from archinstall.lib.models.device import ( + BtrfsMountOption, + DiskLayoutConfiguration, + DiskLayoutType, + FilesystemType, +) +from archinstall.tui.menu_item import MenuItem + + +class _Answered: + """The result of a yes or no prompt that a user answered yes.""" + + def item(self) -> MenuItem: + return MenuItem.yes() + + +class _Yes: + """Stands in for the prompt that asks for the default subvolumes.""" + + def __init__(self, *_args: object, **_kwargs: object) -> None: + pass + + async def show(self) -> _Answered: + return _Answered() + + +async def _compression() -> list[str]: + """The answer "Use compression" to the btrfs mount option prompt.""" + return [BtrfsMountOption.compress.value] + + +def main(device_path: str) -> int: + device = device_handler.get_device(Path(device_path)) + if device is None: + print(f"disk_layout: no block device {device_path}", file=sys.stderr) + return 1 + default_layouts.Confirmation = _Yes + default_layouts.select_mount_options = _compression + modification = asyncio.run( + default_layouts.suggest_single_disk_layout( + device, filesystem_type=FilesystemType.BTRFS + ) + ) + config = DiskLayoutConfiguration( + config_type=DiskLayoutType.Default, + device_modifications=[modification], + ) + layout = config.json() + partitions = layout["device_modifications"][0]["partitions"] + subvolumes = [vol["name"] for part in partitions for vol in part["btrfs"]] + if len(partitions) != 2 or subvolumes != ["@", "@home", "@log", "@pkg"]: + print(f"disk_layout: unexpected suggestion: {layout}", file=sys.stderr) + return 1 + print(json.dumps(layout, indent=2)) + return 0 + + +if __name__ == "__main__": + sys.exit(main(sys.argv[1])) diff --git a/nix/distro-tests/arch-install/inputs.json b/nix/distro-tests/arch-install/inputs.json new file mode 100644 index 000000000..74e288497 --- /dev/null +++ b/nix/distro-tests/arch-install/inputs.json @@ -0,0 +1,15 @@ +{ + "iso": { + "version": "2026.11.01", + "name": "archlinux-2026.11.01-x86_64.iso", + "url": "https://archive.archlinux.org/iso/2026.11.01/archlinux-2026.11.01-x86_64.iso", + "sha256": "sha256-Abzc8Bry99WPJ5SJnINHcNJcm/yUW9CSsyu2ZnKkohY=" + }, + "packages": { + "snapshot": "2026-11-01", + "server": "https://archive.archlinux.org/repos/2026/11/01/$repo/os/$arch" + }, + "disk": { + "size": "16G" + } +} diff --git a/nix/distro-tests/arch-install/install.sh b/nix/distro-tests/arch-install/install.sh new file mode 100644 index 000000000..7101019b7 --- /dev/null +++ b/nix/distro-tests/arch-install/install.sh @@ -0,0 +1,142 @@ +#!/usr/bin/env bash +# The install that runs inside the Arch live ISO (see build.sh). +# +# The ISO's own automated-script hook runs this on tty1: build.sh boots the +# ISO's kernel with `script=`, and the live system fetches +# and runs it once root is logged in there. It installs Arch with archinstall, +# from the package snapshot the mirrorlist names, onto the first IDE disk, and +# writes what it did to the output disk (label NAILSOUT): `status` ("ok" or the +# failure), the logs, the package list and the layout. Then it powers off, +# which ends QEMU and hands control back to build.sh. +set -Eeuo pipefail + +out=/run/nails-out +target=/dev/sda +exec > >(tee /dev/ttyS0) 2>&1 + +finish() { + local status=$1 + if mountpoint -q "$out"; then + cp /var/log/archinstall/install.log "$out/archinstall.log" 2>/dev/null || true + journalctl -b --no-pager >"$out/live-journal.txt" 2>/dev/null || true + printf '%s\n' "$status" >"$out/status" + sync + umount "$out" || true + fi + echo "nails-arch-install: $status" + systemctl poweroff + exit 0 +} +trap 'finish "failed at line $LINENO"' ERR + +# The directory this script was fetched from, which serves the other files. +base= +for param in $("$out/archinstall-version.txt" +python3 "$work/disk_layout.py" "$target" >"$work/disk_config.json" +python3 - "$work" <<'PY' +import json +import sys +from pathlib import Path + +work = Path(sys.argv[1]) +config = json.loads((work / "user_configuration.json").read_text()) +config["disk_config"] = json.loads((work / "disk_config.json").read_text()) +(work / "config.json").write_text(json.dumps(config, indent=2)) +PY +cp "$work/config.json" "$out/config.json" + +# --skip-ntp: the live clock comes from the host's RTC, and an NTP sync over +# QEMU's user network may never finish. --skip-wkd: the keyring is the ISO's, +# from the same day as the snapshot. +archinstall \ + --config "$work/config.json" \ + --creds "$work/user_credentials.json" \ + --silent \ + --skip-ntp \ + --skip-wkd \ + --skip-version-check \ + --skip-wifi-check +grep -q 'Installation completed without any errors' /var/log/archinstall/install.log + +# archinstall leaves the target mounted at /mnt. +mountpoint -q /mnt + +# What the test harness needs beyond archinstall's own result: the kernel +# console on the serial line the test driver reads, as nix-vm-test sets it +# for arch-boxes. +sed -i 's/^options .*/& console=tty0 console=ttyS0/' /mnt/boot/loader/entries/*.conf + +# The image ships without the downloaded packages: every test VM would fetch +# them only to keep them in the cache. +find /mnt/var/cache/pacman/pkg -mindepth 1 -delete + +{ + echo "== findmnt" + findmnt -R /mnt + echo "== btrfs subvolumes" + btrfs subvolume list /mnt + echo "== /etc/fstab" + cat /mnt/etc/fstab + echo "== loader.conf" + cat /mnt/boot/loader/loader.conf + for entry in /mnt/boot/loader/entries/*.conf; do + echo "== $entry" + cat "$entry" + done + echo "== ESP" + find /mnt/boot -maxdepth 3 + echo "== zram" + cat /mnt/etc/systemd/zram-generator.conf + echo "== users" + grep -E '^(root|arch):' /mnt/etc/passwd + grep -E '^wheel:' /mnt/etc/group +} >"$out/layout.txt" +pacman --root /mnt --dbpath /mnt/var/lib/pacman -Q >"$out/packages.txt" + +# The checks that a test needs these to hold, so a change of archinstall's +# defaults fails the build rather than a test later. +test -f /mnt/boot/EFI/BOOT/BOOTX64.EFI +ls /mnt/boot/loader/entries/*.conf +grep -Eq '[[:space:]]/[[:space:]]+btrfs[[:space:]].*subvol=/@([,[:space:]]|$)' /mnt/etc/fstab +grep -Eq '[[:space:]]/home[[:space:]]+btrfs[[:space:]].*subvol=/@home' /mnt/etc/fstab +grep -Eq '[[:space:]]/boot[[:space:]]+vfat[[:space:]]' /mnt/etc/fstab +grep -q '^arch:' /mnt/etc/passwd +test -f /mnt/etc/systemd/zram-generator.conf + +# Free the blocks the package cache held, so the image does not carry them. +fstrim -v /mnt || true +fstrim -v /mnt/boot || true +sync +umount -R /mnt + +finish ok diff --git a/nix/distro-tests/arch-install/user_configuration.json b/nix/distro-tests/arch-install/user_configuration.json new file mode 100644 index 000000000..5d6e55c95 --- /dev/null +++ b/nix/distro-tests/arch-install/user_configuration.json @@ -0,0 +1,31 @@ +{ + "archinstall-language": "English", + "bootloader_config": { + "bootloader": "Systemd-boot", + "uki": false, + "removable": false + }, + "hostname": "archlinux", + "kernels": ["linux"], + "locale_config": { + "kb_layout": "us", + "sys_enc": "UTF-8", + "sys_lang": "en_US" + }, + "network_config": { + "type": "iso" + }, + "ntp": true, + "packages": [], + "profile_config": { + "profile": { + "main": "Minimal" + } + }, + "script": "guided", + "swap": { + "enabled": true, + "algorithm": "zstd" + }, + "timezone": "UTC" +} diff --git a/nix/distro-tests/arch-install/user_credentials.json b/nix/distro-tests/arch-install/user_credentials.json new file mode 100644 index 000000000..b2d2e9a1b --- /dev/null +++ b/nix/distro-tests/arch-install/user_credentials.json @@ -0,0 +1,10 @@ +{ + "users": [ + { + "username": "arch", + "!password": "arch", + "sudo": true, + "groups": [] + } + ] +} diff --git a/nix/distro-tests/probe/README.md b/nix/distro-tests/probe/README.md index 8d1f009d3..abe455807 100644 --- a/nix/distro-tests/probe/README.md +++ b/nix/distro-tests/probe/README.md @@ -31,7 +31,8 @@ image, with `-enforcing` added for a Fedora image booted with SELinux enforcing. - `fedora-45.json`, `fedora-45-enforcing.json` -- the pinned Fedora 45 cloud image, booted permissive and enforcing as for Fedora 44 (recorded) - `arch-boxes.json` -- the pinned Arch `arch-boxes` image (recorded) -- `arch-install.json` -- the `archinstall`-built Arch image, once hosted +- `arch-install.json` -- the `archinstall`-built Arch image, which + `.github/workflows/test-images.yml` builds and publishes Debian and Ubuntu need no probe: they are admitted and covered by the smoke suite directly. From e130e15d8b694e6cdd98f0cf83b57c98a685a492 Mon Sep 17 00:00:00 2001 From: WitteShadovv Date: Wed, 25 Nov 2026 09:54:39 +0100 Subject: [PATCH 03/13] ci(test-images): build on pushes that change the image builder GitHub dispatches a workflow that is not on the default branch only once it has run there, and a dispatch from the branch is how its first image gets published. A push to any branch but main and next that changes the builder or the workflow now runs the build alone, which also lets the branch be dispatched. It publishes nothing, as a pull request does not. --- .github/workflows/test-images.yml | 22 ++++++++++++++++------ docs/ci.md | 4 ++-- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/.github/workflows/test-images.yml b/.github/workflows/test-images.yml index 24ed2fe81..8e363654e 100644 --- a/.github/workflows/test-images.yml +++ b/.github/workflows/test-images.yml @@ -27,6 +27,11 @@ name: Test images # nightly schedule build, publish and verify (runs on main only) # dispatch the same on any branch, unless `publish` is off # pull request build only, when the builder or this file changes +# push to a branch build only, under the same path filter, on any branch +# but main and next. GitHub dispatches a workflow that +# is not on the default branch only once it has run, so +# this run is also what lets a branch with a new or +# changed copy of this file be dispatched. # # The upload token, NAILS_TEST_IMAGES_TOKEN, is a fine-grained token with # Contents read and write on the assets repository alone. Only the upload step @@ -42,6 +47,11 @@ on: paths: - nix/distro-tests/arch-install/** - .github/workflows/test-images.yml + push: + branches-ignore: [main, next] + paths: + - nix/distro-tests/arch-install/** + - .github/workflows/test-images.yml workflow_dispatch: inputs: publish: @@ -53,11 +63,11 @@ permissions: contents: read concurrency: - # A new push to a pull request cancels its build in progress; a scheduled or - # dispatched run waits for the one before it, so two uploads never prune - # each other's assets. - group: test-images-${{ github.event_name == 'pull_request' && format('pr-{0}', github.event.pull_request.number) || 'publish' }} - cancel-in-progress: ${{ github.event_name == 'pull_request' }} + # A new push to a pull request or a branch cancels its build in progress; a + # scheduled or dispatched run waits for the one before it, so two uploads + # never prune each other's assets. + group: test-images-${{ github.event_name == 'pull_request' && format('pr-{0}', github.event.pull_request.number) || github.event_name == 'push' && format('push-{0}', github.ref) || 'publish' }} + cancel-in-progress: ${{ github.event_name == 'pull_request' || github.event_name == 'push' }} defaults: run: @@ -160,7 +170,7 @@ jobs: needs: build # Only a run of this repository's own branches publishes: the nightly # schedule, which runs on main, and a dispatch, from any branch. Never a - # pull request. + # pull request or a push. if: >- github.repository == 'WitteShadovv/nails' && startsWith(github.ref, 'refs/heads/') diff --git a/docs/ci.md b/docs/ci.md index 764c828f0..27b2bfd64 100644 --- a/docs/ci.md +++ b/docs/ci.md @@ -23,7 +23,7 @@ Tier 3 is everything a contributor must pass to merge. The informational `fuzz` | `.github/workflows/pr-title.yml` | Pull request opened, edited, synchronized, reopened | `pr-title` | 3 | `ubuntu-26.04` | the commit-msg hook | | `.github/workflows/e2e.yml` | PRs to `main` and `next`, push to either, nightly, dispatch, `workflow_call` | `e2e-result` | 3 (affected) and 4 (nightly full) | `runner` input, default `ubuntu-26.04` | `just e2e` | | `.github/workflows/distro-e2e.yml` | Nightly, PRs to `main` and `next` (the records and refusal jobs when the change touches what they are built from, the smoke scenarios too with the `distro-e2e` label), dispatch, `workflow_call` | — (`distro-result` fails on a records or refusal job; the smoke scenarios, the probes and the staged suite are informational) | 3 (records and refusal on pull requests, outside its budget) and 4 | `runner` input, default `ubuntu-26.04` (KVM) | `nix build .#legacyPackages.x86_64-linux.e2e-distro.`; a records scenario, a refusal, a probe or a staged driver runs its driver ([details](../nix/e2e-tests/README.md#running-and-ci), [probes](../nix/distro-tests/probe/README.md#regenerating)) | -| `.github/workflows/test-images.yml` | Nightly, dispatch, PRs to `main` and `next` that change the image builder (build only) | — | 4 | `ubuntu-26.04` (KVM) | `nix run .#arch-install-image-builder -- ` ([details](#the-test-images-test-imagesyml)) | +| `.github/workflows/test-images.yml` | Nightly, dispatch, PRs to `main` and `next` and pushes to other branches that change the image builder (build only) | — | 4 | `ubuntu-26.04` (KVM) | `nix run .#arch-install-image-builder -- ` ([details](#the-test-images-test-imagesyml)) | | `.github/workflows/next-nightly.yml` | Nightly, dispatch: starts the nightly `e2e.yml` and `distro-e2e.yml` runs of `next` | — | 4 | `ubuntu-26.04` | — | | `.github/workflows/oracle-real-nightly.yml` | Nightly, dispatch | — (informational) | 4 | produce and produce-btrfs on `ubuntu-26.04` (KVM), scan, scan-btrfs, scan-btrfs-real and btrfs-wtmp-extents on `ubuntu-24.04` | `nix build .#legacyPackages.x86_64-linux.e2e.oracle-images.driver`, its `bin/nixos-test-driver -o `, then `sudo env ORACLE_IMAGES_DIR=/forensics ci/oracle/run-scan.sh `; for the btrfs disks, the `e2e-distro."-oracle-images"` driver's `bin/test-driver` with `NAILS_ORACLE_OUT=` ([details](#the-forensic-oracle-nightly)) | | `.github/workflows/scheduled.yml` | Weekly, twice-weekly and monthly schedules, dispatch with a `task` input | — | 4 | `ubuntu-26.04` | `just deny-full`, `just stress`, `cargo bench`, `just mutants`, `just kani` | @@ -167,7 +167,7 @@ There used to be a second, per-PR container lane (`distro-smoke` in `ci.yml`). I The archinstall image (the `arch-install` entry of `nix/distro-tests/images.json`) has no upstream that publishes it, so `test-images.yml` builds it every night from pinned inputs and publishes it as a release asset of the public assets repository `WitteShadovv/nails-test-images`, the `base` of `nix/distro-tests/mirrors.nix`. Each family has one release, `images-` (`tagFor`), and every asset stays under GitHub's 2 GiB limit, so none is split. - **Build.** The `build` job runs `nix run .#arch-install-image-builder` (`nix/distro-tests/arch-install/`) on a hosted `ubuntu-26.04` runner for KVM. It boots the kernel of the Arch ISO that `inputs.json` pins by hash under UEFI (OVMF), with a blank 16 GiB disk on IDE, the bus the test harness boots it from. The ISO's own automated-script hook runs `install.sh`, which points the mirrorlist at the dated Arch Linux Archive snapshot of the same day and runs the ISO's archinstall unattended: archinstall's own default layout for one btrfs disk (a 1 GiB ESP at `/boot`, the `@`, `@home`, `@log` and `@pkg` subvolumes, `compress=zstd`), systemd-boot with loader entries, zram, the minimal profile, the network setup of the ISO, a user `arch` (password `arch`, in `wheel`) and no root password. Then it adds `console=ttyS0` to the loader entries for the serial line the test driver reads, empties the package cache and checks the layout. It boots the result once more under UEFI with no saved boot entries, as the harness does, and fails unless the login prompt appears on the serial line. The compressed qcow2, its `.sha256` and its `.json` manifest (the hash in the SRI form `images.json` takes, the inputs and every installed package) are the `arch-install-image` artifact, and the serial logs and archinstall's log the `arch-install-logs` artifact. The image is rebuilt from the same inputs every night, but not bit for bit: the file system UUIDs, the keyring and the timestamps differ, so every build has a hash of its own. -- **Publish.** On the nightly schedule, which runs on `main`, and on a dispatch from any branch (unless its `publish` input is off), the `publish` job checks the artifact against the hash the build reported and uploads it to `images-arch-install`, creating the release when it is missing. Every build is named `arch-install---.qcow2`, so a nightly never replaces the asset that `images.json` pins; an asset of the same name, from a re-run of the same run, is replaced. It then replaces `arch-install-latest.json` with the new manifest and deletes the builds beyond the newest three that the `images.json` of `main`, of `next` and of the run's commit do not pin. No pull request publishes: a pull request that changes the builder or the workflow runs the build alone. +- **Publish.** On the nightly schedule, which runs on `main`, and on a dispatch from any branch (unless its `publish` input is off), the `publish` job checks the artifact against the hash the build reported and uploads it to `images-arch-install`, creating the release when it is missing. Every build is named `arch-install---.qcow2`, so a nightly never replaces the asset that `images.json` pins; an asset of the same name, from a re-run of the same run, is replaced. It then replaces `arch-install-latest.json` with the new manifest and deletes the builds beyond the newest three that the `images.json` of `main`, of `next` and of the run's commit do not pin. No pull request or push publishes: a pull request into `main` or `next`, or a push to any other branch, that changes the builder or the workflow runs the build alone. That push run is also what lets the branch be dispatched: GitHub dispatches a workflow file that is not on the default branch only after it has run once. - **Verify.** The `verify` job downloads the asset from its public URL and fails unless its SHA-256 is the build's and `arch-install-latest.json` names it. Its summary shows the `asset` and `sha256` to pin. - **Pinning.** `images.json` pins one build by its `asset` and `sha256` (`python3 -m ci.distro_images repin arch-install` takes the newest), so a test fetches exactly that file and Nix checks its hash. Its `firmware` is `uefi`, so `nix/distro-tests/lib/distro-vm.nix` boots it with OVMF. The entry stays disabled until the Arch admission enables it; the probe and refusal suites of `distro-e2e.yml` boot it already. - **The token.** `NAILS_TEST_IMAGES_TOKEN` is a fine-grained token with Contents read and write on the assets repository alone. Only the upload step of the `publish` job reads it, a job that runs no code of the build and no pull request ever starts. From 3a984e80b0966a68c5b9d748339a17cc6de7386f Mon Sep 17 00:00:00 2001 From: WitteShadovv Date: Wed, 25 Nov 2026 11:54:42 +0100 Subject: [PATCH 04/13] fix(test-images): attach the ISO as a virtio-scsi CD and stop a stuck live boot The first dispatch timed out after 90 minutes: the live initramfs found no IDE CD drive, waited for the ISO's UUID and dropped to its rescue shell, which never powers off. The ISO now goes on a virtio-scsi CD drive, as archiso's own run_archiso attaches it, and build.sh watches the serial log: it stops the VM at once when the initramfs gives up or the kernel panics, and after 90 minutes in any case. --- nix/distro-tests/arch-install/build.sh | 35 +++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 4 deletions(-) diff --git a/nix/distro-tests/arch-install/build.sh b/nix/distro-tests/arch-install/build.sh index e2f8fd015..45eb52b69 100644 --- a/nix/distro-tests/arch-install/build.sh +++ b/nix/distro-tests/arch-install/build.sh @@ -43,8 +43,10 @@ logs=$out/logs work=$(mktemp -d "${TMPDIR:-/tmp}/arch-install.XXXXXX") http_pid= boot_pid= +install_pid= cleanup() { [ -z "$http_pid" ] || kill "$http_pid" 2>/dev/null || true + [ -z "$install_pid" ] || kill "$install_pid" 2>/dev/null || true [ -z "$boot_pid" ] || kill "$boot_pid" 2>/dev/null || true rm -rf "$work" } @@ -91,17 +93,42 @@ common=( ) echo "Installing from $(basename "$ISO") (live system $iso_uuid)" -timeout 5400 qemu-system-x86_64 "${common[@]}" \ +# The ISO goes on a virtio-scsi CD drive, as archiso's own run_archiso attaches +# it: the live initramfs finds no IDE CD drive. +qemu-system-x86_64 "${common[@]}" \ -drive if=pflash,format=raw,readonly=on,file="$OVMF_CODE" \ -drive if=pflash,format=raw,file="$work/vars.fd" \ -kernel "$work/iso/arch/boot/x86_64/vmlinuz-linux" \ -initrd "$work/iso/arch/boot/x86_64/initramfs-linux.img" \ -append "$live_options console=tty0 console=ttyS0,115200 script=http://10.0.2.2:$port/install.sh" \ - -drive file="$ISO",media=cdrom,if=ide,readonly=on \ + -device virtio-scsi-pci,id=scsi0 \ + -device scsi-cd,bus=scsi0.0,drive=cdrom0 \ + -drive id=cdrom0,if=none,format=raw,media=cdrom,readonly=on,file="$ISO" \ -drive file="$work/disk.qcow2",format=qcow2,if=ide,discard=unmap \ -drive file="$work/out.img",format=raw,if=virtio \ - -serial file:"$logs/install-serial.log" || - die "the install VM failed or timed out (see logs/install-serial.log)" + -serial file:"$logs/install-serial.log" & +install_pid=$! + +# Watch the install: stop at once when the live system cannot start (the +# initramfs drops to its rescue shell, or the kernel panics), and after 90 +# minutes in any case, rather than wait out the job's timeout. +for _ in $(seq 5400); do + kill -0 "$install_pid" 2>/dev/null || break + if grep -q -e 'ERROR: Device' -e 'Kernel panic' -e "can't access tty" "$logs/install-serial.log" 2>/dev/null; then + kill "$install_pid" 2>/dev/null || true + wait "$install_pid" 2>/dev/null || true + tail -n 40 "$logs/install-serial.log" >&2 || true + die "the live system did not start (see logs/install-serial.log)" + fi + sleep 1 +done +if kill -0 "$install_pid" 2>/dev/null; then + kill "$install_pid" 2>/dev/null || true + wait "$install_pid" 2>/dev/null || true + tail -n 80 "$logs/install-serial.log" >&2 || true + die "the install VM did not finish within 90 minutes (see logs/install-serial.log)" +fi +wait "$install_pid" || die "the install VM failed (see logs/install-serial.log)" mcopy -s -n -i "$work/out.img" '::*' "$logs/" || true status=$(cat "$logs/status" 2>/dev/null || echo "no status written") From 72a8b6a8cb34de814110d89643e5bdf21753ebcf Mon Sep 17 00:00:00 2001 From: WitteShadovv Date: Wed, 25 Nov 2026 12:03:52 +0100 Subject: [PATCH 05/13] fix(test-images): build and boot the archinstall image on q35 Under OVMF on QEMU's default i440fx machine, Linux finds no drive on the PIIX IDE controller: ata_piix loads and its two ports stay empty, so the live system saw no target disk and a test VM would see no root disk. The build now runs on q35, where an IDE drive lands on the AHCI controller, and distro-vm.nix adds -machine q35 beside OVMF for a UEFI entry, which puts nix-vm-test's root drive on the same controller. The initramfs archinstall builds therefore holds the driver the test VMs need. --- docs/ci.md | 4 ++-- nix/distro-tests/arch-install/build.sh | 12 +++++++----- nix/distro-tests/arch-install/install.sh | 2 +- nix/distro-tests/lib/distro-vm.nix | 20 ++++++++++++++------ 4 files changed, 24 insertions(+), 14 deletions(-) diff --git a/docs/ci.md b/docs/ci.md index 27b2bfd64..e3dc73efe 100644 --- a/docs/ci.md +++ b/docs/ci.md @@ -166,10 +166,10 @@ There used to be a second, per-PR container lane (`distro-smoke` in `ci.yml`). I The archinstall image (the `arch-install` entry of `nix/distro-tests/images.json`) has no upstream that publishes it, so `test-images.yml` builds it every night from pinned inputs and publishes it as a release asset of the public assets repository `WitteShadovv/nails-test-images`, the `base` of `nix/distro-tests/mirrors.nix`. Each family has one release, `images-` (`tagFor`), and every asset stays under GitHub's 2 GiB limit, so none is split. -- **Build.** The `build` job runs `nix run .#arch-install-image-builder` (`nix/distro-tests/arch-install/`) on a hosted `ubuntu-26.04` runner for KVM. It boots the kernel of the Arch ISO that `inputs.json` pins by hash under UEFI (OVMF), with a blank 16 GiB disk on IDE, the bus the test harness boots it from. The ISO's own automated-script hook runs `install.sh`, which points the mirrorlist at the dated Arch Linux Archive snapshot of the same day and runs the ISO's archinstall unattended: archinstall's own default layout for one btrfs disk (a 1 GiB ESP at `/boot`, the `@`, `@home`, `@log` and `@pkg` subvolumes, `compress=zstd`), systemd-boot with loader entries, zram, the minimal profile, the network setup of the ISO, a user `arch` (password `arch`, in `wheel`) and no root password. Then it adds `console=ttyS0` to the loader entries for the serial line the test driver reads, empties the package cache and checks the layout. It boots the result once more under UEFI with no saved boot entries, as the harness does, and fails unless the login prompt appears on the serial line. The compressed qcow2, its `.sha256` and its `.json` manifest (the hash in the SRI form `images.json` takes, the inputs and every installed package) are the `arch-install-image` artifact, and the serial logs and archinstall's log the `arch-install-logs` artifact. The image is rebuilt from the same inputs every night, but not bit for bit: the file system UUIDs, the keyring and the timestamps differ, so every build has a hash of its own. +- **Build.** The `build` job runs `nix run .#arch-install-image-builder` (`nix/distro-tests/arch-install/`) on a hosted `ubuntu-26.04` runner for KVM. It boots the kernel of the Arch ISO that `inputs.json` pins by hash under UEFI (OVMF), on the q35 machine with a blank 16 GiB SATA disk, as the test harness boots it, and the ISO on a virtio-scsi CD drive. The ISO's own automated-script hook runs `install.sh`, which points the mirrorlist at the dated Arch Linux Archive snapshot of the same day and runs the ISO's archinstall unattended: archinstall's own default layout for one btrfs disk (a 1 GiB ESP at `/boot`, the `@`, `@home`, `@log` and `@pkg` subvolumes, `compress=zstd`), systemd-boot with loader entries, zram, the minimal profile, the network setup of the ISO, a user `arch` (password `arch`, in `wheel`) and no root password. Then it adds `console=ttyS0` to the loader entries for the serial line the test driver reads, empties the package cache and checks the layout. It boots the result once more under UEFI with no saved boot entries, as the harness does, and fails unless the login prompt appears on the serial line. The compressed qcow2, its `.sha256` and its `.json` manifest (the hash in the SRI form `images.json` takes, the inputs and every installed package) are the `arch-install-image` artifact, and the serial logs and archinstall's log the `arch-install-logs` artifact. The image is rebuilt from the same inputs every night, but not bit for bit: the file system UUIDs, the keyring and the timestamps differ, so every build has a hash of its own. - **Publish.** On the nightly schedule, which runs on `main`, and on a dispatch from any branch (unless its `publish` input is off), the `publish` job checks the artifact against the hash the build reported and uploads it to `images-arch-install`, creating the release when it is missing. Every build is named `arch-install---.qcow2`, so a nightly never replaces the asset that `images.json` pins; an asset of the same name, from a re-run of the same run, is replaced. It then replaces `arch-install-latest.json` with the new manifest and deletes the builds beyond the newest three that the `images.json` of `main`, of `next` and of the run's commit do not pin. No pull request or push publishes: a pull request into `main` or `next`, or a push to any other branch, that changes the builder or the workflow runs the build alone. That push run is also what lets the branch be dispatched: GitHub dispatches a workflow file that is not on the default branch only after it has run once. - **Verify.** The `verify` job downloads the asset from its public URL and fails unless its SHA-256 is the build's and `arch-install-latest.json` names it. Its summary shows the `asset` and `sha256` to pin. -- **Pinning.** `images.json` pins one build by its `asset` and `sha256` (`python3 -m ci.distro_images repin arch-install` takes the newest), so a test fetches exactly that file and Nix checks its hash. Its `firmware` is `uefi`, so `nix/distro-tests/lib/distro-vm.nix` boots it with OVMF. The entry stays disabled until the Arch admission enables it; the probe and refusal suites of `distro-e2e.yml` boot it already. +- **Pinning.** `images.json` pins one build by its `asset` and `sha256` (`python3 -m ci.distro_images repin arch-install` takes the newest), so a test fetches exactly that file and Nix checks its hash. Its `firmware` is `uefi`, so `nix/distro-tests/lib/distro-vm.nix` boots it with OVMF on the q35 machine: under OVMF on QEMU's default i440fx machine, Linux finds no drive on the IDE controller. The entry stays disabled until the Arch admission enables it; the probe and refusal suites of `distro-e2e.yml` boot it already. - **The token.** `NAILS_TEST_IMAGES_TOKEN` is a fine-grained token with Contents read and write on the assets repository alone. Only the upload step of the `publish` job reads it, a job that runs no code of the build and no pull request ever starts. ### The forensic oracle nightly diff --git a/nix/distro-tests/arch-install/build.sh b/nix/distro-tests/arch-install/build.sh index 45eb52b69..1211db9a5 100644 --- a/nix/distro-tests/arch-install/build.sh +++ b/nix/distro-tests/arch-install/build.sh @@ -76,11 +76,13 @@ truncate -s 64M "$work/out.img" mkfs.vfat -n NAILSOUT "$work/out.img" >/dev/null install -m 0644 "$OVMF_VARS" "$work/vars.fd" -# The machine the harness boots (nix-vm-test): the default i440fx machine, the -# root disk on IDE, so that the initramfs archinstall builds for this machine -# holds the drivers the test VMs need. +# The machine the harness boots (nix-vm-test with the QEMU_OPTS that +# lib/distro-vm.nix adds for a UEFI image): q35, whose default drive is a SATA +# disk on its AHCI controller, so that the initramfs archinstall builds for +# this machine holds the drivers the test VMs need. On the older i440fx +# machine under OVMF, Linux sees no drive on the PIIX IDE controller at all. common=( - -machine "pc,accel=kvm" + -machine "q35,accel=kvm" -cpu max -m 4096 -smp "$(nproc)" @@ -94,7 +96,7 @@ common=( echo "Installing from $(basename "$ISO") (live system $iso_uuid)" # The ISO goes on a virtio-scsi CD drive, as archiso's own run_archiso attaches -# it: the live initramfs finds no IDE CD drive. +# it. qemu-system-x86_64 "${common[@]}" \ -drive if=pflash,format=raw,readonly=on,file="$OVMF_CODE" \ -drive if=pflash,format=raw,file="$work/vars.fd" \ diff --git a/nix/distro-tests/arch-install/install.sh b/nix/distro-tests/arch-install/install.sh index 7101019b7..9c10b7f2b 100644 --- a/nix/distro-tests/arch-install/install.sh +++ b/nix/distro-tests/arch-install/install.sh @@ -4,7 +4,7 @@ # The ISO's own automated-script hook runs this on tty1: build.sh boots the # ISO's kernel with `script=`, and the live system fetches # and runs it once root is logged in there. It installs Arch with archinstall, -# from the package snapshot the mirrorlist names, onto the first IDE disk, and +# from the package snapshot the mirrorlist names, onto the first SATA disk, and # writes what it did to the output disk (label NAILSOUT): `status` ("ok" or the # failure), the logs, the package list and the layout. Then it powers off, # which ends QEMU and hands control back to build.sh. diff --git a/nix/distro-tests/lib/distro-vm.nix b/nix/distro-tests/lib/distro-vm.nix index fe3034ada..33f97736a 100644 --- a/nix/distro-tests/lib/distro-vm.nix +++ b/nix/distro-tests/lib/distro-vm.nix @@ -144,13 +144,21 @@ let throw "distro image ${entry.osId} ${entry.release}: no prepare function for '${entry.prepare}'"; # The QEMU options an entry's firmware needs, or null for QEMU's default - # SeaBIOS. nix-vm-test starts QEMU with no firmware option and appends - # $QEMU_OPTS to its command line, so an image whose only boot loader is a - # UEFI one (the archinstall image's systemd-boot) gets OVMF through it. The - # combined OVMF image keeps no boot entries from one boot to the next, so the - # firmware starts the ESP's fallback loader, EFI/BOOT/BOOTX64.EFI, every time. + # SeaBIOS. nix-vm-test starts QEMU with no firmware or machine option and + # appends $QEMU_OPTS to its command line, so an image whose only boot loader + # is a UEFI one (the archinstall image's systemd-boot) gets OVMF through it. + # The combined OVMF image keeps no boot entries from one boot to the next, so + # the firmware starts the ESP's fallback loader, EFI/BOOT/BOOTX64.EFI, every + # time. The machine is q35, where nix-vm-test's root drive is a SATA disk: + # under OVMF on the default i440fx machine, Linux finds no drive on its IDE + # controller. The archinstall image is built on the same machine + # (arch-install/build.sh), so its initramfs holds the AHCI driver. firmwareOpts = - entry: if (entry.firmware or "bios") == "uefi" then "-bios ${vmPkgs.OVMF.fd}/FV/OVMF.fd" else null; + entry: + if (entry.firmware or "bios") == "uefi" then + "-machine q35 -bios ${vmPkgs.OVMF.fd}/FV/OVMF.fd" + else + null; # Hand a built test its firmware: the sandboxed derivation gets QEMU_OPTS in # its build environment, and a host driver a wrapper that sets it (before From d1dde892f98c3fb64b2af88f1f36d96183db0577 Mon Sep 17 00:00:00 2001 From: WitteShadovv Date: Wed, 25 Nov 2026 12:24:21 +0100 Subject: [PATCH 06/13] fix(test-images): ride out a stalling archive and retry a failed install The second dispatch got as far as pacstrap, where the Arch Linux Archive stalled on one package: pacman gave up on it after ten seconds below a byte a second, skipped the server after a few such errors and failed the transaction. The live pacman.conf, which pacstrap uses, now sets DisableDownloadTimeout and three parallel downloads, and a failed archinstall run is tried again from a wiped disk, up to three times, with each failed run's log kept. --- nix/distro-tests/arch-install/install.sh | 41 ++++++++++++++++++------ 1 file changed, 32 insertions(+), 9 deletions(-) diff --git a/nix/distro-tests/arch-install/install.sh b/nix/distro-tests/arch-install/install.sh index 9c10b7f2b..18e674469 100644 --- a/nix/distro-tests/arch-install/install.sh +++ b/nix/distro-tests/arch-install/install.sh @@ -54,6 +54,16 @@ timeout 900 systemctl is-system-running --wait || true systemctl stop reflector.service reflector.timer || true curl -fsS --retry 5 "$base/mirrorlist" -o /etc/pacman.d/mirrorlist cat /etc/pacman.d/mirrorlist +# The archive is one server that stalls under load: pacman's default gives up +# on a download that moves less than a byte a second for ten seconds, and +# after a few such errors skips the server for the rest of the transaction. +# pacstrap runs with this pacman.conf, so turn that timeout off and download +# fewer files at once. +sed -i \ + -e 's/^#\?ParallelDownloads.*/ParallelDownloads = 3/' \ + -e '/^\[options\]/a DisableDownloadTimeout' \ + /etc/pacman.conf +grep -E '^(ParallelDownloads|DisableDownloadTimeout)' /etc/pacman.conf work=/root/nails-install mkdir -p "$work" @@ -78,15 +88,28 @@ cp "$work/config.json" "$out/config.json" # --skip-ntp: the live clock comes from the host's RTC, and an NTP sync over # QEMU's user network may never finish. --skip-wkd: the keyring is the ISO's, # from the same day as the snapshot. -archinstall \ - --config "$work/config.json" \ - --creds "$work/user_credentials.json" \ - --silent \ - --skip-ntp \ - --skip-wkd \ - --skip-version-check \ - --skip-wifi-check -grep -q 'Installation completed without any errors' /var/log/archinstall/install.log +# A failed download still fails pacstrap, so a failed run is tried again from +# a wiped disk, up to three times; each run's log is kept. +installed= +for attempt in 1 2 3; do + rm -f /var/log/archinstall/install.log + if archinstall \ + --config "$work/config.json" \ + --creds "$work/user_credentials.json" \ + --silent \ + --skip-ntp \ + --skip-wkd \ + --skip-version-check \ + --skip-wifi-check && + grep -q 'Installation completed without any errors' /var/log/archinstall/install.log; then + installed=yes + break + fi + echo "nails-arch-install: archinstall run $attempt failed" + cp /var/log/archinstall/install.log "$out/archinstall-attempt-$attempt.log" 2>/dev/null || true + umount -R /mnt 2>/dev/null || true +done +[ -n "$installed" ] # archinstall leaves the target mounted at /mnt. mountpoint -q /mnt From 0fabbe9a51af8175b054e17a6855f7db6d3314a4 Mon Sep 17 00:00:00 2001 From: WitteShadovv Date: Wed, 25 Nov 2026 12:42:55 +0100 Subject: [PATCH 07/13] ci(distro): probe the archinstall builder's ISO and snapshot weekly The nightly rebuild of the archinstall image needs the ISO and the package snapshot that its inputs.json pins, both on archive.archlinux.org. The weekly link check now probes them beside the published asset of a mirror entry whose family has a builder: the ISO and the snapshot's core.db, the first file pacman fetches from it. --- ci/distro_images.py | 55 +++++++++++++++++- ci/tests/test_distro_images.py | 100 ++++++++++++++++++++++++++++++++- docs/ci.md | 2 +- 3 files changed, 150 insertions(+), 7 deletions(-) diff --git a/ci/distro_images.py b/ci/distro_images.py index 4dc9f53a5..13bf138fc 100644 --- a/ci/distro_images.py +++ b/ci/distro_images.py @@ -49,6 +49,12 @@ TABLE_PATH = REPO / "nix" / "distro-tests" / "images.json" LOCK_PATH = REPO / "flake.lock" MIRRORS_PATH = REPO / "nix" / "distro-tests" / "mirrors.nix" +# The pinned inputs of each image the project builds itself, by mirror family: +# the test-images workflow rebuilds it from them every night, so the link +# check probes them as well as the published asset. +BUILDER_INPUTS = { + "arch-install": REPO / "nix" / "distro-tests" / "arch-install" / "inputs.json", +} # The placeholder hash an entry carries until it is pinned for real. It is the # well-known Nix "fake" SHA256, so an enabled entry that still has it is caught @@ -435,6 +441,7 @@ def link_check( url_ok: Callable[[str], bool] = _url_ok, pin_url: Callable[[Mapping], str] | None = None, mirror: Mirror | None = None, + builder_inputs: Mapping[str, Path] | None = None, ) -> LinkReport: """Check the pin of every entry, the staged ones as well as the enabled. @@ -447,8 +454,14 @@ def link_check( smoke matrix until a change enables it, and the probes boot the Fedora and Arch ones before then; its pin lapses all the same, so it is checked like an enabled one. A mirror entry is probed at the asset it pins in the - assets repository (``mirror``, by default read from mirrors.nix); one that - pins no asset yet, or a mirror with no base, is listed as not checked. A + assets repository (``mirror``, by default read from mirrors.nix). The + inputs its builder pins (``builder_inputs``, by default + ``BUILDER_INPUTS``) are probed too, the installer ISO and the package + snapshot, since the nightly rebuild fails once either is gone; that + happens before its first asset is pinned as well. An entry that pins no + asset yet, or a mirror with no base, names that in its line: among the + checked entries when its build inputs were probed, and among the + unchecked ones otherwise. A run that could check no enabled entry fails as well: a pass would claim a check of the images CI boots that never happened, whatever it found for the staged ones. @@ -457,6 +470,7 @@ def link_check( resolve = pin_url or _locked_nix_vm_test_url() report = LinkReport() no_probe: dict[str, str] = {} + inputs = BUILDER_INPUTS if builder_inputs is None else builder_inputs checked_enabled = False for name, entry in table.items(): enabled = bool(entry.get("enabled")) @@ -497,6 +511,24 @@ def link_check( url, why = _mirror_url(source, mirror) if url is None: no_probe[name] = why + family = str(source.get("family")) + if family in inputs: + try: + build_urls = builder_urls(inputs[family]) + except LinkError as error: + done.append("its build inputs unreadable") + report.failures.append(f"{label}: {error}") + else: + for build_url in build_urls: + done.append(f"probed {build_url}") + if not url_ok(build_url): + report.failures.append( + f"{label}: build input is unreachable: {build_url}" + ) + # The entry counts as checked by its build inputs; its + # line still says why its asset was not probed. + if name in no_probe: + done.append(no_probe.pop(name)) if url is not None: done.append(f"probed {url}") if not url_ok(url): @@ -518,13 +550,30 @@ def link_check( return report +def builder_urls(path: Path) -> list[str]: + """The URLs a builder's inputs.json pins: its ISO and its package snapshot. + + The snapshot is probed at its core repository database, the first file + pacman fetches from it. + """ + try: + inputs = json.loads(path.read_text(encoding="utf-8")) + iso, server = inputs["iso"]["url"], inputs["packages"]["server"] + except (OSError, ValueError, KeyError, TypeError) as error: + raise LinkError(f"cannot read {path.name}: {error}") from None + if not isinstance(iso, str) or not isinstance(server, str): + raise LinkError(f"{path.name} names no ISO URL and package server") + core = server.replace("$repo", "core").replace("$arch", "x86_64") + return [iso, f"{core}/core.db"] + + def _mirror_url(source: Mapping, mirror: Mirror) -> tuple[str | None, str]: """The URL a mirror source pins, or None and why there is none to probe.""" if not mirror.configured(): return None, "the mirror is not configured yet" asset = source.get("asset") if asset is None: - return None, "a mirror source that pins no asset yet" + return None, "no asset pinned yet" return mirror.url_for(str(source.get("family")), str(asset)), "" diff --git a/ci/tests/test_distro_images.py b/ci/tests/test_distro_images.py index 68235fa7f..9f0d0f89e 100644 --- a/ci/tests/test_distro_images.py +++ b/ci/tests/test_distro_images.py @@ -361,7 +361,16 @@ def url_ok(url: str) -> bool: if entry["source"]["kind"] in ("upstream", "nix-vm-test") or entry["source"].get("asset") is not None ] - self.assertEqual(len(probed), len(pinned)) + # A mirror entry probes its builder's inputs whether or not it pins + # an asset yet. + build_inputs = [ + name + for name, entry in table.items() + if entry["source"]["kind"] == "mirror" + and entry["source"].get("family") in di.BUILDER_INPUTS + ] + # Each of those also probes its builder's ISO and package snapshot. + self.assertEqual(len(probed), len(pinned) + 2 * len(build_inputs)) staged = [name for name in pinned if not table[name]["enabled"]] self.assertTrue(staged, "no staged pin to probe") @@ -599,13 +608,94 @@ def url_ok(url: str) -> bool: return True report = di.link_check( - self.mirror_table(), today=THE_DAY, url_ok=url_ok, mirror=MIRROR + self.mirror_table(), + today=THE_DAY, + url_ok=url_ok, + mirror=MIRROR, + builder_inputs={}, ) url = f"{MIRROR.base}/images-arch-install/{MIRROR_ASSET}" self.assertEqual(report.failures, []) self.assertIn(url, probed) self.assertIn(f"arch-install (staged): probed {url}", report.checked) + def test_a_mirror_entry_probes_its_build_inputs(self) -> None: + with tempfile.TemporaryDirectory() as tmp: + path = pathlib.Path(tmp) / "inputs.json" + path.write_text( + json.dumps( + { + "iso": {"url": "https://iso.invalid/a.iso"}, + "packages": { + "server": "https://pkg.invalid/2026/$repo/os/$arch" + }, + } + ), + encoding="utf-8", + ) + down = "https://pkg.invalid/2026/core/os/x86_64/core.db" + probed: list[str] = [] + + def url_ok(url: str) -> bool: + probed.append(url) + return url != down + + report = di.link_check( + self.mirror_table(), + today=THE_DAY, + url_ok=url_ok, + mirror=MIRROR, + builder_inputs={"arch-install": path}, + ) + self.assertIn("https://iso.invalid/a.iso", probed) + self.assertEqual( + report.failures, + [f"arch-install (staged): build input is unreachable: {down}"], + ) + + def test_an_unpinned_entry_is_checked_by_its_build_inputs(self) -> None: + with tempfile.TemporaryDirectory() as tmp: + path = pathlib.Path(tmp) / "inputs.json" + path.write_text( + json.dumps( + { + "iso": {"url": "https://iso.invalid/a.iso"}, + "packages": {"server": "https://pkg.invalid/$repo/os/$arch"}, + } + ), + encoding="utf-8", + ) + report = di.link_check( + self.mirror_table(asset=None, sha256=None), + today=THE_DAY, + url_ok=lambda _url: True, + mirror=MIRROR, + builder_inputs={"arch-install": path}, + ) + self.assertEqual(report.failures, []) + self.assertEqual(report.unchecked, []) + self.assertIn( + "arch-install (staged): probed https://iso.invalid/a.iso, probed" + " https://pkg.invalid/core/os/x86_64/core.db, no asset pinned yet", + report.checked, + ) + + def test_unreadable_build_inputs_fail(self) -> None: + report = di.link_check( + self.mirror_table(), + today=THE_DAY, + url_ok=lambda _url: True, + mirror=MIRROR, + builder_inputs={"arch-install": pathlib.Path("/nonexistent/inputs.json")}, + ) + self.assertEqual(len(report.failures), 1, report.failures) + self.assertIn("cannot read inputs.json", report.failures[0]) + + def test_the_shipped_builder_pins_an_iso_and_a_snapshot(self) -> None: + iso, core = di.builder_urls(di.BUILDER_INPUTS["arch-install"]) + self.assertTrue(iso.endswith("-x86_64.iso"), iso) + self.assertTrue(core.endswith("/core/os/x86_64/core.db"), core) + def test_a_missing_mirror_asset_fails(self) -> None: url = f"{MIRROR.base}/images-arch-install/{MIRROR_ASSET}" report = di.link_check( @@ -613,6 +703,7 @@ def test_a_missing_mirror_asset_fails(self) -> None: today=THE_DAY, url_ok=lambda probed: probed != url, mirror=MIRROR, + builder_inputs={}, ) self.assertEqual( report.failures, @@ -625,11 +716,12 @@ def test_a_mirror_entry_without_an_asset_is_listed_as_not_checked(self) -> None: today=THE_DAY, url_ok=lambda _url: True, mirror=MIRROR, + builder_inputs={}, ) self.assertEqual(report.failures, []) self.assertEqual( report.unchecked, - ["arch-install (staged): a mirror source that pins no asset yet"], + ["arch-install (staged): no asset pinned yet"], ) def test_a_mirror_that_is_not_configured_is_listed_as_not_checked(self) -> None: @@ -638,6 +730,7 @@ def test_a_mirror_that_is_not_configured_is_listed_as_not_checked(self) -> None: today=THE_DAY, url_ok=lambda _url: True, mirror=di.Mirror(base="", tag_prefix="images-"), + builder_inputs={}, ) self.assertEqual(report.failures, []) self.assertEqual( @@ -655,6 +748,7 @@ def url_ok(url: str) -> bool: offline=True, url_ok=url_ok, mirror=MIRROR, + builder_inputs={}, ) self.assertIn( "arch-install (staged): offline, and no upstreamUntil", report.unchecked diff --git a/docs/ci.md b/docs/ci.md index e3dc73efe..fa69931df 100644 --- a/docs/ci.md +++ b/docs/ci.md @@ -159,7 +159,7 @@ There used to be a second, per-PR container lane (`distro-smoke` in `ci.yml`). I - **Staged scenarios.** A dispatch or call with `suite` set to `staged` runs the scenarios of each image staged for its family's admission (`stagedImages` in `nix/distro-tests/default.nix`, today `arch-boxes`, not every disabled entry of the image table) instead of the other suites: the image's smoke scenario and its login- and boot-record scenario, each with a test-only build of `nails` that admits the family (`nix/distro-tests/lib/admitted.nix`) and is never released. `distros` then names them, such as `arch-boxes-smoke` and `arch-boxes-records`; empty runs every one. Each is a derivation that `nix build` runs in the Nix build sandbox, as a smoke scenario is, in a job of its own, and its failure only warns. No nightly or pull request runs them. The commit that admits a family takes its image out of that list and enables it in the image table, which also makes the oracle nightly's driver run the release binary on it. - **Staged drivers.** The staged suite also runs the drivers of Fedora's admission gate (`nix/distro-tests/fedora-gate.nix`), for each pinned Fedora image: `-rpms`, which resolves the closure of tuned, firewalld and ABRT on the image itself from the release's own repository; `-gate`, the gate scenario on the image booted with SELinux enforcing, with the release binary and the locked closure installed offline; `-gate-noda`, the same with the policy's dontaudit rules off; and `-btrfs`, the btrfs scan controls on the stock image ([details](../nix/e2e-tests/README.md#the-admission-gate-of-fedora)). `distros` names them as it names the staged scenarios, such as `fedora-44-gate`; empty runs every one whose image is pinned, with every staged scenario. Each driver is one job, and at most `max-jobs` of the suite's jobs run at once. A staged driver is a host driver, built and run as a probe is, with `NAILS_GATE_OUT` naming where it writes. The job uploads the `staged-` artifact, kept 30 days, with what the driver wrote and its log, also when the driver failed, and then fails with the driver's exit status; that failure only warns, as a staged scenario's does. - **Adding a distribution** is one entry in `nix/distro-tests/images.json`, which `nix/distro-tests/images.nix` checks; see `nix/e2e-tests/README.md`. The image hashes and the `nix-vm-test` lock are pinned on a networked KVM host, not in the sandbox. -- **Image links.** The weekly `distro-images` task of `scheduled.yml` runs `python3 -m ci.distro_images link-check` over every entry of `nix/distro-tests/images.json`, the disabled ones too: a disabled image stays out of the smoke matrix until a change enables it, and the probes (`nix/distro-tests/probe.nix`) boot the Arch ones before then, but its pin lapses all the same. It fails 14 days before an entry's `upstreamUntil` date, and when the image URL an entry pins no longer answers: an upstream entry's own URL, or for a `nix-vm-test` entry the dated Debian or Ubuntu URL that `nix-vm-test` pins at the revision `flake.lock` locks, read from its image list. A `mirror` entry is probed at the asset it pins in the assets repository that `nix/distro-tests/mirrors.nix` names (see [The test images](#the-test-images-test-imagesyml)); one that pins no asset yet is listed as not checked. A pending entry names no URL, so only a date it carries is checked. It names each entry it checked, marking each disabled one `(staged)`, and fails when it could check no enabled entry, whatever it found for the disabled ones. Of those, only the images `stagedImages` lists run in the staged suite. `python3 -m ci.distro_images repin` bumps the upstream pins, and moves a mirror entry to the newest build its release's `-latest.json` names; `--all` leaves out a pending entry, which is pinned the first time by naming it, and an entry that does not resolve fails the command without holding back the others. +- **Image links.** The weekly `distro-images` task of `scheduled.yml` runs `python3 -m ci.distro_images link-check` over every entry of `nix/distro-tests/images.json`, the disabled ones too: a disabled image stays out of the smoke matrix until a change enables it, and the probes (`nix/distro-tests/probe.nix`) boot the Arch ones before then, but its pin lapses all the same. It fails 14 days before an entry's `upstreamUntil` date, and when the image URL an entry pins no longer answers: an upstream entry's own URL, or for a `nix-vm-test` entry the dated Debian or Ubuntu URL that `nix-vm-test` pins at the revision `flake.lock` locks, read from its image list. A `mirror` entry is probed at the asset it pins in the assets repository that `nix/distro-tests/mirrors.nix` names (see [The test images](#the-test-images-test-imagesyml)); one that pins no asset yet names that in its line. For the archinstall image it also probes what its builder pins in `nix/distro-tests/arch-install/inputs.json`, the ISO and the package snapshot's `core.db`, since the nightly rebuild fails once either is gone; with those probed, an entry that pins no asset yet is among the checked ones too. A pending entry names no URL, so only a date it carries is checked. It names each entry it checked, marking each disabled one `(staged)`, and fails when it could check no enabled entry, whatever it found for the disabled ones. Of those, only the images `stagedImages` lists run in the staged suite. `python3 -m ci.distro_images repin` bumps the upstream pins, and moves a mirror entry to the newest build its release's `-latest.json` names; `--all` leaves out a pending entry, which is pinned the first time by naming it, and an entry that does not resolve fails the command without holding back the others. - **Concurrency.** The runs of a pull request share a concurrency group, so a new push, or adding the `distro-e2e` label, cancels the run in progress, and the cancelled run reports nothing: `distro-result` runs only in a run that was not cancelled. Every label added to a pull request starts a run, but only a run for the `distro-e2e` label tests anything. A run for any other label skips `plan` and the VM jobs, passes, and gets a group of its own, so it can neither cancel a run that tests nor be cancelled. Such a run's `distro-result` passes without testing anything, under the same name as a run that tests, so revisit this before `distro-result` becomes a required check. A draft that becomes ready runs nothing again. A scheduled or dispatched run never cancels a run in progress: it waits for an earlier run of the same event and ref, and since GitHub keeps only one waiting run per group, a newer run replaces one that has not started. A dispatch of one suite waits in a group of its own, so it neither waits for a run of every suite on the same branch nor replaces one. A call counts as its caller's event, so call the workflow from a scheduled, dispatched or push-triggered workflow, not from a pull request one. ### The test images (`test-images.yml`) From 8a0710846a5752569b9eb49942293e03e6e89554 Mon Sep 17 00:00:00 2001 From: WitteShadovv Date: Wed, 25 Nov 2026 12:43:03 +0100 Subject: [PATCH 08/13] test(distro): pin the archinstall image to its first published build Run 45604987470 of test-images.yml built, published and verified arch-install-2026.11.01-20261125-45604987470.qcow2 in the release images-arch-install of WitteShadovv/nails-test-images. `repin arch-install` pins the entry to it from arch-install-latest.json. The entry stays disabled until the Arch admission enables it; the probe and refusal suites boot it now, and docs/ci.md names it among the refusal's images. --- docs/ci.md | 2 +- nix/distro-tests/images.json | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/ci.md b/docs/ci.md index fa69931df..8523ef37c 100644 --- a/docs/ci.md +++ b/docs/ci.md @@ -153,7 +153,7 @@ There used to be a second, per-PR container lane (`distro-smoke` in `ci.yml`). I - **Trigger.** A nightly schedule; a pull request to `main` or `next`; manual dispatch; and `workflow_call`. A push to a pull request runs the records and refusal suites when the change touches what they are built from (the path filter below), and the smoke suite too when the pull request carries the `distro-e2e` label. Adding that label runs all three at once, whatever the change. The nightly runs, and a dispatch or call that leaves `suite` at `all`, run the smoke, records and refusal suites; `suite` can also name one of them, the probes or the staged scenarios and drivers. The nightly run of `next` is a dispatch from `next-nightly.yml`. - **Runner.** Each VM needs KVM, so the `runner` input selects where the jobs run (a hosted `ubuntu-26.04` exposes `/dev/kvm`; a self-hosted KVM runner is a label list). The matrix is planned by `python3 -m ci.e2e distro-plan`: the smoke shards are kept at or below `max-jobs` parallel jobs (distributions times their shards), eight by default, and each records scenario, refusal, probe and staged scenario or driver is a job of its own; at most `max-jobs` of the jobs that do not gate run at once. `distros` names what to run: distributions for the smoke and records suites, images such as `arch-boxes` for the refusal suite, probes for the probe suite and staged scenarios and drivers such as `arch-boxes-smoke` and `fedora-44-rpms` for the staged suite. Each suite runs what it has of the names, and empty runs every entry of each suite. A name that no selected suite has fails the plan, and so do a plan with no job and, when no name is given, a selected suite with nothing to run, so that a suite cannot drop out of a run unseen. - **Coverage.** One smoke scenario per distribution (`nix/distro-tests/tests/smoke.nix`), today Debian 13, Ubuntu 24.04, Ubuntu 26.04, Fedora 44 and Fedora 45: platform detection, the decoy-persistence preflight, the `fstab-policy` refusal of a `noauto` line below the hidden root (exit 4), activation soft-rebooting the stock cloud image into an overlay of its own root (every hidden write, `/usr` included, lands on the hidden root; the ESP stays read-only), deactivation and emergency soft-rebooting back, and the host-side decoy disk-image leak check with null and positive controls. The scenario lists the failed units on the decoy before the first switch, right after each switch, and in each hidden session again just before its way back, which resets the units that failed in the session, and each listing must hold exactly the units the entry's `knownFailedUnits` lists for its phase, each failed with its known line, while the `platform` row of `check` must warn about each unit listed. A listing sees only what is failed at that moment, not a unit that failed while a switch stopped the old system and that the new system started again. Ubuntu 26.04 lists chrony, which an upstream AppArmor issue fails in the hidden sessions and after the way back, and CUPS, which its warning names as well but its cloud image does not install. Ubuntu 24.04 lists none. Debian 13 and the Fedora images have no list yet, so their failed units are only printed. A known failure that a newer image fixes fails the scenario until the list is narrowed ([details](../nix/e2e-tests/README.md#known-failures)). Debian 13 also runs the Nix scenario (`nix/distro-tests/tests/nix-trace.nix`) among its smoke scenarios, in a shard of its own where the job ceiling leaves room: Nix's multi-user installer run in a hidden session, whose store writes, files in `/etc` and build users must land on the hidden volume, while the decoy and an image of its disk must show none of the marks the scenario looks for, with an install on the decoy as the positive control ([details](../nix/e2e-tests/README.md#the-nix-scenario)). Debian 13, Ubuntu 24.04 and Ubuntu 26.04 also run the unattended-upgrades scenario (`nix/distro-tests/tests/apt-shutdown.nix`) among their smoke scenarios: a daily unattended-upgrade run held with its lock taken, during which `check` and `activate` refuse and the decoy disk gains no line, with a plain soft-reboot during the run as the positive control; `apt-daily.service` held before its download takes the lock, which `check` and `activate` refuse, with a plain soft-reboot that meets the lock as the positive control; `Unattended-Upgrade::InstallOnShutdown` on, which `check` and `activate` refuse, and the line deleted after the helper read it and a file apt refuses while the helper holds the setting on, which `check` refuses, each with an activation under `--allow-persistent-decoy` as the positive control; the decoy's helper stopped but enabled, which only warns, with the session's copy logging its shutdown-mode run into the upper at the way back; and, on Debian 13, the warning of a helper without python3-gi ([details](../nix/e2e-tests/README.md#the-unattended-upgrades-scenario)). Like every smoke scenario they run on a pull request only with the `distro-e2e` label, and their failure only warns. -- **Records and refusal.** The `records` suite runs the login- and boot-record scenarios of `nix/distro-tests/records.nix` on Debian 13, Ubuntu 24.04, Fedora 44 and Fedora 45: each power-cycles the decoy for a reference, keeps a session until the kernel has been up for more than five minutes, deactivates, and checks that the session added one boot record as a power cycle does, named reboot and dated at the way back, with a plain soft-reboot as the positive control; on Fedora, where a plain soft-reboot's boot record reads as a power cycle's, a login and a failed login run in the session and must leave no record on the decoy. The records suite also runs the access-time scenarios of `nix/distro-tests/access-times.nix`, on Debian 13, Fedora 44 and Fedora 45: each fails when `nails check`, an activation or a way back reads a file of the decoy disk, on a root mounted `relatime`, that a plain soft-reboot of the decoy does not read, though they may not see a read of `/etc/selinux/config`, which they do not age ([details](../nix/e2e-tests/README.md#the-access-time-scenarios)). The `refusal` suite runs the refusal of `nix/distro-tests/refusal.nix` on each pinned Arch image (`arch-boxes` today) ([details](../nix/e2e-tests/README.md#the-refusal-of-arch)). Each is a host driver and a job of its own, named after its distribution or image and its suite, such as `debian-13 records`: the job builds the driver and runs it on the runner, outside the Nix build sandbox, as the probe job does, and it stops the driver after its time limit (30 minutes for a records scenario, 20 for a refusal). The Debian records scenario installs wtmpdb over the guest's network. `distro-result` fails when one of these jobs failed, or was planned and did not run, and when the plan left no suite or job count behind. +- **Records and refusal.** The `records` suite runs the login- and boot-record scenarios of `nix/distro-tests/records.nix` on Debian 13, Ubuntu 24.04, Fedora 44 and Fedora 45: each power-cycles the decoy for a reference, keeps a session until the kernel has been up for more than five minutes, deactivates, and checks that the session added one boot record as a power cycle does, named reboot and dated at the way back, with a plain soft-reboot as the positive control; on Fedora, where a plain soft-reboot's boot record reads as a power cycle's, a login and a failed login run in the session and must leave no record on the decoy. The records suite also runs the access-time scenarios of `nix/distro-tests/access-times.nix`, on Debian 13, Fedora 44 and Fedora 45: each fails when `nails check`, an activation or a way back reads a file of the decoy disk, on a root mounted `relatime`, that a plain soft-reboot of the decoy does not read, though they may not see a read of `/etc/selinux/config`, which they do not age ([details](../nix/e2e-tests/README.md#the-access-time-scenarios)). The `refusal` suite runs the refusal of `nix/distro-tests/refusal.nix` on each pinned Arch image (`arch-boxes` and `arch-install` today) ([details](../nix/e2e-tests/README.md#the-refusal-of-arch)). Each is a host driver and a job of its own, named after its distribution or image and its suite, such as `debian-13 records`: the job builds the driver and runs it on the runner, outside the Nix build sandbox, as the probe job does, and it stops the driver after its time limit (30 minutes for a records scenario, 20 for a refusal). The Debian records scenario installs wtmpdb over the guest's network. `distro-result` fails when one of these jobs failed, or was planned and did not run, and when the plan left no suite or job count behind. - **Path filter.** On a pull request, a push runs the tier only when the change touches what its scenarios and drivers are built from: what `flake.nix` builds the binary from (the crates it links, `nails-oracle`'s manifest alone, `.cargo/`, the workspace manifest and lock and the toolchain pin), `flake.nix` and `flake.lock`, `nix/distro-tests/`, the files of `nix/e2e-tests/` the tier reads (`py/`, `lib/records.py`, `lib/disk-forensics.nix`, `lib/disk_forensics.py` and `fixtures/indicators.json`), `ci/e2e/`, the `setup-nix` action and `distro-e2e.yml` itself. The change is the diff between the merge commit and its first parent, a moved file counted under both its names, and an unknown base counts as a change. `ci/tests` checks the filter against every crate of the workspace and against every path the tier's Nix files read, following their imports. Without a match the run tests nothing and `distro-result` passes. A dispatch, a call and adding the `distro-e2e` label are not filtered. - **Probes.** A dispatch or call with `suite` set to `probe` runs the fact probes of the Fedora and Arch images instead of the other suites (`nix/distro-tests/probe.nix`, [the fixtures](../nix/distro-tests/probe/README.md)). `distros` then names probes, such as `fedora-44`, `fedora-44-enforcing` and `arch-boxes`; empty runs every probe whose image is pinned. Each probe is one job, and at most `max-jobs` of them run at once. A probe is a host driver: its job builds the driver and runs it on the runner, outside the Nix build sandbox, as the oracle nightly runs its test, and the job stops the driver after the probe's time limit. The job uploads the `probe-` artifact, kept 30 days, with `.json`, the record the matching fixture holds, `.raw.json`, the output of every query, and the driver's log. It shows the record in its summary, or fails when the record is not recorded because the run read no kernel release or no soft-reboot. A probe run waits in a concurrency group of its own, so it neither waits for a smoke run of the same branch nor replaces one. - **Staged scenarios.** A dispatch or call with `suite` set to `staged` runs the scenarios of each image staged for its family's admission (`stagedImages` in `nix/distro-tests/default.nix`, today `arch-boxes`, not every disabled entry of the image table) instead of the other suites: the image's smoke scenario and its login- and boot-record scenario, each with a test-only build of `nails` that admits the family (`nix/distro-tests/lib/admitted.nix`) and is never released. `distros` then names them, such as `arch-boxes-smoke` and `arch-boxes-records`; empty runs every one. Each is a derivation that `nix build` runs in the Nix build sandbox, as a smoke scenario is, in a job of its own, and its failure only warns. No nightly or pull request runs them. The commit that admits a family takes its image out of that list and enables it in the image table, which also makes the oracle nightly's driver run the release binary on it. diff --git a/nix/distro-tests/images.json b/nix/distro-tests/images.json index 34a8e5aee..3560be38a 100644 --- a/nix/distro-tests/images.json +++ b/nix/distro-tests/images.json @@ -148,8 +148,8 @@ "kind": "mirror", "family": "arch-install", "release": "rolling", - "asset": null, - "sha256": null + "asset": "arch-install-2026.11.01-20261125-45604987470.qcow2", + "sha256": "sha256-3CGFbdliAbfexsaY8XRETYrubAVMfH4dfnWL9aUmwLI=" } } } From 2c7f2530cdc75d5613d1095f5f7b8779262a8b0f Mon Sep 17 00:00:00 2001 From: WitteShadovv Date: Wed, 25 Nov 2026 13:02:05 +0100 Subject: [PATCH 09/13] test(distro): record the probe facts of the archinstall image distro-e2e.yml run 45608598475 ran the probe on the pinned archinstall image, booted with OVMF on q35 through the harness: kernel 7.2.11, systemd 262.1, the btrfs @, @home, @log and @pkg subvolumes with the ESP at /boot, zram swap, no failed unit at boot or after the soft reboot. The fixture is that run's record, and the README marks it recorded. --- nix/distro-tests/probe/README.md | 2 +- nix/distro-tests/probe/arch-install.json | 300 +++++++++++++++++++++-- 2 files changed, 278 insertions(+), 24 deletions(-) diff --git a/nix/distro-tests/probe/README.md b/nix/distro-tests/probe/README.md index abe455807..dc7f11bab 100644 --- a/nix/distro-tests/probe/README.md +++ b/nix/distro-tests/probe/README.md @@ -32,7 +32,7 @@ image, with `-enforcing` added for a Fedora image booted with SELinux enforcing. image, booted permissive and enforcing as for Fedora 44 (recorded) - `arch-boxes.json` -- the pinned Arch `arch-boxes` image (recorded) - `arch-install.json` -- the `archinstall`-built Arch image, which - `.github/workflows/test-images.yml` builds and publishes + `.github/workflows/test-images.yml` builds and publishes (recorded) Debian and Ubuntu need no probe: they are admitted and covered by the smoke suite directly. diff --git a/nix/distro-tests/probe/arch-install.json b/nix/distro-tests/probe/arch-install.json index 64258b942..de129d4e6 100644 --- a/nix/distro-tests/probe/arch-install.json +++ b/nix/distro-tests/probe/arch-install.json @@ -2,58 +2,312 @@ "image": "arch-install", "osId": "arch", "enforcing": false, - "imageFile": null, - "recorded": false, + "imageFile": "arch-install-2026.11.01-20261125-45604987470.qcow2", + "recorded": true, "facts": { "selinuxMode": null, "selinuxBackdoorDomain": null, "selinuxLabels": null, "selinuxPolicyLoads": null, - "kernelRelease": null, - "moduleDirs": null, - "systemdVersion": null, - "mounts": [], - "fstab": null, - "swaps": [], - "mountUnits": [], + "kernelRelease": "7.2.11-arch1-1", + "moduleDirs": [ + "7.2.11-arch1-1" + ], + "systemdVersion": "systemd 262 (262.1-1-arch)", + "mounts": [ + { + "target": "/", + "fstype": "btrfs", + "options": "rw,relatime,compress=zstd:3,discard=async,space_cache=v2,subvolid=256,subvol=/@" + }, + { + "target": "/boot", + "fstype": "vfat", + "options": "rw,relatime,fmask=0177,dmask=0077,codepage=437,iocharset=ascii,shortname=mixed,utf8,errors=remount-ro" + }, + { + "target": "/home", + "fstype": "btrfs", + "options": "rw,relatime,compress=zstd:3,discard=async,space_cache=v2,subvolid=257,subvol=/@home" + }, + { + "target": "/var/cache/pacman/pkg", + "fstype": "btrfs", + "options": "rw,relatime,compress=zstd:3,discard=async,space_cache=v2,subvolid=259,subvol=/@pkg" + }, + { + "target": "/var/log", + "fstype": "btrfs", + "options": "rw,relatime,compress=zstd:3,discard=async,space_cache=v2,subvolid=258,subvol=/@log" + } + ], + "fstab": [ + { + "source": "UUID=e513c647-706f-43c6-8406-9f7349369429", + "target": "/", + "fstype": "btrfs", + "options": "rw,relatime,compress=zstd:3,discard=async,space_cache=v2,subvol=/@", + "dump": 0, + "pass": 0 + }, + { + "source": "UUID=e513c647-706f-43c6-8406-9f7349369429", + "target": "/home", + "fstype": "btrfs", + "options": "rw,relatime,compress=zstd:3,discard=async,space_cache=v2,subvol=/@home", + "dump": 0, + "pass": 0 + }, + { + "source": "UUID=e513c647-706f-43c6-8406-9f7349369429", + "target": "/var/cache/pacman/pkg", + "fstype": "btrfs", + "options": "rw,relatime,compress=zstd:3,discard=async,space_cache=v2,subvol=/@pkg", + "dump": 0, + "pass": 0 + }, + { + "source": "UUID=e513c647-706f-43c6-8406-9f7349369429", + "target": "/var/log", + "fstype": "btrfs", + "options": "rw,relatime,compress=zstd:3,discard=async,space_cache=v2,subvol=/@log", + "dump": 0, + "pass": 0 + }, + { + "source": "UUID=7C69-A7EA", + "target": "/boot", + "fstype": "vfat", + "options": "rw,relatime,fmask=0177,dmask=0077,codepage=437,iocharset=ascii,shortname=mixed,utf8,errors=remount-ro", + "dump": 0, + "pass": 2 + } + ], + "swaps": [ + { + "name": "/dev/zram0", + "type": "partition", + "size": 1023930368, + "priority": 100 + } + ], + "mountUnits": [ + { + "unit": "proc-sys-fs-binfmt_misc.automount", + "load": "loaded", + "active": "active", + "sub": "waiting", + "fragmentPath": "/usr/lib/systemd/system/proc-sys-fs-binfmt_misc.automount", + "sourcePath": null + }, + { + "unit": "-.mount", + "load": "loaded", + "active": "active", + "sub": "mounted", + "fragmentPath": "/run/systemd/generator/-.mount", + "sourcePath": "/etc/fstab" + }, + { + "unit": "boot.mount", + "load": "loaded", + "active": "active", + "sub": "mounted", + "fragmentPath": "/run/systemd/generator/boot.mount", + "sourcePath": "/etc/fstab" + }, + { + "unit": "dev-hugepages.mount", + "load": "loaded", + "active": "active", + "sub": "mounted", + "fragmentPath": "/usr/lib/systemd/system/dev-hugepages.mount", + "sourcePath": null + }, + { + "unit": "dev-mqueue.mount", + "load": "loaded", + "active": "active", + "sub": "mounted", + "fragmentPath": "/usr/lib/systemd/system/dev-mqueue.mount", + "sourcePath": null + }, + { + "unit": "home.mount", + "load": "loaded", + "active": "active", + "sub": "mounted", + "fragmentPath": "/run/systemd/generator/home.mount", + "sourcePath": "/etc/fstab" + }, + { + "unit": "proc-sys-fs-binfmt_misc.mount", + "load": "loaded", + "active": "inactive", + "sub": "dead", + "fragmentPath": "/usr/lib/systemd/system/proc-sys-fs-binfmt_misc.mount", + "sourcePath": null + }, + { + "unit": "sys-fs-fuse-connections.mount", + "load": "loaded", + "active": "active", + "sub": "mounted", + "fragmentPath": "/usr/lib/systemd/system/sys-fs-fuse-connections.mount", + "sourcePath": null + }, + { + "unit": "sys-kernel-config.mount", + "load": "loaded", + "active": "active", + "sub": "mounted", + "fragmentPath": "/usr/lib/systemd/system/sys-kernel-config.mount", + "sourcePath": null + }, + { + "unit": "sys-kernel-debug.mount", + "load": "loaded", + "active": "active", + "sub": "mounted", + "fragmentPath": "/usr/lib/systemd/system/sys-kernel-debug.mount", + "sourcePath": null + }, + { + "unit": "sys-kernel-tracing.mount", + "load": "loaded", + "active": "active", + "sub": "mounted", + "fragmentPath": "/usr/lib/systemd/system/sys-kernel-tracing.mount", + "sourcePath": null + }, + { + "unit": "tmp.mount", + "load": "loaded", + "active": "active", + "sub": "mounted", + "fragmentPath": "/usr/lib/systemd/system/tmp.mount", + "sourcePath": null + }, + { + "unit": "var-cache-pacman-pkg.mount", + "load": "loaded", + "active": "active", + "sub": "mounted", + "fragmentPath": "/run/systemd/generator/var-cache-pacman-pkg.mount", + "sourcePath": "/etc/fstab" + }, + { + "unit": "var-lib-machines.mount", + "load": "loaded", + "active": "inactive", + "sub": "dead", + "fragmentPath": "/usr/lib/systemd/system/var-lib-machines.mount", + "sourcePath": null + }, + { + "unit": "var-log.mount", + "load": "loaded", + "active": "active", + "sub": "mounted", + "fragmentPath": "/run/systemd/generator/var-log.mount", + "sourcePath": "/etc/fstab" + }, + { + "unit": "dev-disk-by\\x2ddiskseq-4.swap", + "load": "loaded", + "active": "active", + "sub": "active", + "fragmentPath": null, + "sourcePath": null + }, + { + "unit": "dev-zram0.swap", + "load": "loaded", + "active": "active", + "sub": "active", + "fragmentPath": "/run/systemd/generator/dev-zram0.swap", + "sourcePath": null + } + ], "generatorUnits": { - "/run/systemd/generator": null, + "/run/systemd/generator": [ + "-.mount", + "boot.mount", + "dev-zram0.swap", + "getty.target.wants", + "home.mount", + "local-fs.target.requires", + "local-fs.target.wants", + "swap.target.wants", + "systemd-zram-setup@zram0.service.d", + "var-cache-pacman-pkg.mount", + "var-log.mount" + ], "/run/systemd/generator.late": null }, - "tools": {}, + "tools": { + "systemctl": "/usr/bin/systemctl", + "loginctl": "/usr/bin/loginctl", + "busctl": "/usr/bin/busctl", + "journalctl": "/usr/bin/journalctl", + "dmsetup": "/usr/bin/dmsetup", + "ip": "/usr/bin/ip", + "nft": "/usr/bin/nft", + "cryptsetup": "/usr/bin/cryptsetup", + "sh": "/usr/bin/sh", + "mount": "/usr/bin/mount", + "sync": "/usr/bin/sync", + "swapoff": "/usr/bin/swapoff", + "kill": "/usr/bin/kill", + "systemd-run": "/usr/bin/systemd-run", + "modprobe": "/usr/bin/modprobe", + "cp": "/usr/bin/cp", + "chown": "/usr/bin/chown" + }, "services": { "auditd": { - "enabled": null, - "active": null + "enabled": "disabled", + "active": "inactive" }, "tuned": { - "enabled": null, - "active": null + "enabled": "not-found", + "active": "inactive" }, "firewalld": { - "enabled": null, - "active": null + "enabled": "not-found", + "active": "inactive" }, "abrtd": { - "enabled": null, - "active": null + "enabled": "not-found", + "active": "inactive" } }, - "auditdRefuseManualStop": null, + "auditdRefuseManualStop": true, "packages": null, "journaldVendorConfig": { - "storage": null, + "storage": "persistent", "sources": [], "credential": null, "vendorHint": null }, "failedBootUnits": [], - "maskedUnits": [], + "maskedUnits": [ + "archlinux-keyring-wkd-sync.service", + "pacman-init.service", + "serial-getty@hvc0.service", + "serial-getty@ttyS0.service", + "sshd.service", + "systemd-boot-update.service", + "systemd-networkd-wait-online.service", + "systemd-time-wait-sync.service", + "sshd.socket", + "archlinux-keyring-wkd-sync.timer" + ], "updatedbPrunePaths": [], "avcs": [], "ninePUnderEnforcing": null, "derivativeOsRelease": {}, - "softRebootsCount": null, + "softRebootsCount": 1, "failedUnitsAfterSoftReboot": [], "avcsAfterSoftReboot": [], "selinuxLabelsAfterSoftReboot": null, From de29be236d233cf3d38aaf41e66409f103c9d028 Mon Sep 17 00:00:00 2001 From: WitteShadovv Date: Wed, 25 Nov 2026 13:48:39 +0100 Subject: [PATCH 10/13] fix(test-images): prune and replace assets only with every pin read The prune deleted builds even when the images.json of main, next or the run's commit could not be read, which it only warned about, so a failed read could delete a pinned asset. The publish job now reads the three with its own read-only token through the API, counts only a branch that does not exist as pinning nothing, and deletes no build unless every read succeeded. A re-run of the publish job alone keeps the build's name and would replace the asset of that name. Every build's name now carries the run attempt as well, and the job refuses to replace an existing asset of its name when a read failed or an images.json pins it. The download-artifact pin is v8.0.2, not v6.0.0 as its comment said. --- .github/workflows/test-images.yml | 94 +++++++++++++++++++++++-------- docs/ci.md | 2 +- 2 files changed, 71 insertions(+), 25 deletions(-) diff --git a/.github/workflows/test-images.yml b/.github/workflows/test-images.yml index 8e363654e..1b9040891 100644 --- a/.github/workflows/test-images.yml +++ b/.github/workflows/test-images.yml @@ -12,15 +12,19 @@ name: Test images # prompt, and the compressed qcow2 (under 2 GiB) is kept as an # artifact with its SHA-256 and manifest # publish uploads them to the release images-arch-install (created when it -# is missing; an asset of the same name is replaced), replaces -# arch-install-latest.json with the new manifest, and deletes the -# older builds beyond the newest three that no images.json of -# main, next or this commit pins +# is missing), replaces arch-install-latest.json with the new +# manifest, and deletes the older builds beyond the newest three +# that no images.json of main, next or this commit pins. It +# deletes nothing, and replaces no asset of the same name, unless +# it could read all three images.json, and it never replaces a +# pinned asset # verify downloads the asset from its public URL and checks its SHA-256 # -# Every build gets a name of its own (the ISO version, the UTC date and the -# run ID), so a nightly build never replaces the asset that images.json pins; -# a re-run of the same run replaces its own upload. `python3 -m ci.distro_images +# Every build gets a name of its own (the ISO version, the UTC date, the run +# ID and the attempt), so a nightly build never replaces the asset that +# images.json pins; only a re-run of the publish job alone, which keeps the +# build's name, meets an asset of its own name, and replaces it only when no +# images.json pins it. `python3 -m ci.distro_images # repin arch-install` moves the pin to the newest build, which the latest # manifest names. # @@ -107,9 +111,10 @@ jobs: id: name env: RUN_ID: ${{ github.run_id }} + RUN_ATTEMPT: ${{ github.run_attempt }} run: | iso=$(jq -er .iso.version nix/distro-tests/arch-install/inputs.json) - asset="$FAMILY-$iso-$(date -u +%Y%m%d)-$RUN_ID.qcow2" + asset="$FAMILY-$iso-$(date -u +%Y%m%d)-$RUN_ID-$RUN_ATTEMPT.qcow2" echo "asset=$asset" >> "$GITHUB_OUTPUT" echo "Building $asset" @@ -183,7 +188,7 @@ jobs: steps: - name: Fetch the image - uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v6.0.0 + uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2 with: name: arch-install-image path: ${{ runner.temp }}/image @@ -201,26 +206,46 @@ jobs: cp "$ASSET.json" "$FAMILY-latest.json" # The assets a prune must keep: the one each images.json of main, next - # and this commit pins, read from the public repository without a token. + # and this commit pins, read with the job's own read-only token. The + # list is complete only when every read succeeded; a branch that does + # not exist pins nothing, but any other failed read leaves the list + # incomplete, and then nothing is pruned and no asset is replaced. - name: List the pinned assets + id: pins env: + GH_TOKEN: ${{ github.token }} REPOSITORY: ${{ github.repository }} SHA: ${{ github.sha }} run: | - : > "$RUNNER_TEMP/pinned" + pinned="$RUNNER_TEMP/pinned" + : > "$pinned" + complete=yes for ref in main next "$SHA"; do - url="https://raw.githubusercontent.com/$REPOSITORY/$ref/nix/distro-tests/images.json" - if table=$(curl -fsSL --retry 3 "$url"); then - jq -r --arg family "$FAMILY" \ + if table=$(gh api -H "Accept: application/vnd.github.raw+json" \ + "repos/$REPOSITORY/contents/nix/distro-tests/images.json?ref=$ref" 2> "$RUNNER_TEMP/read-error"); then + if ! jq -r --arg family "$FAMILY" \ '.[] | .source | select(.kind == "mirror" and .family == $family and .asset != null) | .asset' \ - <<< "$table" >> "$RUNNER_TEMP/pinned" - else - echo "::warning::Could not read images.json of $ref; its pin is not protected from the prune." + <<< "$table" >> "$pinned"; then + complete=no + echo "::warning::images.json of $ref is not the table this step reads." + fi + continue + fi + if [ "$ref" != "$SHA" ]; then + if gh api "repos/$REPOSITORY/branches/$ref" --jq .name > /dev/null 2> "$RUNNER_TEMP/branch-error"; then + : + elif grep -q '(HTTP 404)' "$RUNNER_TEMP/branch-error"; then + echo "There is no branch $ref, so it pins nothing." + continue + fi fi + complete=no + echo "::warning::Could not read images.json of $ref: $(head -c 300 "$RUNNER_TEMP/read-error")" done - sort -u -o "$RUNNER_TEMP/pinned" "$RUNNER_TEMP/pinned" - echo "Pinned assets:" - cat "$RUNNER_TEMP/pinned" + sort -u -o "$pinned" "$pinned" + echo "complete=$complete" >> "$GITHUB_OUTPUT" + echo "Pinned assets (list complete: $complete):" + cat "$pinned" # The one step that holds the upload token. It runs gh alone, on the # files the build job produced and their checked hash. @@ -228,6 +253,7 @@ jobs: env: GH_TOKEN: ${{ secrets.NAILS_TEST_IMAGES_TOKEN }} # zizmor: ignore[secrets-outside-env] ASSET: ${{ needs.build.outputs.asset }} + PINS_COMPLETE: ${{ steps.pins.outputs.complete }} working-directory: ${{ runner.temp }}/image run: | if [ -z "$GH_TOKEN" ]; then @@ -240,15 +266,35 @@ jobs: --notes "Nightly builds of the $FAMILY test image of WitteShadovv/nails (nix/distro-tests/arch-install). Each build is a qcow2 with its .sha256 and .json manifest; $FAMILY-latest.json names the newest. Test data, not a release of NAILS." \ --latest=false fi + list_assets() { + release_id=$(gh api "repos/$ASSETS_REPO/releases/tags/$RELEASE_TAG" --jq .id) + gh api --paginate "repos/$ASSETS_REPO/releases/$release_id/assets" \ + --jq '.[] | [.id, .name, .created_at] | @tsv' > "$RUNNER_TEMP/assets" + } + + # Replace an asset of the same name (a re-run of the publish job + # alone keeps the build's name) only when no protected ref pins it, + # and only when that is known. + list_assets + if awk -F '\t' -v n="$ASSET" '$2 == n { found = 1 } END { exit !found }' "$RUNNER_TEMP/assets"; then + if [ "$PINS_COMPLETE" != yes ] || grep -qxF "$ASSET" "$RUNNER_TEMP/pinned"; then + echo "::error::$ASSET is in the release already and is pinned, or the pins could not all be read; it is not replaced." + exit 1 + fi + echo "Replacing $ASSET, which no images.json pins." + fi gh release upload "$RELEASE_TAG" --repo "$ASSETS_REPO" --clobber \ "$ASSET" "$ASSET.sha256" "$ASSET.json" gh release upload "$RELEASE_TAG" --repo "$ASSETS_REPO" --clobber \ "$FAMILY-latest.json" - # Prune: keep the newest builds and every pinned one. - release_id=$(gh api "repos/$ASSETS_REPO/releases/tags/$RELEASE_TAG" --jq .id) - gh api --paginate "repos/$ASSETS_REPO/releases/$release_id/assets" \ - --jq '.[] | [.id, .name, .created_at] | @tsv' > "$RUNNER_TEMP/assets" + # Prune: keep the newest builds and every pinned one, and nothing at + # all when a pin could not be read. + if [ "$PINS_COMPLETE" != yes ]; then + echo "::warning::Not every images.json could be read, so no old build is deleted." + exit 0 + fi + list_assets grep -P '\t'"$FAMILY"'-[^\t]+\.qcow2\t' "$RUNNER_TEMP/assets" \ | sort -t "$(printf '\t')" -k3,3r | cut -f2 > "$RUNNER_TEMP/builds" || true tail -n +"$((KEEP_BUILDS + 1))" "$RUNNER_TEMP/builds" | while read -r build; do diff --git a/docs/ci.md b/docs/ci.md index 8523ef37c..bbfc75c18 100644 --- a/docs/ci.md +++ b/docs/ci.md @@ -167,7 +167,7 @@ There used to be a second, per-PR container lane (`distro-smoke` in `ci.yml`). I The archinstall image (the `arch-install` entry of `nix/distro-tests/images.json`) has no upstream that publishes it, so `test-images.yml` builds it every night from pinned inputs and publishes it as a release asset of the public assets repository `WitteShadovv/nails-test-images`, the `base` of `nix/distro-tests/mirrors.nix`. Each family has one release, `images-` (`tagFor`), and every asset stays under GitHub's 2 GiB limit, so none is split. - **Build.** The `build` job runs `nix run .#arch-install-image-builder` (`nix/distro-tests/arch-install/`) on a hosted `ubuntu-26.04` runner for KVM. It boots the kernel of the Arch ISO that `inputs.json` pins by hash under UEFI (OVMF), on the q35 machine with a blank 16 GiB SATA disk, as the test harness boots it, and the ISO on a virtio-scsi CD drive. The ISO's own automated-script hook runs `install.sh`, which points the mirrorlist at the dated Arch Linux Archive snapshot of the same day and runs the ISO's archinstall unattended: archinstall's own default layout for one btrfs disk (a 1 GiB ESP at `/boot`, the `@`, `@home`, `@log` and `@pkg` subvolumes, `compress=zstd`), systemd-boot with loader entries, zram, the minimal profile, the network setup of the ISO, a user `arch` (password `arch`, in `wheel`) and no root password. Then it adds `console=ttyS0` to the loader entries for the serial line the test driver reads, empties the package cache and checks the layout. It boots the result once more under UEFI with no saved boot entries, as the harness does, and fails unless the login prompt appears on the serial line. The compressed qcow2, its `.sha256` and its `.json` manifest (the hash in the SRI form `images.json` takes, the inputs and every installed package) are the `arch-install-image` artifact, and the serial logs and archinstall's log the `arch-install-logs` artifact. The image is rebuilt from the same inputs every night, but not bit for bit: the file system UUIDs, the keyring and the timestamps differ, so every build has a hash of its own. -- **Publish.** On the nightly schedule, which runs on `main`, and on a dispatch from any branch (unless its `publish` input is off), the `publish` job checks the artifact against the hash the build reported and uploads it to `images-arch-install`, creating the release when it is missing. Every build is named `arch-install---.qcow2`, so a nightly never replaces the asset that `images.json` pins; an asset of the same name, from a re-run of the same run, is replaced. It then replaces `arch-install-latest.json` with the new manifest and deletes the builds beyond the newest three that the `images.json` of `main`, of `next` and of the run's commit do not pin. No pull request or push publishes: a pull request into `main` or `next`, or a push to any other branch, that changes the builder or the workflow runs the build alone. That push run is also what lets the branch be dispatched: GitHub dispatches a workflow file that is not on the default branch only after it has run once. +- **Publish.** On the nightly schedule, which runs on `main`, and on a dispatch from any branch (unless its `publish` input is off), the `publish` job checks the artifact against the hash the build reported and uploads it to `images-arch-install`, creating the release when it is missing. Every build is named `arch-install----.qcow2`, so a nightly never replaces the asset that `images.json` pins. It then replaces `arch-install-latest.json` with the new manifest and deletes the builds beyond the newest three that the `images.json` of `main`, of `next` and of the run's commit do not pin. It reads those three with the job's own read-only token. A branch that does not exist pins nothing, but when any other read fails it deletes no build, and it replaces an asset of the same name, which only a re-run of the publish job alone meets, only when every read succeeded and none of them pins it. No pull request or push publishes: a pull request into `main` or `next`, or a push to any other branch, that changes the builder or the workflow runs the build alone. That push run is also what lets the branch be dispatched: GitHub dispatches a workflow file that is not on the default branch only after it has run once. - **Verify.** The `verify` job downloads the asset from its public URL and fails unless its SHA-256 is the build's and `arch-install-latest.json` names it. Its summary shows the `asset` and `sha256` to pin. - **Pinning.** `images.json` pins one build by its `asset` and `sha256` (`python3 -m ci.distro_images repin arch-install` takes the newest), so a test fetches exactly that file and Nix checks its hash. Its `firmware` is `uefi`, so `nix/distro-tests/lib/distro-vm.nix` boots it with OVMF on the q35 machine: under OVMF on QEMU's default i440fx machine, Linux finds no drive on the IDE controller. The entry stays disabled until the Arch admission enables it; the probe and refusal suites of `distro-e2e.yml` boot it already. - **The token.** `NAILS_TEST_IMAGES_TOKEN` is a fine-grained token with Contents read and write on the assets repository alone. Only the upload step of the `publish` job reads it, a job that runs no code of the build and no pull request ever starts. From 6426d057f9a30f6bb401fa376418a91df2885d9a Mon Sep 17 00:00:00 2001 From: WitteShadovv Date: Wed, 25 Nov 2026 13:48:48 +0100 Subject: [PATCH 11/13] ci(oracle): name the download-artifact pin by its tag v8.0.2 The commit the oracle nightly pins actions/download-artifact to is the tag v8.0.2; its comments said v6.0.0. --- .github/workflows/oracle-real-nightly.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/oracle-real-nightly.yml b/.github/workflows/oracle-real-nightly.yml index e98ead47c..2d1c30c99 100644 --- a/.github/workflows/oracle-real-nightly.yml +++ b/.github/workflows/oracle-real-nightly.yml @@ -176,7 +176,7 @@ jobs: run: cargo build --release --locked -p nails-oracle - name: Download the raws - uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v6.0.0 + uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2 with: name: oracle-real-raws @@ -449,7 +449,7 @@ jobs: run: cargo build --release --locked -p nails-oracle - name: Download the raws - uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v6.0.0 + uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2 with: name: oracle-real-btrfs-raws-${{ matrix.image }} @@ -617,7 +617,7 @@ jobs: persist-credentials: false - name: Download the raws - uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v6.0.0 + uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2 with: name: oracle-real-btrfs-raws-${{ matrix.image }} From 7b3e2ab9024010362425b2889f7439b4b4b2e628 Mon Sep 17 00:00:00 2001 From: WitteShadovv Date: Wed, 25 Nov 2026 13:48:56 +0100 Subject: [PATCH 12/13] fix(ci): report a firmware value that is no string as a finding A firmware value that is no string, such as a list, made the image table check raise a TypeError instead of naming the entry. It is now a finding like an unknown name: firmware must be "bios" or "uefi". --- ci/distro_images.py | 4 ++-- ci/tests/test_distro_images.py | 9 ++++++++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/ci/distro_images.py b/ci/distro_images.py index 13bf138fc..2676a41eb 100644 --- a/ci/distro_images.py +++ b/ci/distro_images.py @@ -191,8 +191,8 @@ def _problems_for_entry(name: str, entry: object) -> list[str]: except ValueError: out.append(f"{name}: upstreamUntil must be null or YYYY-MM-DD") firmware = entry.get("firmware", "bios") - if firmware not in KNOWN_FIRMWARE: - out.append(f"{name}: unknown firmware {firmware!r}") + if not isinstance(firmware, str) or firmware not in KNOWN_FIRMWARE: + out.append(f"{name}: firmware must be \"bios\" or \"uefi\", not {firmware!r}") out.extend(_source_problems(name, entry, entry["source"])) out.extend(_known_failed_problems(name, entry.get("knownFailedUnits"))) return out diff --git a/ci/tests/test_distro_images.py b/ci/tests/test_distro_images.py index 9f0d0f89e..aa93adf63 100644 --- a/ci/tests/test_distro_images.py +++ b/ci/tests/test_distro_images.py @@ -110,7 +110,14 @@ def test_firmware_is_bios_or_uefi(self) -> None: self.assertEqual(di.validate({"x": upstream_entry(firmware="uefi")}), []) self.assertEqual(di.validate({"x": upstream_entry(firmware="bios")}), []) problems = di.validate({"x": upstream_entry(firmware="coreboot")}) - self.assertEqual(problems, ["x: unknown firmware 'coreboot'"]) + self.assertEqual( + problems, ['x: firmware must be "bios" or "uefi", not \'coreboot\''] + ) + # A value that is no string is a finding too, not a TypeError. + problems = di.validate({"x": upstream_entry(firmware=["uefi"])}) + self.assertEqual( + problems, ['x: firmware must be "bios" or "uefi", not [\'uefi\']'] + ) def test_a_pinned_and_an_unpinned_mirror_entry_are_well_formed(self) -> None: self.assertEqual(di.validate({"a": mirror_entry()}), []) From b2943cf2a822cb474c854ab39bce36388708292b Mon Sep 17 00:00:00 2001 From: WitteShadovv Date: Wed, 25 Nov 2026 14:40:48 +0100 Subject: [PATCH 13/13] fix(test-images): read the pins of any table shape and refuse an empty one The publish job counted a read of images.json as complete whenever jq exited 0, and jq does that for an empty body, {} or a table of another shape, which pins nothing in the old filter. A reshaped table on main or next could then let the prune or a replace hit a build that branch pins. Now every string in the table that names one of the family's builds counts as a pin, wherever it stands, and an empty body or anything but a non-empty object leaves the list incomplete, so nothing is pruned or replaced. Also say exactly when an unpinned mirror entry names that in its line, and that a branch that does not exist pins nothing. --- .github/workflows/test-images.yml | 14 ++++++++++---- ci/distro_images.py | 7 ++++--- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/.github/workflows/test-images.yml b/.github/workflows/test-images.yml index 1b9040891..64a9f41db 100644 --- a/.github/workflows/test-images.yml +++ b/.github/workflows/test-images.yml @@ -16,8 +16,8 @@ name: Test images # manifest, and deletes the older builds beyond the newest three # that no images.json of main, next or this commit pins. It # deletes nothing, and replaces no asset of the same name, unless -# it could read all three images.json, and it never replaces a -# pinned asset +# it read the images.json of all three (a branch that does not +# exist pins nothing), and it never replaces a pinned asset # verify downloads the asset from its public URL and checks its SHA-256 # # Every build gets a name of its own (the ISO version, the UTC date, the run @@ -223,8 +223,14 @@ jobs: for ref in main next "$SHA"; do if table=$(gh api -H "Accept: application/vnd.github.raw+json" \ "repos/$REPOSITORY/contents/nix/distro-tests/images.json?ref=$ref" 2> "$RUNNER_TEMP/read-error"); then - if ! jq -r --arg family "$FAMILY" \ - '.[] | .source | select(.kind == "mirror" and .family == $family and .asset != null) | .asset' \ + # Every string in the table that names one of this family's + # builds counts as a pin, wherever it stands, so a table of + # another shape keeps more, never less. Anything but a non-empty + # object is no table this step can trust. + if [ -z "$table" ] || ! jq -r --arg family "$FAMILY" \ + 'if type == "object" and length > 0 + then .. | strings | select(startswith($family + "-") and endswith(".qcow2")) + else error("not a table") end' \ <<< "$table" >> "$pinned"; then complete=no echo "::warning::images.json of $ref is not the table this step reads." diff --git a/ci/distro_images.py b/ci/distro_images.py index 2676a41eb..26548d4e6 100644 --- a/ci/distro_images.py +++ b/ci/distro_images.py @@ -459,9 +459,10 @@ def link_check( ``BUILDER_INPUTS``) are probed too, the installer ISO and the package snapshot, since the nightly rebuild fails once either is gone; that happens before its first asset is pinned as well. An entry that pins no - asset yet, or a mirror with no base, names that in its line: among the - checked entries when its build inputs were probed, and among the - unchecked ones otherwise. A + asset yet, or a mirror with no base, names that in its line when its + build inputs were probed and could be read, and is among the unchecked + ones when nothing of it was probed; where a probe failed, the entry is + among the checked ones and the run fails. A run that could check no enabled entry fails as well: a pass would claim a check of the images CI boots that never happened, whatever it found for the staged ones.