#!/usr/bin/env sh # G-01/G-02/G-03 generations validation, run inside the VM. Creates distinct # system generations by changing the config between applies (a tiny /etc file via # an imported module), then exercises history/current/back/go/clean. Prints # nina's output beside ground-truth system-profile state for host-side judging. set -u N=/root/nina sysgens() { nix-env -p /nix/var/nix/profiles/system --list-generations 2>/dev/null | wc -l | tr -d ' '; } syscur() { readlink /nix/var/nix/profiles/system | sed -n 's/.*system-\([0-9][0-9]*\)-link/\1/p'; } mkgen() { printf '{ ... }: { environment.etc."nina-gen".text = "%s"; }\n' "$1" > /etc/nixos/genmarker.nix; } echo "KILN_GEN_TEST_BEGIN" # Import a marker module so each content change yields a new system generation. sed -i 's| ./hardware-configuration.nix | ./hardware-configuration.nix ./genmarker.nix |' /etc/nixos/configuration.nix echo "imports now: $(grep -o 'imports = .*];' /etc/nixos/configuration.nix)" echo "GROUND before: sysgens=$(sysgens) syscur=$(syscur)" echo "### G-01 apply x3 with config changes (expect generations to increment)" mkgen A; $N apply; echo "APPLY_A_RC=$?"; echo "GROUND: sysgens=$(sysgens) syscur=$(syscur)" mkgen B; $N apply; echo "APPLY_B_RC=$?"; echo "GROUND: sysgens=$(sysgens) syscur=$(syscur)" mkgen C; $N apply; echo "APPLY_C_RC=$?"; echo "GROUND: sysgens=$(sysgens) syscur=$(syscur)" echo "### T-015 nina history (expect all system generations, current marked)" $N history; echo "HIST_RC=$?" echo "### T-017 nina gen current (expect = $(syscur))" $N gen current; echo "GENCUR_RC=$?" echo "### T-010 nina back (expect syscur decrements by 1)" $N back; echo "BACK_RC=$?"; echo "GROUND after back: syscur=$(syscur)" echo "### T-012 nina go (return forward)" NEWEST=$(nix-env -p /nix/var/nix/profiles/system --list-generations | awk '{print $1}' | sort -n | tail -1) $N go "$NEWEST"; echo "GO_RC=$?"; echo "GROUND after go $NEWEST: syscur=$(syscur)" echo "### T-030 nina clean (keep 5; expect exit 0, no duration error)" $N clean; echo "CLEAN_RC=$?"; echo "GROUND after clean: sysgens=$(sysgens)" echo "KILN_GEN_TEST_END"