2025-12-29 12:27:40 +01:00
|
|
|
{
|
|
|
|
|
symlinkJoin,
|
|
|
|
|
writers,
|
|
|
|
|
lib,
|
|
|
|
|
netcat,
|
|
|
|
|
openssh,
|
2025-12-29 13:17:42 +01:00
|
|
|
try-connect,
|
2025-12-29 12:27:40 +01:00
|
|
|
}:
|
|
|
|
|
let
|
|
|
|
|
inherit (lib.niveum) machines;
|
|
|
|
|
sshableMachines = lib.filterAttrs (name: value: value ? "sshPort") machines;
|
|
|
|
|
in
|
|
|
|
|
symlinkJoin {
|
|
|
|
|
name = "niveum-ssh";
|
|
|
|
|
paths = lib.mapAttrsToList (
|
|
|
|
|
hostname: _:
|
|
|
|
|
writers.writeBashBin "niveum-ssh-${hostname}" ''
|
2025-12-29 13:17:42 +01:00
|
|
|
reachable=$(${try-connect.${hostname}}/bin/try-connect)
|
2025-12-29 12:27:40 +01:00
|
|
|
|
2025-12-29 13:17:42 +01:00
|
|
|
if [ -z "$reachable" ]; then
|
|
|
|
|
exit 1
|
|
|
|
|
fi
|
2025-12-29 12:27:40 +01:00
|
|
|
|
2025-12-29 13:17:42 +01:00
|
|
|
if [[ "$reachable" == *.onion ]]; then
|
|
|
|
|
exec ${openssh}/bin/ssh -p ${toString machines.${hostname}.sshPort} \
|
|
|
|
|
-o ProxyCommand="${netcat}/bin/nc -x localhost:9050 %h %p" \
|
|
|
|
|
"root@$reachable" "$@"
|
|
|
|
|
else
|
|
|
|
|
exec ${openssh}/bin/ssh -p ${toString machines.${hostname}.sshPort} \
|
|
|
|
|
"root@$reachable" "$@"
|
|
|
|
|
fi
|
2025-12-29 12:27:40 +01:00
|
|
|
''
|
|
|
|
|
) sshableMachines;
|
|
|
|
|
}
|