diff --git a/.github/workflows/test-virgin-root.yml b/.github/workflows/test-virgin-root.yml index c856d5f..121eb6a 100644 --- a/.github/workflows/test-virgin-root.yml +++ b/.github/workflows/test-virgin-root.yml @@ -46,8 +46,6 @@ jobs: . "$HOME/.venvs/pkgmgr/bin/activate" - export NIX_CONFIG="experimental-features = nix-command flakes" - pkgmgr update pkgmgr --clone-mode shallow --no-verification pkgmgr version pkgmgr diff --git a/.github/workflows/test-virgin-user.yml b/.github/workflows/test-virgin-user.yml index 8887938..0ec7366 100644 --- a/.github/workflows/test-virgin-user.yml +++ b/.github/workflows/test-virgin-user.yml @@ -59,7 +59,6 @@ jobs: pkgmgr version pkgmgr export NIX_REMOTE=local - export NIX_CONFIG=\"experimental-features = nix-command flakes\" nix run /src#pkgmgr -- version pkgmgr " ' diff --git a/Dockerfile b/Dockerfile index c51af7b..6f14706 100644 --- a/Dockerfile +++ b/Dockerfile @@ -36,9 +36,6 @@ CMD ["bash"] # ============================================================ FROM virgin AS full -# Nix environment defaults (only config; nix itself comes from deps/install flow) -ENV NIX_CONFIG="experimental-features = nix-command flakes" - WORKDIR /build # Copy full repository for build diff --git a/packaging/arch/PKGBUILD b/packaging/arch/PKGBUILD index 887eb3b..d50a2a9 100644 --- a/packaging/arch/PKGBUILD +++ b/packaging/arch/PKGBUILD @@ -47,7 +47,7 @@ package() { cd "$srcdir/$_srcdir_name" # Install the wrapper into /usr/bin - install -Dm0755 "scripts/pkgmgr-wrapper.sh" \ + install -Dm0755 "scripts/launcher.sh" \ "$pkgdir/usr/bin/pkgmgr" # Install Nix bootstrap (init + lib) diff --git a/packaging/debian/rules b/packaging/debian/rules index 18b36c2..bdf4bf7 100755 --- a/packaging/debian/rules +++ b/packaging/debian/rules @@ -28,7 +28,7 @@ override_dh_auto_install: install -d debian/package-manager/usr/lib/package-manager # Install wrapper - install -m0755 scripts/pkgmgr-wrapper.sh \ + install -m0755 scripts/launcher.sh \ debian/package-manager/usr/bin/pkgmgr # Install Nix bootstrap (init + lib) diff --git a/packaging/fedora/package-manager.spec b/packaging/fedora/package-manager.spec index a07f3cd..56fabfe 100644 --- a/packaging/fedora/package-manager.spec +++ b/packaging/fedora/package-manager.spec @@ -42,7 +42,7 @@ install -d %{buildroot}/usr/lib/package-manager cp -a . %{buildroot}/usr/lib/package-manager/ # Wrapper -install -m0755 scripts/pkgmgr-wrapper.sh %{buildroot}%{_bindir}/pkgmgr +install -m0755 scripts/launcher.sh %{buildroot}%{_bindir}/pkgmgr # Nix bootstrap (init + lib) install -d %{buildroot}/usr/lib/package-manager/nix diff --git a/scripts/pkgmgr-wrapper.sh b/scripts/launcher.sh similarity index 80% rename from scripts/pkgmgr-wrapper.sh rename to scripts/launcher.sh index 9cf0eaf..2d5752a 100755 --- a/scripts/pkgmgr-wrapper.sh +++ b/scripts/launcher.sh @@ -1,11 +1,6 @@ #!/usr/bin/env bash set -euo pipefail -# Ensure NIX_CONFIG has our defaults if not already set -if [[ -z "${NIX_CONFIG:-}" ]]; then - export NIX_CONFIG="experimental-features = nix-command flakes" -fi - FLAKE_DIR="/usr/lib/package-manager" # --------------------------------------------------------------------------- @@ -43,6 +38,6 @@ 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 after init." -echo "[pkgmgr-wrapper] Nix is required to run pkgmgr (no Python fallback)." +echo "[launcher] ERROR: 'nix' binary not found on PATH after init." +echo "[launcher] Nix is required to run pkgmgr (no Python fallback)." exit 1 diff --git a/scripts/nix/lib/nix_conf_file.sh b/scripts/nix/lib/nix_conf_file.sh index 3e94b24..1eed630 100644 --- a/scripts/nix/lib/nix_conf_file.sh +++ b/scripts/nix/lib/nix_conf_file.sh @@ -11,45 +11,79 @@ nixconf_file_path() { echo "/etc/nix/nix.conf" } -nixconf_ensure_experimental_features() { - local nix_conf want - nix_conf="$(nixconf_file_path)" - want="experimental-features = nix-command flakes" +# Ensure a given nix.conf key contains required tokens (merged, no duplicates) +nixconf_ensure_features_key() { + local nix_conf="$1" + local key="$2" + shift 2 + local required=("$@") mkdir -p /etc/nix + # Create file if missing (with just the required tokens) if [[ ! -f "${nix_conf}" ]]; then + local want="${key} = ${required[*]}" echo "[nix-conf] Creating ${nix_conf} with: ${want}" printf "%s\n" "${want}" >"${nix_conf}" return 0 fi - if grep -qE '^\s*experimental-features\s*=' "${nix_conf}"; then - if grep -qE '^\s*experimental-features\s*=.*\bnix-command\b' "${nix_conf}" \ - && grep -qE '^\s*experimental-features\s*=.*\bflakes\b' "${nix_conf}"; then - echo "[nix-conf] experimental-features already correct" + # Key exists -> merge tokens + if grep -qE "^\s*${key}\s*=" "${nix_conf}"; then + local ok=1 + local t + for t in "${required[@]}"; do + if ! grep -qE "^\s*${key}\s*=.*\b${t}\b" "${nix_conf}"; then + ok=0 + break + fi + done + + if [[ "$ok" -eq 1 ]]; then + echo "[nix-conf] ${key} already correct" return 0 fi - echo "[nix-conf] Extending experimental-features in ${nix_conf}" + echo "[nix-conf] Extending ${key} in ${nix_conf}" local current - current="$(grep -E '^\s*experimental-features\s*=' "${nix_conf}" | head -n1 | cut -d= -f2-)" + current="$(grep -E "^\s*${key}\s*=" "${nix_conf}" | head -n1 | cut -d= -f2-)" current="$(echo "${current}" | xargs)" # trim - # Build a merged feature string without duplicates (simple token set) - local merged="nix-command flakes" + local merged="" local token + + # Start with existing tokens for token in ${current}; do if [[ " ${merged} " != *" ${token} "* ]]; then merged="${merged} ${token}" fi done - sed -i "s|^\s*experimental-features\s*=.*|experimental-features = ${merged}|" "${nix_conf}" + # Add required tokens + for token in "${required[@]}"; do + if [[ " ${merged} " != *" ${token} "* ]]; then + merged="${merged} ${token}" + fi + done + + merged="$(echo "${merged}" | xargs)" # trim + + sed -i "s|^\s*${key}\s*=.*|${key} = ${merged}|" "${nix_conf}" return 0 fi + # Key missing -> append + local want="${key} = ${required[*]}" echo "[nix-conf] Appending to ${nix_conf}: ${want}" printf "\n%s\n" "${want}" >>"${nix_conf}" } + +nixconf_ensure_experimental_features() { + local nix_conf + nix_conf="$(nixconf_file_path)" + + # Ensure both keys to avoid prompts and cover older/alternate expectations + nixconf_ensure_features_key "${nix_conf}" "experimental-features" "nix-command" "flakes" + nixconf_ensure_features_key "${nix_conf}" "extra-experimental-features" "nix-command" "flakes" +}