nixos-config/lib/gen-ssh-config.nix

24 lines
598 B
Nix
Raw Normal View History

2023-03-17 04:21:32 +00:00
lib:
nixosConfigurations:
let
sshKnownHostsTxt = builtins.toFile "known_hosts" (lib.concatMapStrings
(hostName:
let d = nixosConfigurations.${hostName}.config.deploy;
in lib.concatMapStrings (key: "${d.targetHost} ${key}\n") d.sshPublicKeys
)
(builtins.attrNames nixosConfigurations)
);
in
builtins.toFile "ssh-config" (''
StrictHostKeyChecking yes
GlobalKnownHostsFile ${sshKnownHostsTxt}
'' +
lib.concatMapStrings
(host: ''
Host ${host}
HostName ${nixosConfigurations.${host}.config.deploy.targetHost}
'')
(builtins.attrNames nixosConfigurations))