nixos-config/nixos/components/network/sshd/default.nix

74 lines
1.9 KiB
Nix
Raw Normal View History

2022-10-13 10:19:23 +02:00
{ pkgs, config, lib, ... }:
with lib;
with types;
let
defaultRootKeyFiles = [ (toString ../../../assets/ssh/palo_rsa.pub) ];
2023-05-28 21:24:20 +02:00
cfg = config.components.network.sshd;
2022-10-13 10:19:23 +02:00
in
{
imports = [
./known-hosts-bootup.nix
./known-hosts-private.nix
./known-hosts-public.nix
];
2023-02-17 00:41:22 +01:00
options.components.network.sshd = {
2022-10-13 10:19:23 +02:00
enable = mkOption {
type = bool;
default = true;
};
rootKeyFiles = mkOption {
type = with types; listOf path;
default = [ ];
description = "keys to root login";
};
onlyTincAccess = mkOption {
type = bool;
default = false;
description = ''
make sure ssh is only available trough the tinc
'';
};
};
config = mkMerge [
(mkIf cfg.enable {
2023-05-28 21:24:20 +02:00
environment.systemPackages = [ pkgs.sshfs ];
2022-10-13 10:19:23 +02:00
services.openssh = {
enable = true;
2023-06-29 10:08:09 +02:00
settings.X11Forwarding = false;
settings.PasswordAuthentication = false;
2022-10-13 10:19:23 +02:00
};
2023-06-01 11:44:02 +02:00
users.users.root.openssh.authorizedKeys.keyFiles = cfg.rootKeyFiles ++ defaultRootKeyFiles;
2022-10-13 10:19:23 +02:00
services.openssh.extraConfig = ''
Banner /etc/ssh/banner-line
'';
environment.etc."ssh/banner-line".text =
let
text = config.networking.hostName;
size = 80 - (lib.stringLength text);
space = lib.fixedWidthString size " " "";
in
''
${space}${text}
'';
})
(mkIf (cfg.onlyTincAccess && cfg.enable) {
networking.firewall.extraCommands = ''
iptables --table nat --append PREROUTING ! --in-interface tinc.+ --protocol tcp --match tcp --dport 22 --jump REDIRECT --to-ports 0
'';
})
];
}