refactor: move nix experimental feature setup to nix.conf and rename pkgmgr wrapper
Some checks failed
CI / test-unit (push) Has been cancelled
CI / test-integration (push) Has been cancelled
CI / test-env-virtual (push) Has been cancelled
CI / test-env-nix (push) Has been cancelled
CI / test-e2e (push) Has been cancelled
CI / test-virgin-user (push) Has been cancelled
CI / test-virgin-root (push) Has been cancelled
CI / codesniffer-shellcheck (push) Has been cancelled
CI / codesniffer-ruff (push) Has been cancelled
Mark stable commit / test-unit (push) Has been cancelled
Mark stable commit / test-integration (push) Has been cancelled
Mark stable commit / test-env-virtual (push) Has been cancelled
Mark stable commit / test-env-nix (push) Has been cancelled
Mark stable commit / test-e2e (push) Has been cancelled
Mark stable commit / test-virgin-user (push) Has been cancelled
Mark stable commit / test-virgin-root (push) Has been cancelled
Mark stable commit / codesniffer-shellcheck (push) Has been cancelled
Mark stable commit / codesniffer-ruff (push) Has been cancelled
Mark stable commit / mark-stable (push) Has been cancelled

https://chatgpt.com/share/693dcbad-3d30-800f-acfe-22f7263f3e80
This commit is contained in:
Kevin Veen-Birkenbach
2025-12-13 21:25:02 +01:00
parent 923519497a
commit 4cb62e90f8
8 changed files with 52 additions and 29 deletions

View File

@@ -46,8 +46,6 @@ jobs:
. "$HOME/.venvs/pkgmgr/bin/activate" . "$HOME/.venvs/pkgmgr/bin/activate"
export NIX_CONFIG="experimental-features = nix-command flakes"
pkgmgr update pkgmgr --clone-mode shallow --no-verification pkgmgr update pkgmgr --clone-mode shallow --no-verification
pkgmgr version pkgmgr pkgmgr version pkgmgr

View File

@@ -59,7 +59,6 @@ jobs:
pkgmgr version pkgmgr pkgmgr version pkgmgr
export NIX_REMOTE=local export NIX_REMOTE=local
export NIX_CONFIG=\"experimental-features = nix-command flakes\"
nix run /src#pkgmgr -- version pkgmgr nix run /src#pkgmgr -- version pkgmgr
" "
' '

View File

@@ -36,9 +36,6 @@ CMD ["bash"]
# ============================================================ # ============================================================
FROM virgin AS full 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 WORKDIR /build
# Copy full repository for build # Copy full repository for build

View File

@@ -47,7 +47,7 @@ package() {
cd "$srcdir/$_srcdir_name" cd "$srcdir/$_srcdir_name"
# Install the wrapper into /usr/bin # Install the wrapper into /usr/bin
install -Dm0755 "scripts/pkgmgr-wrapper.sh" \ install -Dm0755 "scripts/launcher.sh" \
"$pkgdir/usr/bin/pkgmgr" "$pkgdir/usr/bin/pkgmgr"
# Install Nix bootstrap (init + lib) # Install Nix bootstrap (init + lib)

View File

@@ -28,7 +28,7 @@ override_dh_auto_install:
install -d debian/package-manager/usr/lib/package-manager install -d debian/package-manager/usr/lib/package-manager
# Install wrapper # Install wrapper
install -m0755 scripts/pkgmgr-wrapper.sh \ install -m0755 scripts/launcher.sh \
debian/package-manager/usr/bin/pkgmgr debian/package-manager/usr/bin/pkgmgr
# Install Nix bootstrap (init + lib) # Install Nix bootstrap (init + lib)

View File

@@ -42,7 +42,7 @@ install -d %{buildroot}/usr/lib/package-manager
cp -a . %{buildroot}/usr/lib/package-manager/ cp -a . %{buildroot}/usr/lib/package-manager/
# Wrapper # Wrapper
install -m0755 scripts/pkgmgr-wrapper.sh %{buildroot}%{_bindir}/pkgmgr install -m0755 scripts/launcher.sh %{buildroot}%{_bindir}/pkgmgr
# Nix bootstrap (init + lib) # Nix bootstrap (init + lib)
install -d %{buildroot}/usr/lib/package-manager/nix install -d %{buildroot}/usr/lib/package-manager/nix

View File

@@ -1,11 +1,6 @@
#!/usr/bin/env bash #!/usr/bin/env bash
set -euo pipefail 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" 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" -- "$@" exec nix run "${FLAKE_DIR}#pkgmgr" -- "$@"
fi fi
echo "[pkgmgr-wrapper] ERROR: 'nix' binary not found on PATH after init." echo "[launcher] ERROR: 'nix' binary not found on PATH after init."
echo "[pkgmgr-wrapper] Nix is required to run pkgmgr (no Python fallback)." echo "[launcher] Nix is required to run pkgmgr (no Python fallback)."
exit 1 exit 1

View File

@@ -11,45 +11,79 @@ nixconf_file_path() {
echo "/etc/nix/nix.conf" echo "/etc/nix/nix.conf"
} }
nixconf_ensure_experimental_features() { # Ensure a given nix.conf key contains required tokens (merged, no duplicates)
local nix_conf want nixconf_ensure_features_key() {
nix_conf="$(nixconf_file_path)" local nix_conf="$1"
want="experimental-features = nix-command flakes" local key="$2"
shift 2
local required=("$@")
mkdir -p /etc/nix mkdir -p /etc/nix
# Create file if missing (with just the required tokens)
if [[ ! -f "${nix_conf}" ]]; then if [[ ! -f "${nix_conf}" ]]; then
local want="${key} = ${required[*]}"
echo "[nix-conf] Creating ${nix_conf} with: ${want}" echo "[nix-conf] Creating ${nix_conf} with: ${want}"
printf "%s\n" "${want}" >"${nix_conf}" printf "%s\n" "${want}" >"${nix_conf}"
return 0 return 0
fi fi
if grep -qE '^\s*experimental-features\s*=' "${nix_conf}"; then # Key exists -> merge tokens
if grep -qE '^\s*experimental-features\s*=.*\bnix-command\b' "${nix_conf}" \ if grep -qE "^\s*${key}\s*=" "${nix_conf}"; then
&& grep -qE '^\s*experimental-features\s*=.*\bflakes\b' "${nix_conf}"; then local ok=1
echo "[nix-conf] experimental-features already correct" 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 return 0
fi fi
echo "[nix-conf] Extending experimental-features in ${nix_conf}" echo "[nix-conf] Extending ${key} in ${nix_conf}"
local current 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 current="$(echo "${current}" | xargs)" # trim
# Build a merged feature string without duplicates (simple token set) local merged=""
local merged="nix-command flakes"
local token local token
# Start with existing tokens
for token in ${current}; do for token in ${current}; do
if [[ " ${merged} " != *" ${token} "* ]]; then if [[ " ${merged} " != *" ${token} "* ]]; then
merged="${merged} ${token}" merged="${merged} ${token}"
fi fi
done 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 return 0
fi fi
# Key missing -> append
local want="${key} = ${required[*]}"
echo "[nix-conf] Appending to ${nix_conf}: ${want}" echo "[nix-conf] Appending to ${nix_conf}: ${want}"
printf "\n%s\n" "${want}" >>"${nix_conf}" 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"
}