nixos/ssh: take care not to accept empty host key files

In case of a power loss shortly after first boot,
the host keys gernerated by ssh-keygen could exist
in the file system but have zero size, preventing
sshd from starting up.

This commit changes the behaviour to generate host
keys if the file either does not exist or has zero
size, fixing the problem on the next boot.

Thanks to @SuperSandro2000 for figuring this out.
This commit is contained in:
Matthias Treydte 2021-10-12 12:21:53 +02:00
parent 8da58db50b
commit 97e61a071d

View File

@ -439,7 +439,7 @@ in
mkdir -m 0755 -p /etc/ssh
${flip concatMapStrings cfg.hostKeys (k: ''
if ! [ -f "${k.path}" ]; then
if ! [ -s "${k.path}" ]; then
ssh-keygen \
-t "${k.type}" \
${if k ? bits then "-b ${toString k.bits}" else ""} \