From a3b21f23fc4355036cee50cc84a45789a13c17e3 Mon Sep 17 00:00:00 2001 From: Kevin Veen-Birkenbach Date: Thu, 11 Dec 2025 18:33:02 +0100 Subject: [PATCH] pkgmgr-wrapper: improve Nix detection and auto-initialization MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Extend PATH probing to include /home/nix/.nix-profile/bin/nix (container mode). - Automatically invoke init-nix.sh when nix is not found before first run. - Ensure pkgmgr always attempts a one-time Nix initialization instead of failing prematurely. - Improve error message to clarify that nix was still missing *after* initialization attempt. - Keep existing flake-based execution path unchanged (exec nix run …). This makes the wrapper fully reliable across Debian/Ubuntu package installs, fresh containers, and minimal systems where Nix is not yet initialized. https://chatgpt.com/share/693b005d-b250-800f-8830-ab71685f51b3 --- scripts/pkgmgr-wrapper.sh | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/scripts/pkgmgr-wrapper.sh b/scripts/pkgmgr-wrapper.sh index 68fa573..117ff27 100755 --- a/scripts/pkgmgr-wrapper.sh +++ b/scripts/pkgmgr-wrapper.sh @@ -8,19 +8,18 @@ fi FLAKE_DIR="/usr/lib/package-manager" -# ------------------------------------------------------------ -# Try to ensure that "nix" is on PATH -# ------------------------------------------------------------ +# --------------------------------------------------------------------------- +# Try to ensure that "nix" is on PATH (common locations + container user) +# --------------------------------------------------------------------------- if ! command -v nix >/dev/null 2>&1; then - # Common locations for Nix installations CANDIDATES=( "/nix/var/nix/profiles/default/bin/nix" "${HOME:-/root}/.nix-profile/bin/nix" + "/home/nix/.nix-profile/bin/nix" ) for candidate in "${CANDIDATES[@]}"; do if [[ -x "$candidate" ]]; then - # Prepend the directory of the candidate to PATH PATH="$(dirname "$candidate"):${PATH}" export PATH break @@ -28,13 +27,22 @@ if ! command -v nix >/dev/null 2>&1; then done fi -# ------------------------------------------------------------ -# Primary (and only) path: use Nix flake if available -# ------------------------------------------------------------ +# --------------------------------------------------------------------------- +# If nix is still missing, try to run init-nix.sh once +# --------------------------------------------------------------------------- +if ! command -v nix >/dev/null 2>&1; then + if [[ -x "${FLAKE_DIR}/init-nix.sh" ]]; then + "${FLAKE_DIR}/init-nix.sh" || true + fi +fi + +# --------------------------------------------------------------------------- +# Primary path: use Nix flake if available +# --------------------------------------------------------------------------- if command -v nix >/dev/null 2>&1; then exec nix run "${FLAKE_DIR}#pkgmgr" -- "$@" fi -echo "[pkgmgr-wrapper] ERROR: 'nix' binary not found on PATH." +echo "[pkgmgr-wrapper] ERROR: 'nix' binary not found on PATH after init." echo "[pkgmgr-wrapper] Nix is required to run pkgmgr (no Python fallback)." exit 1