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

26 lines
679 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.ssh.HostName} ${key}\n") d.sshPublicKeys
2023-03-17 04:21:32 +00:00
)
(builtins.attrNames nixosConfigurations)
);
attrsToList = lib.mapAttrsToList (n: v: "${n} ${v}");
attrsToLines = a: lib.concatLines (attrsToList a);
2023-03-17 04:21:32 +00:00
in
builtins.toFile "ssh-config" (''
GlobalKnownHostsFile ${sshKnownHostsTxt}
'' +
lib.concatMapStrings
(host: ''
Host ${host}
${attrsToLines nixosConfigurations.${host}.config.deploy.ssh}
2023-03-17 04:21:32 +00:00
'')
(builtins.attrNames nixosConfigurations))