nixos-config/nixos/modules/services/sshd.nix

64 lines
1.4 KiB
Nix
Raw Normal View History

2019-10-24 02:20:38 +02:00
{ pkgs, config, lib, ... }:
with lib;
let
cfg = config.services.custom.ssh;
2021-11-01 09:20:42 +01:00
in
{
2019-10-24 02:20:38 +02:00
options.services.custom.ssh = {
tools.enable = mkEnableOption "Add ssh tools";
sshd = {
enable = mkEnableOption "Start sshd server";
rootKeyFiles = mkOption {
2019-12-20 05:54:26 +01:00
type = with types; listOf path;
2019-10-24 02:20:38 +02:00
description = "keys to root login";
2019-12-20 05:54:26 +01:00
default = [ ];
2019-10-24 02:20:38 +02:00
};
};
};
config = mkMerge [
2019-12-20 05:54:26 +01:00
(mkIf cfg.tools.enable {
environment.systemPackages = with pkgs;
[
# sshuttle
sshfs
];
})
2019-10-24 02:20:38 +02:00
2019-12-20 05:54:26 +01:00
(mkIf cfg.sshd.enable {
2019-10-24 02:20:38 +02:00
2019-12-20 05:54:26 +01:00
services.openssh = {
enable = true;
forwardX11 = true;
passwordAuthentication = false;
};
2019-10-24 02:20:38 +02:00
2019-12-20 05:54:26 +01:00
users.users.root.openssh.authorizedKeys.keyFiles = cfg.sshd.rootKeyFiles;
2019-10-24 02:20:38 +02:00
2019-12-20 05:54:26 +01:00
services.openssh.extraConfig = ''
Banner /etc/sshd/banner-line
'';
2019-10-24 02:20:38 +02:00
2021-11-01 09:20:42 +01:00
environment.etc."sshd/banner-line".text =
let
text = config.networking.hostName;
size = 80 - (lib.stringLength text);
space = lib.fixedWidthString size " " "";
in
''
${space}${text}
'';
2019-10-24 02:20:38 +02:00
2019-12-20 05:54:26 +01:00
})
2019-10-24 02:20:38 +02:00
];
}