stockholm/krebs/3modules/hidden-ssh.nix

82 lines
2.0 KiB
Nix
Raw Permalink Normal View History

2017-04-15 16:04:19 +00:00
{ config, lib, pkgs, ... }:
2023-06-10 10:50:53 +00:00
with lib;
2017-04-15 16:04:19 +00:00
let
cfg = config.krebs.hidden-ssh;
out = {
options.krebs.hidden-ssh = api;
config = lib.mkIf cfg.enable imp;
};
api = {
enable = mkEnableOption "hidden SSH announce";
channel = mkOption {
type = types.str;
default = "#krebs-announce";
};
server = mkOption {
type = types.str;
2021-05-20 08:29:40 +00:00
default = "irc.hackint.org";
};
2021-09-05 20:51:37 +00:00
port = mkOption {
type = types.int;
default = 6697;
};
tls = mkOption {
type = types.bool;
default = true;
};
2020-04-11 15:06:24 +00:00
message = mkOption {
type = types.str;
default = "SSH Hidden Service at ";
};
2017-04-15 16:04:19 +00:00
};
imp = let
torDirectory = "/var/lib/tor"; # from tor.nix
hiddenServiceDir = torDirectory + "/onion/hidden-ssh";
2017-04-15 16:04:19 +00:00
in {
services.tor = {
enable = true;
relay.onionServices.hidden-ssh = {
version = 3;
map = [{
port = 22;
target.port = 22;
}];
};
2017-04-15 16:04:19 +00:00
client.enable = true;
};
systemd.services.hidden-ssh-announce = {
description = "irc announce hidden ssh";
after = [ "tor.service" "network-online.target" ];
2017-04-15 16:04:19 +00:00
wants = [ "tor.service" ];
wantedBy = [ "multi-user.target" ];
serviceConfig = {
# ${pkgs.tor}/bin/torify
ExecStart = pkgs.writeDash "irc-announce-ssh" ''
set -efu
until test -e ${hiddenServiceDir}/hostname; do
echo "still waiting for ${hiddenServiceDir}/hostname"
sleep 1
done
2021-09-05 20:51:37 +00:00
${pkgs.untilport}/bin/untilport ${escapeShellArg cfg.server} ${toString cfg.port}
${pkgs.irc-announce}/bin/irc-announce \
${escapeShellArg cfg.server} \
${toString cfg.port} \
"${config.krebs.build.host.name}-ssh" \
${escapeShellArg cfg.channel} \
${escapeShellArg cfg.tls} \
2020-04-11 15:06:24 +00:00
"${cfg.message}$(cat ${hiddenServiceDir}/hostname)"
2017-04-15 16:04:19 +00:00
'';
PrivateTmp = "true";
User = "tor";
Type = "oneshot";
};
};
};
in
out