From 4b1eba8ac0da4407b002e2172ada9ebac696dd37 Mon Sep 17 00:00:00 2001 From: Lior Date: Wed, 27 May 2026 15:41:37 -0400 Subject: [PATCH] =?UTF-8?q?feat(b-0857.2):=20install.sh=20NixOS-aware=20ro?= =?UTF-8?q?uting=20=E2=80=94=20full=20state=20with=203=20Copilot=20finding?= =?UTF-8?q?s=20addressed=20(supersedes=20PR=20#5606=20=E2=80=94=20clean=20?= =?UTF-8?q?fresh=20branch=20off=20origin/main,=20no=20force-push)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Supersedes PR #5606 (which had 3 valid Copilot findings + 1 false- positive that I addressed in a fix-fwd commit; that commit would have required force-push to PR #5606's branch which is policy- restricted per the autonomous-loop force-push discipline; opening a fresh PR off origin/main is the policy-respected new-branch path). PR #5606 to be closed with cross-reference to this PR after this opens. Full B-0857.2 substrate-engineering content (originally drafted across 3 commits on PR #5606 branch; squashed here for clean review): ROUTING MATRIX: - macOS (uname -s = Darwin) -> setup/macos.sh - Linux non-NixOS (no /etc/NIXOS) -> setup/linux.sh - NixOS installed (/etc/NIXOS, no docker, no /iso, no /run/initramfs) -> setup/linux.sh - NixOS docker test harness (/etc/NIXOS + /.dockerenv from B-0849 harness) -> setup/linux.sh - NixOS live-USB (/etc/NIXOS + /iso OR /run/initramfs canonical markers) -> exit 2 + message pointing to zeta-install.sh DISCRIMINATOR PRIORITY: 1. /etc/NIXOS marker -> NixOS (else linux-non-nixos) 2. /.dockerenv -> installed (Docker container short-circuit; runs FIRST so subsequent overlay check doesn't false-positive on B-0849 harness) 3. /iso present OR /run/initramfs present -> live-USB (canonical NixOS-installer-ISO markers) 4. Otherwise -> installed (safer default) COPILOT FINDINGS ADDRESSED (from PR #5606 review): Finding 1 (P1, line 16 exit contract): Was: "Exit 0 on success. Any failure is a dev-experience bug" Fixed: expanded exit-code documentation to 3 codes (0 success; 1 error; 2 intentional routing guard for NixOS live-USB — NOT a dev-experience bug). Clarified CI gate.yml asserts exit 0 in its tested environments (none are NixOS live-USB). Finding 2 (P1, line 36 name attribution): Was: "Per B-0857 operator framing (Aaron 2026-05-27):" Fixed: "Per B-0857 operator framing (2026-05-27):" — per name- attribution convention (no first names in non-history-surface source files). Finding 3 (P1, line 111 relative path): Was: "sudo bash full-ai-cluster/usb-nixos-installer/zeta-install.sh" (relative; fails if user not in repo root) Fixed: resolves $REPO_ROOT-rooted absolute path before printing the message; also resolves $INJECTION_POINTS_ABS absolute path; both paths now work regardless of caller cwd. Also references the exit-code documentation in the script header for exit 2 case. Finding 4 (P0, line 114 dead link) — FALSE POSITIVE: Copilot flagged "full-ai-cluster/INJECTION-POINTS.md does not exist in the repo" but the file DID land on origin/main at 976b3521a (PR #5601, merged before PR #5606 CI ran). Verified via `git ls-tree origin/main full-ai-cluster/INJECTION-POINTS.md`. Copilot's review-base was earlier than current main. Will resolve PR #5606 thread as no-op confirmed-on-main when closing. LOCAL VALIDATION: - bash -n syntax PASS - bash tools/setup/install.sh on Darwin: routes to setup/macos.sh - bun tools/ci/docker-nixos-install-sh-test.ts: SUCCESS in 108s (B-0849 docker harness validates the /.dockerenv discriminator-2 short-circuit preserves existing harness behavior) PER OPERATOR DIRECTIVE 2026-05-27: "and again dont feel any rush this is critical we get this usb right not fast fast comes after our self healing usb is stable" + "we pay the time now while things are simple to avoid sprawling complexity later" + "we can test nixos install in quick iteration locally with docker" This PR follows all three directives: substrate-engineering-correctness- first; one sub-row scope; docker-harness-validated locally before push. Co-Authored-By: Claude --- tools/setup/install.sh | 137 +++++++++++++++++++++++++++++++++++++++-- 1 file changed, 131 insertions(+), 6 deletions(-) diff --git a/tools/setup/install.sh b/tools/setup/install.sh index e23d17ef32..649d33aeb7 100755 --- a/tools/setup/install.sh +++ b/tools/setup/install.sh @@ -1,7 +1,8 @@ #!/usr/bin/env bash # # tools/setup/install.sh — the one install script consumed three ways -# (dev laptops, CI runners, devcontainer images) per GOVERNANCE.md §24. +# (dev laptops, CI runners, devcontainer images) per GOVERNANCE.md §24, +# plus iter-B-0857.2: NixOS-aware routing for cluster nodes. # # Safe to run repeatedly — detect-first-install-else-update. Safe to # run daily to keep tools fresh. @@ -9,17 +10,88 @@ # Usage: # tools/setup/install.sh # -# Exit 0 on success. Any failure is a dev-experience bug; the CI -# `gate.yml` workflow asserts this script completes twice in sequence. +# Exit codes: +# 0 — success (install/runtime-setup completed on a routable environment) +# 1 — error (unsupported OS, unrecognized Linux flavor, or downstream +# failure from setup/macos.sh or setup/linux.sh) +# 2 — intentional routing guard (NixOS live-USB environment detected; +# script directs operator to zeta-install.sh — this is NOT a +# dev-experience bug, it's the live-USB-vs-installed routing per +# B-0857.2 below) +# +# The CI `gate.yml` workflow asserts this script completes with exit 0 +# twice in sequence in its tested environments (none of which are NixOS +# live-USB), so exit 2 from the live-USB branch does NOT affect CI gate +# assertions. +# +# B-0857.2 routing (added 2026-05-27): +# - macOS (uname -s = Darwin) -> setup/macos.sh +# - Linux non-NixOS (no /etc/NIXOS) -> setup/linux.sh +# - NixOS installed (/etc/NIXOS, -> setup/linux.sh +# not docker, no /iso, no (NixOS-installed nodes get the same +# /run/initramfs) mise + bun + claude runtime setup +# as any Linux build machine; nixos- +# rebuild handles the NixOS-side +# declarative config) +# - NixOS docker test harness (/etc/NIXOS -> setup/linux.sh (treated as installed; +# + /.dockerenv from B-0849 docker discriminator-2 short-circuit) +# test harness) +# - NixOS live-USB (/etc/NIXOS + /iso OR -> message pointing to zeta-install.sh +# /run/initramfs canonical installer- (B-0857.3 will factor that body into +# ISO markers) a callable nixos-install-from-usb.sh; +# this routing stub lands first) +# +# Per B-0857 operator framing (2026-05-27): install.sh is the universal +# Unix-like-OS install + self-update entry — "there is no distinction +# between build machines and prod when prod can update itself." This +# row's substrate scope is environment-routing dispatch. set -euo pipefail REPO_ROOT="$(cd "$(dirname "$0")/../.." && pwd)" SETUP_DIR="$REPO_ROOT/tools/setup" -echo "=== Zeta install — three-way parity script (GOVERNANCE.md §24) ===" +echo "=== Zeta install — universal Unix-like-OS entry (GOVERNANCE.md §24 + B-0857.2) ===" echo "Repo root: $REPO_ROOT" +# Detect-NixOS-and-mode helper (B-0857.2). +# +# Outputs one of: "nixos-live", "nixos-installed", "linux-non-nixos". +# Caller decides routing. +# +# Discriminator priority (per B-0849 docker-test-harness composition): +# 1. /etc/NIXOS marker → NixOS (else linux-non-nixos) +# 2. /.dockerenv → installed (Docker container, e.g., the B-0849 +# docker-nixos-install-sh-test harness, which manually creates +# /etc/NIXOS to exercise the NixOS userspace path; Docker uses +# overlayfs at root which would false-positive on the live-USB +# check, so the docker discriminator runs FIRST) +# 3. /iso present OR /run/initramfs present → live-USB (the canonical +# NixOS-installer-ISO markers; these are what zeta-install.sh +# itself probes for in its boot-USB detection logic) +# 4. Otherwise → installed (safer default; overlayfs-without-iso is +# more likely an unusual installed config than a live boot) +detect_linux_flavor() { + if [ ! -f /etc/NIXOS ]; then + echo "linux-non-nixos" + return 0 + fi + # Discriminator 2: Docker container short-circuits to installed + # (the B-0849 harness creates /etc/NIXOS manually but is not a + # live USB; its overlayfs root would otherwise false-positive). + if [ -f /.dockerenv ]; then + echo "nixos-installed" + return 0 + fi + # Discriminator 3: canonical NixOS-installer-ISO markers. + if [ -d /iso ] || [ -d /run/initramfs ]; then + echo "nixos-live" + return 0 + fi + # Discriminator 4 (default): installed. + echo "nixos-installed" +} + os="$(uname -s)" case "$os" in Darwin) @@ -27,8 +99,61 @@ case "$os" in "$SETUP_DIR/macos.sh" ;; Linux) - echo "OS: Linux" - "$SETUP_DIR/linux.sh" + flavor="$(detect_linux_flavor)" + case "$flavor" in + linux-non-nixos) + echo "OS: Linux (non-NixOS)" + "$SETUP_DIR/linux.sh" + ;; + nixos-installed) + echo "OS: NixOS (installed; runtime setup via mise + bun + claude)" + echo "Note: NixOS-side declarative config managed via nixos-rebuild;" + echo " this step only sets up the operator runtime tooling." + "$SETUP_DIR/linux.sh" + ;; + nixos-live) + # Resolve the absolute path to zeta-install.sh so the message + # works regardless of caller's cwd. install.sh is callable + # from any working directory (e.g., on a fresh live-USB boot + # the operator may invoke this via a symlink / absolute path / + # bash <(...) — relative path would fail in those cases). + ZETA_INSTALL_ABS="$REPO_ROOT/full-ai-cluster/usb-nixos-installer/zeta-install.sh" + INJECTION_POINTS_ABS="$REPO_ROOT/full-ai-cluster/INJECTION-POINTS.md" + cat >&2 <&2 + exit 1 + ;; + esac ;; *) echo "error: unsupported OS '$os' (macOS + Linux only this round; Windows backlogged)"