diff --git a/README.md b/README.md index f0b656a..73fe317 100644 --- a/README.md +++ b/README.md @@ -59,6 +59,21 @@ The wrapper uses Nix profiles underneath, so direct Nix commands still work: nix profile install nixpkgs#hello ``` +If `forgeos-app` says `nix is unavailable`, check whether the app layer mounted: + +```bash +forgeos-app status +lsblk -f +``` + +On an installed system with a `FORGE_APPS` partition, recover the current boot as root: + +```bash +mount LABEL=FORGE_APPS /forge +mount -a +systemctl restart forgeos-nix-bootstrap.service nix-daemon.socket nix-daemon.service +``` + To build a UEFI disk image: ```bash diff --git a/docs/INSTALLER.md b/docs/INSTALLER.md index 97d7fb8..2dfac7a 100644 --- a/docs/INSTALLER.md +++ b/docs/INSTALLER.md @@ -87,6 +87,23 @@ Enroll `out/secure-boot/ForgeOS.cer` in the target firmware Secure Boot database - Avoid leaving multiple ForgeOS installations attached during early testing, because multiple disks with the same GPT partition label can confuse root selection. - Secure Boot trust is tied to the enrolled signing certificate. Protect the generated private key. +## App Layer Recovery + +If an installed machine reports `nix is unavailable; is the ForgeOS app layer mounted?`, confirm the app partition exists and is mounted: + +```bash +forgeos-app status +lsblk -f +``` + +If `FORGE_APPS` exists but `/forge` or `/nix` is not mounted, recover the current boot as root: + +```bash +mount LABEL=FORGE_APPS /forge +mount -a +systemctl restart forgeos-nix-bootstrap.service nix-daemon.socket nix-daemon.service +``` + ## Current Limitation This is a host-side installer, not an in-OS guided installer yet. There is no partitioning UI, user setup wizard, or live environment workflow in this version. diff --git a/overlay/rootfs/usr/bin/forgeos-app b/overlay/rootfs/usr/bin/forgeos-app index 87e6200..2e8e3aa 100644 --- a/overlay/rootfs/usr/bin/forgeos-app +++ b/overlay/rootfs/usr/bin/forgeos-app @@ -22,13 +22,6 @@ Short names are expanded to nixpkgs#NAME for install and shell. EOF } -need_nix() { - command -v nix >/dev/null 2>&1 || { - echo "nix is unavailable; is the ForgeOS app layer mounted?" >&2 - exit 1 - } -} - as_installable() { case "$1" in *#*|/*|git+*|http://*|https://*) @@ -54,6 +47,51 @@ show_mount() { ' /proc/mounts } +find_nix() { + if command -v nix >/dev/null 2>&1; then + command -v nix + return 0 + fi + + if [ -x /nix/var/nix/profiles/default/bin/nix ]; then + printf '%s\n' /nix/var/nix/profiles/default/bin/nix + return 0 + fi + + for candidate in /nix/store/*-nix-*/bin/nix; do + [ -x "$candidate" ] || continue + printf '%s\n' "$candidate" + return 0 + done + + return 1 +} + +diagnose_missing_nix() { + echo "nix is unavailable; is the ForgeOS app layer mounted?" >&2 + show_mount /forge >&2 + show_mount /nix >&2 + echo "check: lsblk -f" >&2 + echo "check: systemctl status forge.mount forgeos-nix-bootstrap.service nix-daemon.service nix-daemon.socket" >&2 + echo "repair as root: mount LABEL=FORGE_APPS /forge && mount -a && systemctl restart forgeos-nix-bootstrap.service nix-daemon.socket nix-daemon.service" >&2 +} + +need_nix() { + if NIX_BIN=$(find_nix); then + export NIX_BIN + export NIX_REMOTE=${NIX_REMOTE:-daemon} + return 0 + fi + + diagnose_missing_nix + exit 1 +} + +run_nix() { + need_nix + "$NIX_BIN" "$@" +} + cmd=${1:-} if [ -z "$cmd" ]; then usage @@ -78,9 +116,8 @@ case "$cmd" in usage >&2 exit 2 } - need_nix for item in "$@"; do - nix profile install "$(as_installable "$item")" + run_nix profile install "$(as_installable "$item")" done ;; remove) @@ -88,32 +125,27 @@ case "$cmd" in usage >&2 exit 2 } - need_nix - nix profile remove "$@" + run_nix profile remove "$@" ;; list) - need_nix - nix profile list + run_nix profile list ;; search) [ "$#" -gt 0 ] || { usage >&2 exit 2 } - need_nix - nix search nixpkgs "$@" + run_nix search nixpkgs "$@" ;; upgrade) - need_nix if [ "$#" -eq 0 ]; then - nix profile upgrade '.*' + run_nix profile upgrade '.*' else - nix profile upgrade "$@" + run_nix profile upgrade "$@" fi ;; rollback) - need_nix - nix profile rollback + run_nix profile rollback ;; shell) [ "$#" -gt 0 ] || { @@ -126,12 +158,12 @@ case "$cmd" in for item in "$@"; do expanded="${expanded}${expanded:+ }$(as_installable "$item")" done + need_nix # shellcheck disable=SC2086 - exec nix shell $expanded + exec "$NIX_BIN" shell $expanded ;; gc) - need_nix - nix store gc + run_nix store gc ;; help|--help|-h) usage diff --git a/scripts/build-image.sh b/scripts/build-image.sh index b563cb8..61eea77 100755 --- a/scripts/build-image.sh +++ b/scripts/build-image.sh @@ -129,13 +129,13 @@ write_atomic_fstab() { cat > "$BASE_ROOTFS_STAGING_DIR/etc/fstab" <