Select an accessible Nix CA bundle inside distrobox

This commit is contained in:
Ziad Arafat committed 2026-11-15 12:08:45 -07:00
1 parent 3f71ad2a99
commit 1c4b0657bf
5 files changed
+43 -2

No files matched your search

+3
View File
@@ -132,6 +132,9 @@ link as `nix.conf.broken-link.*` and create a writable bootstrap config enabling
`nix-command` and flakes. Existing readable settings are preserved when adding
features; healthy managed configurations remain linked. You can recover with
`git -C ~/.dotfiles pull` followed by `dot nix` and `dot switch`.
`dot` also replaces an absent/unreadable inherited Nix CA-bundle path with a
readable local system bundle (including Fedora/AlmaLinux's `/etc/pki` path),
while preserving valid custom bundles and keeping TLS verification enabled.
Apps that write their own settings (Claude Code, pi, Vesktop, Konsole profiles, VSCodium, Zed, `~/.ssh/config`) are linked **out of the Nix store** into this checkout. Changes made in the app show up in `git diff`, so commit them.
+21 -2
View File
@@ -26,13 +26,32 @@ os_id() { (. /etc/os-release 2>/dev/null && echo "${ID:-unknown}") || echo unkno
has_systemd() { [ -d /run/systemd/system ]; }
in_container() { [ -f /run/.containerenv ] || [ -f /.dockerenv ] || [ -n "${container:-}" ]; }
nix_ca_candidates() {
printf '%s\n' "${SSL_CERT_FILE:-}" /etc/ssl/certs/ca-certificates.crt \
/etc/pki/tls/certs/ca-bundle.crt /etc/ssl/cert.pem \
"$HOME/.nix-profile/etc/ssl/certs/ca-bundle.crt"
}
configure_nix_tls() {
# A shared home/session may carry the host's Debian CA path into Fedora/Alma.
# Keep valid custom trust bundles; select a local bundle only when needed.
[ -n "${NIX_SSL_CERT_FILE:-}" ] && [ -f "$NIX_SSL_CERT_FILE" ] && [ -r "$NIX_SSL_CERT_FILE" ] && return 0
local cert
while IFS= read -r cert; do
if [ -f "$cert" ] && [ -r "$cert" ]; then
export NIX_SSL_CERT_FILE="$cert"
return 0
fi
done < <(nix_ca_candidates)
return 0
}
source_nix() {
have nix && return 0
if have nix; then configure_nix_tls; return 0; fi
for f in "$HOME/.nix-profile/etc/profile.d/nix.sh" /nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh; do
# shellcheck disable=SC1090
[ -e "$f" ] && . "$f" && break
done
have nix
have nix || return 1
configure_nix_tls
}
# sudo that works as root, with a TTY, or not at all.
+7
View File
@@ -26,6 +26,13 @@ doctor_nix() {
return 0
fi
ok "Nix executable starts"
if [ -n "${NIX_SSL_CERT_FILE:-}" ]; then
if [ -f "$NIX_SSL_CERT_FILE" ] && [ -r "$NIX_SSL_CERT_FILE" ]; then
ok "Nix TLS CA bundle accessible"
else
warn "Nix TLS CA bundle missing/unreadable — inherited host certificate paths may not exist in a container; install ca-certificates and select a readable NIX_SSL_CERT_FILE"
fi
fi
if [ -d "$root/store" ] && [ -r "$root/store" ] && [ -x "$root/store" ]; then
ok "Nix store directory accessible"
else
+3
View File
@@ -44,6 +44,9 @@ unset missing
broken=1 result="$(doctor_nix)"
grep -q 'executable cannot start' <<<"$result"
unset broken
NIX_SSL_CERT_FILE="$fixture/missing-ca.pem" result="$(doctor_nix)"
grep -q 'TLS CA bundle missing/unreadable' <<<"$result"
unset NIX_SSL_CERT_FILE
store_broken=1 fixture_daemon=1 result="$(doctor_nix)"
grep -q 'daemon/store connection failed' <<<"$result"
unset store_broken fixture_daemon
+9
View File
@@ -8,6 +8,15 @@ trap 'rm -rf "$fixture"' EXIT
export XDG_CONFIG_HOME="$fixture/config"
mkdir -p "$XDG_CONFIG_HOME/nix"
conf="$XDG_CONFIG_HOME/nix/nix.conf"
# Host-only CA paths must be replaced without disabling TLS verification.
touch "$fixture/container-ca.pem" "$fixture/custom-ca.pem"
nix_ca_candidates() { printf '%s\n' "$fixture/container-ca.pem"; }
export NIX_SSL_CERT_FILE="$fixture/missing-host-ca.pem"
configure_nix_tls
[ "$NIX_SSL_CERT_FILE" = "$fixture/container-ca.pem" ]
export NIX_SSL_CERT_FILE="$fixture/custom-ca.pem"
configure_nix_tls
[ "$NIX_SSL_CERT_FILE" = "$fixture/custom-ca.pem" ]
source_nix() { return 0; }
nix() { echo 'nix (Nix) fixture'; }