Your browser sucks, JavaScript disabled! Gunnar's console needs JavaScript and WebAssembly. Git over SSH on port 2222 does not.

nordisk/holger

xtask/src/appliance_iso.rs

//! **`appliance-iso`** — holger's LIVE appliance medium, through the Build Thing.
//!
//! ```text
//! cargo xtask appliance-iso \
//!     [--variant holger-appliance-iso] [--build kernel] \
//!     --param site=stockholm-7 \
//!     --param holger_ron=@site7.ron
//! ```
//!
//! The `kind = "iso"` peer of [`crate::installer_iso`], and like it a thin caller
//! of `dwarves buildthing <this checkout> --variant <medium>`
//! ([`crate::forge_door`]). The payload is the row's `from_variant`
//! (`mvp-server-musl`, the installer's own static binary), built by the forge in
//! the pinned container; the kernel is the DECLARED donor `tunnr/tunnr-kernel`
//! (owner, 2026-09-27: "tunnr and 3 images just like gunnar"), read off its pin —
//! never an operator file, never the build box's `/boot`. Until that day this verb
//! composed in-process with `--kernel`; the declared donor retired that road.

use std::path::Path;

use anyhow::Result;
use nornir_build_thing::variant::ArtifactKind;

use crate::forge_door;

/// The variant built when the operator names none.
pub const DEFAULT_VARIANT: &str = "holger-appliance-iso";

/// Run the verb.
pub fn run() -> Result<()> {
    run_with(std::env::args().skip(2), &crate::workspace_root())
}

fn run_with(args: impl IntoIterator<Item = String>, repo_root: &Path) -> Result<()> {
    let ask = forge_door::parse("appliance-iso", args)?;
    let variant = ask
        .variant
        .clone()
        .unwrap_or_else(|| DEFAULT_VARIANT.to_string());
    let suite =
        forge_door::declared_medium(&variant, ArtifactKind::Iso, "cargo xtask installer-iso")?;
    forge_door::run("appliance-iso", repo_root, &suite, &variant, &ask).map(|_| ())
}

#[cfg(test)]
mod tests {
    use super::*;

    fn row() -> nornir_build_thing::iso::IsoBuild {
        holger_recipe::declared()
            .isos
            .into_iter()
            .find(|i| i.name == DEFAULT_VARIANT)
            .expect("the declared iso row")
    }

    /// The wrong kind is refused BY NAME, and when the name is an INSTALLER the
    /// refusal says which verb does build it. A machine with `shell = false` is
    /// entered through the medium or not at all.
    #[test]
    fn a_non_iso_variant_is_refused_and_the_installer_is_pointed_at_its_own_door() {
        forge_door::declared_medium(DEFAULT_VARIANT, ArtifactKind::Iso, "x").unwrap();
        let e = forge_door::declared_medium(
            "holger-installer",
            ArtifactKind::Iso,
            "cargo xtask installer-iso",
        )
        .unwrap_err()
        .to_string();
        assert!(
            e.contains("not 'iso'") && e.contains("cargo xtask installer-iso"),
            "{e}"
        );
        let e = forge_door::declared_medium("no-such", ArtifactKind::Iso, "x")
            .unwrap_err()
            .to_string();
        assert!(e.contains("no-such"), "{e}");
    }

    #[test]
    fn the_live_medium_boots_tunnrs_kernel() {
        let d = row().kernel_donor.expect("a declared donor");
        assert_eq!(
            (d.repo.as_str(), d.kernel.as_str()),
            ("tunnr", "tunnr-kernel")
        );
    }

    /// ★ THE PAYLOAD IS THE INSTALLER'S. One binary, two media — the thing that
    /// makes the live medium a PROOF of what the installer lays rather than a
    /// second product that happens to share a name.
    #[test]
    fn the_live_medium_and_the_installer_carry_one_payload() {
        let set = holger_recipe::declared();
        assert_eq!(
            row().from_variant.as_deref(),
            Some(set.installers[0].variant.as_str())
        );
    }

    /// The two measured re-image failures are answered on the INSTALLER rows — the
    /// media that write — with korp-installer's OWN cmdline keys, so a rename
    /// upstream is a compile error here and not a boot-time silence.
    #[test]
    fn the_installer_rows_declare_the_two_keys_the_estate_hands_them() {
        let set = holger_recipe::declared();
        for i in &set.installers {
            let by = |k: &str| i.params.iter().any(|p| p.boot_param == k);
            assert!(
                by(korp_installer::cmdline::DATA_DISKS_KEY),
                "{}: THE BOOT DISK IS THE LARGER ONE",
                i.name
            );
            assert!(
                by(korp_installer::cmdline::REINSTALL_KEY),
                "{}: RE-IMAGE AND RE-MINT GO TOGETHER",
                i.name
            );
        }
    }
}