23 lines
920 B
Nix
23 lines
920 B
Nix
{
|
|
writeTextFile,
|
|
}:
|
|
|
|
let
|
|
stripR = str: if (builtins.substring ((builtins.stringLength str) - 1) (builtins.stringLength str) str) == "\n" then stripR (builtins.substring 0 ((builtins.stringLength str) - 1) str) else str;
|
|
hostsWithSshPubkey = builtins.filter (hostname: (builtins.substring 0 1 hostname) != "_" && builtins.pathExists (../../hosts + "/${hostname}/ssh.pub")) (builtins.attrNames (builtins.readDir ../../hosts));
|
|
sshkeyList = map (hostname: {
|
|
name = hostname;
|
|
sshPubkey = stripR (builtins.readFile (../../hosts + "/${hostname}/ssh.pub"));
|
|
}) hostsWithSshPubkey;
|
|
knownHosts = builtins.concatStringsSep "" (builtins.map ({name, sshPubkey}: ''
|
|
${name} ${sshPubkey}
|
|
${name}.net.clerie.de ${sshPubkey}
|
|
'') sshkeyList);
|
|
in writeTextFile {
|
|
name = "clerie-ssh-known-hosts";
|
|
destination = "/known_hosts";
|
|
allowSubstitutes = true;
|
|
preferLocalBuild = false;
|
|
text = knownHosts;
|
|
}
|