2023-01-09 02:40:25 +00:00
|
|
|
{ config, lib, sane-data, sane-lib, ... }:
|
2023-01-08 03:22:05 +00:00
|
|
|
|
2023-01-19 23:23:41 +00:00
|
|
|
let
|
|
|
|
inherit (builtins) head map mapAttrs tail;
|
|
|
|
inherit (lib) concatStringsSep mkMerge reverseList;
|
|
|
|
in
|
2023-01-09 02:40:25 +00:00
|
|
|
{
|
|
|
|
sane.ssh.pubkeys =
|
|
|
|
let
|
|
|
|
# path is a DNS-style path like [ "org" "uninsane" "root" ]
|
|
|
|
keyNameForPath = path:
|
|
|
|
let
|
2023-01-19 23:23:41 +00:00
|
|
|
rev = reverseList path;
|
|
|
|
name = head rev;
|
|
|
|
host = concatStringsSep "." (tail rev);
|
2023-01-09 02:40:25 +00:00
|
|
|
in
|
|
|
|
"${name}@${host}";
|
2023-01-08 03:22:05 +00:00
|
|
|
|
2023-01-09 03:48:07 +00:00
|
|
|
# [{ path :: [String], value :: String }] for the keys we want to install
|
|
|
|
globalKeys = sane-lib.flattenAttrs sane-data.keys;
|
2023-01-19 23:23:41 +00:00
|
|
|
domainKeys = sane-lib.flattenAttrs (
|
|
|
|
mapAttrs (host: cfg: {
|
|
|
|
colin = cfg.ssh.user_pubkey;
|
|
|
|
root = cfg.ssh.host_pubkey;
|
2023-01-19 23:55:56 +00:00
|
|
|
}) config.sane.hosts.by-name
|
2023-01-19 23:23:41 +00:00
|
|
|
);
|
|
|
|
in mkMerge (map
|
2023-01-09 03:48:07 +00:00
|
|
|
({ path, value }: {
|
2023-01-19 23:23:41 +00:00
|
|
|
"${keyNameForPath path}" = lib.mkIf (value != null) value;
|
2023-01-09 03:48:07 +00:00
|
|
|
})
|
2023-01-19 23:23:41 +00:00
|
|
|
(globalKeys ++ domainKeys)
|
2023-01-09 03:48:07 +00:00
|
|
|
);
|
2022-10-25 09:09:27 +00:00
|
|
|
}
|