mirror of
https://github.com/SebastianStork/nixos-config.git
synced 2026-01-21 22:11:33 +01:00
57 lines
1.4 KiB
Nix
57 lines
1.4 KiB
Nix
{
|
|
config,
|
|
self,
|
|
lib,
|
|
...
|
|
}:
|
|
let
|
|
cfg = config.custom.services.sshd;
|
|
netCfg = config.custom.networking;
|
|
in
|
|
{
|
|
options.custom.services.sshd.enable = lib.mkEnableOption "";
|
|
|
|
config = lib.mkIf cfg.enable {
|
|
meta.ports.tcp = [ 22 ];
|
|
|
|
services = {
|
|
openssh = {
|
|
enable = true;
|
|
openFirewall = false;
|
|
ports = [ ];
|
|
listenAddresses = lib.singleton {
|
|
addr = netCfg.overlay.address;
|
|
port = 22;
|
|
};
|
|
settings = {
|
|
PasswordAuthentication = false;
|
|
KbdInteractiveAuthentication = false;
|
|
PermitRootLogin = "no";
|
|
};
|
|
};
|
|
|
|
nebula.networks.mesh.firewall.inbound =
|
|
netCfg.peers
|
|
|> lib.filter (node: node.isClient)
|
|
|> lib.map (client: {
|
|
port = 22;
|
|
proto = "tcp";
|
|
host = client.hostName;
|
|
});
|
|
};
|
|
|
|
systemd.services.sshd = {
|
|
requires = [ netCfg.overlay.systemdUnit ];
|
|
after = [ netCfg.overlay.systemdUnit ];
|
|
};
|
|
|
|
users.users.seb.openssh.authorizedKeys.keyFiles =
|
|
self.nixosConfigurations
|
|
|> lib.attrValues
|
|
|> lib.filter (host: host.config.custom.networking.hostName != netCfg.hostName)
|
|
|> lib.filter (host: host.config |> lib.hasAttr "home-manager")
|
|
|> lib.map (host: host.config.home-manager.users.seb.custom.programs.ssh)
|
|
|> lib.filter (ssh: ssh.enable)
|
|
|> lib.map (ssh: ssh.publicKeyPath);
|
|
};
|
|
}
|