diff --git a/scripts/gc-hosts.sh b/scripts/gc-hosts.sh index a9ba358..3a87cd0 100755 --- a/scripts/gc-hosts.sh +++ b/scripts/gc-hosts.sh @@ -121,7 +121,7 @@ if [[ "$DRY_RUN" -eq 1 ]]; then echo " ssh ${SSH_OPTS[*]} $target 'sudo -n nix-collect-garbage -d'" echo " # fallback: ssh ... $target 'nix-collect-garbage -d'" else - echo " ssh ${SSH_OPTS[*]} $target 'nix-collect-garbage -d'" + echo " ssh ${SSH_OPTS[*]} $target '. /nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh && nix-collect-garbage -d'" fi done exit 0 @@ -147,7 +147,10 @@ gc_one() { echo "ok(user)"; return fi else - if ssh "${SSH_OPTS[@]}" "$target" "nix-collect-garbage -d" \ + # Non-NixOS node: BatchMode SSH doesn't source the Nix daemon profile, so + # nix-collect-garbage won't be on PATH unless we source it explicitly. + local nix_profile='. /nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh 2>/dev/null || true' + if ssh "${SSH_OPTS[@]}" "$target" "$nix_profile && nix-collect-garbage -d" \ >>"$logfile" 2>>"$logfile"; then echo "ok"; return fi