diff --git a/README.md b/README.md index 0add50e..9d2c3a2 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/bin/dot b/bin/dot index e016a35..24d114f 100755 --- a/bin/dot +++ b/bin/dot @@ -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. diff --git a/scripts/doctor-nix.sh b/scripts/doctor-nix.sh index 7ecb3e3..ef60112 100644 --- a/scripts/doctor-nix.sh +++ b/scripts/doctor-nix.sh @@ -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 diff --git a/tests/doctor-nix.sh b/tests/doctor-nix.sh index 56f01fc..f725c77 100644 --- a/tests/doctor-nix.sh +++ b/tests/doctor-nix.sh @@ -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 diff --git a/tests/nix-bootstrap.sh b/tests/nix-bootstrap.sh index 5cfd079..9af7b84 100644 --- a/tests/nix-bootstrap.sh +++ b/tests/nix-bootstrap.sh @@ -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'; }