nixos-config/images/lib/remote-access.nix

135 lines
3.5 KiB
Nix
Raw Normal View History

{
2021-11-01 19:30:41 +01:00
# cat ~/.ssh/id_rsa.pub
publicSshKey ? ""
, # remote-install-get-hiddenReceiver
hiddenReceiver ? ""
,
}:
2019-12-20 05:54:26 +01:00
{ config, lib, pkgs, ... }: {
imports = [
2021-11-01 19:30:41 +01:00
{
# system setup
networking.hostName = "liveos";
users.extraUsers = {
2019-12-20 05:54:26 +01:00
root = { openssh.authorizedKeys.keys = [ publicSshKey ]; };
};
}
2021-11-01 19:30:41 +01:00
{
# installed packages
nixpkgs.config.allowUnfree = true;
environment.systemPackages = with pkgs; [
2019-12-20 05:54:26 +01:00
#style
most
rxvt_unicode.terminfo
2019-12-20 05:54:26 +01:00
#monitoring tools
htop
iotop
2019-12-20 05:54:26 +01:00
#network
iptables
iftop
nmap
2019-12-20 05:54:26 +01:00
#stuff for dl
aria2
2019-12-20 05:54:26 +01:00
#neat utils
pciutils
psmisc
tmux
usbutils
git
2019-12-20 05:54:26 +01:00
#unpack stuff
p7zip
unzip
unrar
2019-12-20 05:54:26 +01:00
#data recovery
ddrescue
ntfs3g
dosfstools
];
}
2021-11-01 19:30:41 +01:00
{
# bash configuration
programs.bash = {
enableCompletion = true;
interactiveShellInit = ''
HISTCONTROL='erasedups:ignorespace'
HISTSIZE=65536
HISTFILESIZE=$HISTSIZE
shopt -s checkhash
shopt -s histappend histreedit histverify
shopt -s no_empty_cmd_completion
complete -d cd
'';
promptInit = ''
if test $UID = 0; then
PS1='\[\033[1;31m\]\w\[\033[0m\] '
PROMPT_COMMAND='echo -ne "\033]0;$$ $USER@$PWD\007"'
elif test $UID = 1337; then
PS1='\[\033[1;32m\]\w\[\033[0m\] '
PROMPT_COMMAND='echo -ne "\033]0;$$ $PWD\007"'
else
PS1='\[\033[1;33m\]\u@\w\[\033[0m\] '
PROMPT_COMMAND='echo -ne "\033]0;$$ $USER@$PWD\007"'
fi
if test -n "$SSH_CLIENT"; then
PS1='\[\033[35m\]\h'" $PS1"
PROMPT_COMMAND='echo -ne "\033]0;$$ $HOSTNAME $USER@$PWD\007"'
fi
'';
};
}
2021-11-01 19:30:41 +01:00
{
# ssh configuration
services.openssh.enable = true;
services.openssh.passwordAuthentication = false;
systemd.services.sshd.wantedBy = lib.mkForce [ "multi-user.target" ];
}
2021-11-01 19:30:41 +01:00
{
# hidden ssh announce
config =
let
torDirectory = "/var/lib/tor";
hiddenServiceDir = torDirectory + "/liveos";
in
{
services.tor = {
enable = true;
client.enable = true;
extraConfig = ''
HiddenServiceDir ${hiddenServiceDir}
HiddenServicePort 22 127.0.0.1:22
'';
2021-11-01 19:30:41 +01:00
};
systemd.services.hidden-ssh-announce = {
description = "irc announce hidden ssh";
after = [ "tor.service" "network-online.target" ];
wants = [ "tor.service" ];
wantedBy = [ "multi-user.target" ];
serviceConfig = {
ExecStart = pkgs.writers.writeDash "irc-announce-ssh" ''
set -efu
until test -e ${hiddenServiceDir}/hostname; do
echo "still waiting for ${hiddenServiceDir}/hostname"
sleep 1
done
until ${pkgs.tor}/bin/torify ${pkgs.netcat-openbsd}/bin/nc -z ${hiddenReceiver} 1337; do sleep 1; done && \
echo "torify ssh root@$(cat ${hiddenServiceDir}/hostname) -i ~/.ssh/id_rsa" | ${pkgs.tor}/bin/torify ${pkgs.nmap}/bin/ncat ${hiddenReceiver} 1337
'';
PrivateTmp = "true";
User = "tor";
Type = "oneshot";
};
};
};
}
];
}