nixos-config/terranix/tinc-test/01-terranix/config/ssh-setup.nix

47 lines
1.2 KiB
Nix
Raw Normal View History

2020-01-06 06:37:25 +01:00
# --------------------------------------------------------------------------------
#
# configure ssh setup
#
# --------------------------------------------------------------------------------
{ config, lib, pkgs, ... }:
let
ssh = {
privateKeyFile = ../../sshkey;
publicKeyFile = ../../sshkey.pub;
};
target = file: "${toString ../../02-build/generated}/${file}";
2021-11-01 19:30:41 +01:00
in
{
2020-01-06 06:37:25 +01:00
# configure admin ssh keys
users.admins.palo.publicKey = lib.fileContents ssh.publicKeyFile;
# configure provisioning private Key to be used when running provisioning on the machines
provisioner.privateKeyFile = toString ssh.privateKeyFile;
resource.local_file = {
# provide ssh key for the server
sshKey = {
content = lib.fileContents ssh.publicKeyFile;
filename = target "sshkey.pub";
};
sshConfig = {
filename = target "ssh-configuration";
content = with lib;
let
configPart = name: ''
Host ''${ hcloud_server.${name}.ipv4_address }
IdentityFile ${toString ssh.privateKeyFile}
ServerAliveInterval 60
ServerAliveCountMax 3
'';
2021-11-01 19:30:41 +01:00
in
concatStringsSep "\n"
(map configPart (attrNames config.hcloud.server));
2020-01-06 06:37:25 +01:00
};
};
}