nixos-config/nixos/components/network/sshd/known-hosts-bootup.nix

64 lines
1.6 KiB
Nix
Raw Normal View History

2022-06-22 23:06:16 +02:00
{ config, lib, pkgs, private_assets, ... }:
2019-10-24 02:20:38 +02:00
with lib;
let
computers = {
2022-01-18 20:21:03 +01:00
pepe = {
2022-06-22 23:06:16 +02:00
onionId = fileContents "${private_assets}/onion_id_pepe";
2022-01-18 20:21:03 +01:00
# SHA256:aOZbqpgc5CcTNtRAzjuG/0BQZ9MF5c9u/N+UC88y8kI
publicKey = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIB5K4UHD8cIcXB33UiOj5vyXJj+4CyyiLFDMwcyad92a";
};
2019-10-24 02:20:38 +02:00
};
2021-11-01 09:20:42 +01:00
in
{
2022-01-18 20:21:03 +01:00
services.openssh.knownHosts = {
"robi-init-ssh" = {
hostNames = [
"[robi]:2222"
"[144.76.13.147]:2222"
];
# SHA256:rhvbJ84cPXXezaoJiY7tFsG8CJxI2F/lLKz8q+xUW+g
publicKey = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIMKQ7XB6Cs9FJmHkuZ9ihbj76WsK0uJBh882ceyKaaKJ";
};
} // (mapAttrs'
2021-11-01 09:20:42 +01:00
(name:
{ onionId, publicKey, ... }: {
name = "${name}-init-ssh";
value = {
2022-01-18 20:21:03 +01:00
hostNames = [ "[${onionId}]:2222" ];
2021-11-01 09:20:42 +01:00
inherit publicKey;
};
})
2022-01-18 20:21:03 +01:00
computers);
2021-11-01 09:20:42 +01:00
environment.systemPackages =
let
sshTor = mapAttrsToList
2021-11-01 09:20:42 +01:00
(name:
{ onionId, ... }:
pkgs.writers.writeDashBin "ssh-boot-to-${name}-via-tor" ''
2022-01-18 20:21:03 +01:00
${pkgs.tor}/bin/torify ${pkgs.openssh}/bin/ssh root@${onionId} -p 2222
2021-11-01 09:20:42 +01:00
'')
computers;
passwordTor = mapAttrsToList
2021-11-01 09:20:42 +01:00
(name:
{ onionId, ... }:
pkgs.writers.writeDashBin "unlock-boot-${name}-via-tor" ''
2022-01-18 20:21:03 +01:00
${pkgs.tor}/bin/torify ${pkgs.openssh}/bin/ssh root@${onionId} -p 2222 '
2021-11-01 09:20:42 +01:00
echo -n "enter password : "
read password
echo "$password" > /crypt-ramfs/passphrase
'
'')
computers;
in
sshTor ++ passwordTor;
2019-10-24 02:20:38 +02:00
}