68 lines
2.6 KiB
Bash
68 lines
2.6 KiB
Bash
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
cd "$(dirname "$0")/.."
|
|
export DOTFILES_DIR="$PWD"
|
|
source <(sed '$d' bin/dot)
|
|
fixture="$(mktemp -d)"
|
|
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'; }
|
|
|
|
# Reproduce a host Home Manager symlink whose store target is absent in a box.
|
|
ln -s "$fixture/missing-host-store/nix.conf" "$conf"
|
|
cmd_nix
|
|
[ ! -L "$conf" ]
|
|
grep -qx 'extra-experimental-features = nix-command flakes' "$conf"
|
|
backups=("$conf".broken-link.*)
|
|
[ "${#backups[@]}" = 1 ] && [ -L "${backups[0]}" ]
|
|
[ "$(readlink "${backups[0]}")" = "$fixture/missing-host-store/nix.conf" ]
|
|
cmd_nix
|
|
[ "$(grep -c '^extra-experimental-features' "$conf")" = 1 ]
|
|
|
|
# Preserve extra settings and do not write into a valid immutable target.
|
|
printf '# flakes mentioned in a comment is not enabling it\nexperimental-features = ca-derivations\nsubstituters = https://cache.nixos.org\n' >"$fixture/store-config"
|
|
chmod 444 "$fixture/store-config"
|
|
mv "$conf" "$fixture/recovered-config"
|
|
ln -s "$fixture/store-config" "$conf"
|
|
cmd_nix
|
|
[ ! -L "$conf" ]
|
|
! grep -q '^extra-experimental-features' "$fixture/store-config"
|
|
grep -qx 'experimental-features = ca-derivations' "$conf"
|
|
grep -qx 'substituters = https://cache.nixos.org' "$conf"
|
|
grep -qx 'extra-experimental-features = nix-command flakes' "$conf"
|
|
|
|
# A healthy managed file remains linked through repeated bootstraps.
|
|
printf 'experimental-features = nix-command flakes\n' >"$fixture/healthy-config"
|
|
mv "$conf" "$fixture/preserved-config"
|
|
ln -s "$fixture/healthy-config" "$conf"
|
|
cmd_nix
|
|
[ -L "$conf" ]
|
|
|
|
# Switching must also bootstrap features before invoking Home Manager.
|
|
mv "$conf" "$fixture/healthy-link"
|
|
ln -s "$fixture/missing-again" "$conf"
|
|
flake_attr() { echo headless; }
|
|
have() { [ "$1" = home-manager ]; }
|
|
printf 'existing backup\n' >"$conf.hm-bak"
|
|
home-manager() {
|
|
grep -qx 'extra-experimental-features = nix-command flakes' "$conf"
|
|
# The fixed hm-bak suffix would collide with this existing backup.
|
|
[[ " $* " == *' -b hm-bak.'* ]]
|
|
[ ! -e "$conf.${*: -1}" ]
|
|
}
|
|
cmd_switch
|
|
grep -qx 'existing backup' "$conf.hm-bak"
|
|
echo 'Nix bootstrap recovery checks passed'
|