nixos-config/lib/fudo/ssh.nix

26 lines
673 B
Nix
Raw Normal View History

2021-09-29 17:55:13 -07:00
{ config, lib, pkgs, ... }:
with lib;
2021-11-05 07:06:08 -07:00
{
2021-09-29 17:55:13 -07:00
config = {
2021-09-30 08:40:47 -07:00
programs.ssh.knownHosts = let
keyed-hosts =
filterAttrs (h: o: o.ssh-pubkeys != [])
config.fudo.hosts;
crossProduct = f: list0: list1:
concatMap (el0: map (el1: f el0 el1) list1) list0;
2021-09-30 11:30:32 -07:00
all-hostnames = hostname: opts:
[ hostname ] ++
2021-09-30 08:40:47 -07:00
(crossProduct (host: domain: "${host}.${domain}")
2021-09-30 11:30:32 -07:00
([ hostname ] ++ opts.aliases)
2021-09-30 08:40:47 -07:00
([ opts.domain ] ++ opts.extra-domains));
in mapAttrs (hostname: hostOpts: {
publicKeyFile = builtins.head hostOpts.ssh-pubkeys;
2021-11-05 07:06:08 -07:00
hostNames = all-hostnames hostname hostOpts;
2021-09-30 08:40:47 -07:00
}) keyed-hosts;
2021-09-29 17:55:13 -07:00
};
}