2017-04-15 16:04:19 +00:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with import <stockholm/lib>;
|
|
|
|
let
|
|
|
|
cfg = config.krebs.hidden-ssh;
|
|
|
|
|
|
|
|
out = {
|
|
|
|
options.krebs.hidden-ssh = api;
|
|
|
|
config = lib.mkIf cfg.enable imp;
|
|
|
|
};
|
|
|
|
|
|
|
|
api = {
|
|
|
|
enable = mkEnableOption "hidden SSH announce";
|
2020-01-11 19:25:56 +00:00
|
|
|
channel = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "#krebs-announce";
|
|
|
|
};
|
|
|
|
server = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "irc.freenode.org";
|
|
|
|
};
|
2017-04-15 16:04:19 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
imp = let
|
|
|
|
torDirectory = "/var/lib/tor"; # from tor.nix
|
|
|
|
hiddenServiceDir = torDirectory + "/ssh-announce-service";
|
|
|
|
in {
|
|
|
|
services.tor = {
|
|
|
|
enable = true;
|
|
|
|
extraConfig = ''
|
|
|
|
HiddenServiceDir ${hiddenServiceDir}
|
|
|
|
HiddenServicePort 22 127.0.0.1:22
|
|
|
|
'';
|
|
|
|
client.enable = true;
|
|
|
|
};
|
|
|
|
systemd.services.hidden-ssh-announce = {
|
|
|
|
description = "irc announce hidden ssh";
|
2017-04-16 21:31:46 +00:00
|
|
|
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
|
2020-01-11 19:25:56 +00:00
|
|
|
${pkgs.untilport}/bin/untilport ${cfg.server} 6667 && \
|
2017-04-24 10:54:02 +00:00
|
|
|
${pkgs.irc-announce}/bin/irc-announce \
|
2020-01-11 19:25:56 +00:00
|
|
|
${cfg.server} 6667 ${config.krebs.build.host.name}-ssh \
|
|
|
|
\${cfg.channel} \
|
2017-04-15 16:04:19 +00:00
|
|
|
"SSH Hidden Service at $(cat ${hiddenServiceDir}/hostname)"
|
|
|
|
'';
|
|
|
|
PrivateTmp = "true";
|
|
|
|
User = "tor";
|
|
|
|
Type = "oneshot";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
in
|
|
|
|
out
|