ec2-data: ensure providing a SSH host key is actually optional

27016659046a8f8e7b4fd61ecbceaf9f5e306258 broke this.

+13 -11
+13 -11
nixos/modules/virtualisation/ec2-data.nix
··· 43 43 44 44 mkdir -m 0755 -p /etc/ssh 45 45 46 - key="$(sed 's/|/\n/g; s/SSH_HOST_DSA_KEY://; t; d' $userData)" 47 - key_pub="$(sed 's/SSH_HOST_DSA_KEY_PUB://; t; d' $userData)" 48 - if [ -n "$key" -a -n "$key_pub" -a ! -e /etc/ssh/ssh_host_dsa_key ]; then 49 - (umask 077; echo "$key" > /etc/ssh/ssh_host_dsa_key) 50 - echo "$key_pub" > /etc/ssh/ssh_host_dsa_key.pub 51 - fi 46 + if [ -s "$userData" ]; then 47 + key="$(sed 's/|/\n/g; s/SSH_HOST_DSA_KEY://; t; d' $userData)" 48 + key_pub="$(sed 's/SSH_HOST_DSA_KEY_PUB://; t; d' $userData)" 49 + if [ -n "$key" -a -n "$key_pub" -a ! -e /etc/ssh/ssh_host_dsa_key ]; then 50 + (umask 077; echo "$key" > /etc/ssh/ssh_host_dsa_key) 51 + echo "$key_pub" > /etc/ssh/ssh_host_dsa_key.pub 52 + fi 52 53 53 - key="$(sed 's/|/\n/g; s/SSH_HOST_ED25519_KEY://; t; d' $userData)" 54 - key_pub="$(sed 's/SSH_HOST_ED25519_KEY_PUB://; t; d' $userData)" 55 - if [ -n "$key" -a -n "$key_pub" -a ! -e /etc/ssh/ssh_host_ed25519_key ]; then 56 - (umask 077; echo "$key" > /etc/ssh/ssh_host_ed25519_key) 57 - echo "$key_pub" > /etc/ssh/ssh_host_ed25519_key.pub 54 + key="$(sed 's/|/\n/g; s/SSH_HOST_ED25519_KEY://; t; d' $userData)" 55 + key_pub="$(sed 's/SSH_HOST_ED25519_KEY_PUB://; t; d' $userData)" 56 + if [ -n "$key" -a -n "$key_pub" -a ! -e /etc/ssh/ssh_host_ed25519_key ]; then 57 + (umask 077; echo "$key" > /etc/ssh/ssh_host_ed25519_key) 58 + echo "$key_pub" > /etc/ssh/ssh_host_ed25519_key.pub 59 + fi 58 60 fi 59 61 ''; 60 62